/[debburn]/cdrkit/trunk/cdrecord/scsi_scan.c
ViewVC logotype

Contents of /cdrkit/trunk/cdrecord/scsi_scan.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 415 - (show annotations) (download)
Tue Nov 21 18:34:28 2006 UTC (6 years, 5 months ago) by blade
File MIME type: text/plain
File size: 5245 byte(s)
Renaming cdrecord.{c,h} to wodim.{c,h}
1 /*
2 * This file has been modified for the cdrkit suite.
3 *
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
6 *
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
10 *
11 */
12
13 /* @(#)scsi_scan.c 1.19 04/04/16 Copyright 1997-2004 J. Schilling */
14 #ifndef lint
15 static char sccsid[] =
16 "@(#)scsi_scan.c 1.19 04/04/16 Copyright 1997-2004 J. Schilling";
17 #endif
18 /*
19 * Scan SCSI Bus.
20 * Stolen from sformat. Need a more general form to
21 * re-use it in sformat too.
22 *
23 * Copyright (c) 1997-2004 J. Schilling
24 */
25 /*
26 * This program is free software; you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License version 2
28 * as published by the Free Software Foundation.
29 *
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
34 *
35 * You should have received a copy of the GNU General Public License along with
36 * this program; see the file COPYING. If not, write to the Free Software
37 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38 */
39
40 #include <mconfig.h>
41 #include <stdio.h>
42 #include <stdxlib.h>
43 #include <standard.h>
44 #include <btorder.h>
45 #include <errno.h>
46 #include <schily.h>
47
48 #include <scg/scgcmd.h>
49 #include <scg/scsidefs.h>
50 #include <scg/scsireg.h>
51 #include <scg/scsitransp.h>
52
53 #include "scsi_scan.h"
54 #include "wodim.h"
55
56 static void print_product(FILE *f, struct scsi_inquiry *ip);
57 int select_target(SCSI *scgp, FILE *f);
58 static int select_unit(SCSI *scgp, FILE *f);
59
60 static void
61 print_product(FILE *f, struct scsi_inquiry *ip)
62 {
63 fprintf(f, "'%.8s' ", ip->vendor_info);
64 fprintf(f, "'%.16s' ", ip->prod_ident);
65 fprintf(f, "'%.4s' ", ip->prod_revision);
66 if (ip->add_len < 31) {
67 fprintf(f, "NON CCS ");
68 }
69 scg_fprintdev(f, ip);
70 }
71
72 int
73 select_target(SCSI *scgp, FILE *f)
74 {
75 int initiator;
76 #ifdef FMT
77 int cscsibus = scg_scsibus(scgp);
78 int ctarget = scg_target(scgp);
79 int clun = scg_lun(scgp);
80 #endif
81 int n;
82 int low = -1;
83 int high = -1;
84 int amt = 0;
85 int bus;
86 int tgt;
87 int lun = 0;
88 BOOL have_tgt;
89
90 scgp->silent++;
91
92 for (bus = 0; bus < 256; bus++) {
93 scg_settarget(scgp, bus, 0, 0);
94
95 if (!scg_havebus(scgp, bus))
96 continue;
97
98 initiator = scg_initiator_id(scgp);
99 fprintf(f, "scsibus%d:\n", bus);
100
101 for (tgt = 0; tgt < 16; tgt++) {
102 n = bus*100 + tgt;
103
104 scg_settarget(scgp, bus, tgt, lun);
105 have_tgt = unit_ready(scgp) || scgp->scmd->error != SCG_FATAL;
106
107 if (!have_tgt && tgt > 7) {
108 if (scgp->scmd->ux_errno == EINVAL)
109 break;
110 continue;
111 }
112
113 #ifdef FMT
114 if (print_disknames(bus, tgt, -1) < 8)
115 fprintf(f, "\t");
116 else
117 fprintf(f, " ");
118 #else
119 fprintf(f, "\t");
120 #endif
121 if (fprintf(f, "%d,%d,%d", bus, tgt, lun) < 8)
122 fprintf(f, "\t");
123 else
124 fprintf(f, " ");
125 fprintf(f, "%3d) ", n);
126 if (tgt == initiator) {
127 fprintf(f, "HOST ADAPTOR\n");
128 continue;
129 }
130 if (!have_tgt) {
131 /*
132 * Hack: fd -> -2 means no access
133 */
134 fprintf(f, "%c\n", scgp->fd == -2 ? '?':'*');
135 continue;
136 }
137 amt++;
138 if (low < 0)
139 low = n;
140 high = n;
141
142 getdev(scgp, FALSE);
143 print_product(f, scgp->inq);
144 }
145 }
146 scgp->silent--;
147
148 if (low < 0) {
149 errmsgno(EX_BAD, "No target found.\n");
150 return (0);
151 }
152 n = -1;
153 #ifdef FMT
154 getint("Select target", &n, low, high);
155 bus = n/100;
156 tgt = n%100;
157 scg_settarget(scgp, bus, tgt, lun);
158 return (select_unit(scgp));
159
160 scg_settarget(scgp, cscsibus, ctarget, clun);
161 #endif
162 return (amt);
163 }
164
165 static int
166 select_unit(SCSI *scgp, FILE *f)
167 {
168 int initiator;
169 int clun = scg_lun(scgp);
170 int low = -1;
171 int high = -1;
172 int lun;
173
174 scgp->silent++;
175
176 fprintf(f, "scsibus%d target %d:\n", scg_scsibus(scgp), scg_target(scgp));
177
178 initiator = scg_initiator_id(scgp);
179 for (lun = 0; lun < 8; lun++) {
180
181 #ifdef FMT
182 if (print_disknames(scg_scsibus(scgp), scg_target(scgp), lun) < 8)
183 fprintf(f, "\t");
184 else
185 fprintf(f, " ");
186 #else
187 fprintf(f, "\t");
188 #endif
189 if (fprintf(f, "%d,%d,%d", scg_scsibus(scgp), scg_target(scgp), lun) < 8)
190 fprintf(f, "\t");
191 else
192 fprintf(f, " ");
193 fprintf(f, "%3d) ", lun);
194 if (scg_target(scgp) == initiator) {
195 fprintf(f, "HOST ADAPTOR\n");
196 continue;
197 }
198 scg_settarget(scgp, scg_scsibus(scgp), scg_target(scgp), lun);
199 if (!unit_ready(scgp) && scgp->scmd->error == SCG_FATAL) {
200 fprintf(f, "*\n");
201 continue;
202 }
203 if (unit_ready(scgp)) {
204 /* non extended sense illegal lun */
205 if (scgp->scmd->sense.code == 0x25) {
206 fprintf(f, "BAD UNIT\n");
207 continue;
208 }
209 }
210 if (low < 0)
211 low = lun;
212 high = lun;
213
214 getdev(scgp, FALSE);
215 print_product(f, scgp->inq);
216 }
217 scgp->silent--;
218
219 if (low < 0) {
220 errmsgno(EX_BAD, "No lun found.\n");
221 return (0);
222 }
223 lun = -1;
224 #ifdef FMT
225 getint("Select lun", &lun, low, high);
226 scg_settarget(scgp, scg_scsibus(scgp), scg_target(scgp), lun);
227 format_one(scgp);
228 return (1);
229 #endif
230
231 scg_settarget(scgp, scg_scsibus(scgp), scg_target(scgp), clun);
232 return (1);
233 }

  ViewVC Help
Powered by ViewVC 1.1.5