1 --- cdrtools-2.01/libscg/scsi-linux-sg.c.scan 2004-09-22 12:57:24.313986568 +0200
2 +++ cdrtools-2.01/libscg/scsi-linux-sg.c 2004-09-22 12:57:24.327984440 +0200
10 scgo_open(scgp, device)
15 register int nopen = 0;
17 - BOOL use_ata = FALSE;
19 + BOOL use_ata = FALSE;
22 if (busno >= MAX_SCG || tgt >= MAX_TGT || tlun >= MAX_LUN) {
24 @@ -383,103 +386,91 @@
25 * look silly but there may be users that did boot from a SCSI hdd
26 * and connected 4 CD/DVD writers to both IDE cables in the PC.
28 - if (use_ata) for (i = 0; i <= 25; i++) {
29 - js_snprintf(devname, sizeof (devname), "/dev/hd%c", i+'a');
30 - /* O_NONBLOCK is dangerous */
31 - f = open(devname, O_RDWR | O_NONBLOCK);
34 - * Set up error string but let us clear it later
35 - * if at least one open succeeded.
38 - js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE,
39 - "Cannot open '/dev/hd*'");
40 - if (errno != ENOENT && errno != ENXIO && errno != ENODEV) {
42 + glob("/dev/hd[a-z]", GLOB_NOSORT, NULL, &globbuf);
44 + for (i = 0; globbuf.gl_pathv && globbuf.gl_pathv[i] != NULL ; i++) {
45 + devname = globbuf.gl_pathv[i];
46 + f = open(devname, O_RDWR | O_NONBLOCK);
49 + * Set up error string but let us clear it later
50 + * if at least one open succeeded.
53 js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE,
54 - "Cannot open '%s'", devname);
60 - if (ioctl(f, SG_GET_TIMEOUT, &iparm) < 0) {
62 - js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE,
63 - "SCSI unsupported with '/dev/hd*'");
66 + "Cannot open '/dev/hd*'");
67 + if (errno != ENOENT && errno != ENXIO && errno != ENODEV && errno != EACCES) {
69 + js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE,
70 + "Cannot open '%s'", devname);
77 + if (ioctl(f, SG_GET_TIMEOUT, &iparm) < 0) {
79 + js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE,
80 + "SCSI unsupported with '/dev/hd*'");
84 + sg_clearnblock(f); /* Be very proper about this */
85 + if (sg_setup(scgp, f, busno, tgt, tlun, devname[7]-'a')) {
89 + if (busno < 0 && tgt < 0 && tlun < 0)
92 - sg_clearnblock(f); /* Be very proper about this */
93 - if (sg_setup(scgp, f, busno, tgt, tlun, i))
95 - if (busno < 0 && tgt < 0 && tlun < 0)
100 if (use_ata && nopen == 0)
102 if (nopen > 0 && scgp->errstr)
103 scgp->errstr[0] = '\0';
105 - if (nopen == 0) for (i = 0; i < 32; i++) {
106 - js_snprintf(devname, sizeof (devname), "/dev/sg%d", i);
107 - /* O_NONBLOCK is dangerous */
108 - f = open(devname, O_RDWR | O_NONBLOCK);
111 - * Set up error string but let us clear it later
112 - * if at least one open succeeded.
115 - js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE,
116 - "Cannot open '/dev/sg*'");
117 - if (errno != ENOENT && errno != ENXIO && errno != ENODEV) {
119 + glob("/dev/scd[0-9]", GLOB_NOSORT, NULL, &globbuf);
120 + glob("/dev/scd[0-9][0-9]", GLOB_NOSORT|GLOB_APPEND, NULL, &globbuf);
121 + /*glob("/dev/sg[a-z]", GLOB_NOSORT|GLOB_APPEND, NULL, &globbuf);*/
123 + for (i = 0; globbuf.gl_pathv && globbuf.gl_pathv[i] != NULL ; i++) {
124 + devname = globbuf.gl_pathv[i];
126 + f = open(devname, O_RDWR | O_NONBLOCK);
129 + * Set up error string but let us clear it later
130 + * if at least one open succeeded.
133 js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE,
134 - "Cannot open '%s'", devname);
136 + "Cannot open '/dev/scd*'");
137 + if (errno != ENOENT && errno != ENXIO && errno != ENODEV) {
139 + js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE,
140 + "Cannot open '%s'", devname);
141 + globfree(&globbuf);
145 + sg_clearnblock(f); /* Be very proper about this */
146 + if (sg_setup(scgp, f, busno, tgt, tlun, -1)) {
147 + globfree(&globbuf);
150 + if (busno < 0 && tgt < 0 && tlun < 0)
154 - sg_clearnblock(f); /* Be very proper about this */
155 - if (sg_setup(scgp, f, busno, tgt, tlun, -1))
157 - if (busno < 0 && tgt < 0 && tlun < 0)
161 if (nopen > 0 && scgp->errstr)
162 scgp->errstr[0] = '\0';
164 - if (nopen == 0) for (i = 0; i <= 25; i++) {
165 - js_snprintf(devname, sizeof (devname), "/dev/sg%c", i+'a');
166 - /* O_NONBLOCK is dangerous */
167 - f = open(devname, O_RDWR | O_NONBLOCK);
170 - * Set up error string but let us clear it later
171 - * if at least one open succeeded.
174 - js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE,
175 - "Cannot open '/dev/sg*'");
176 - if (errno != ENOENT && errno != ENXIO && errno != ENODEV) {
178 - js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE,
179 - "Cannot open '%s'", devname);
183 - sg_clearnblock(f); /* Be very proper about this */
184 - if (sg_setup(scgp, f, busno, tgt, tlun, -1))
186 - if (busno < 0 && tgt < 0 && tlun < 0)
190 - if (nopen > 0 && scgp->errstr)
191 - scgp->errstr[0] = '\0';
194 if (device != NULL && *device != '\0') {
195 --- cdrtools-2.01/libscg/scsi-linux-ata.c.scan 2004-06-12 12:48:12.000000000 +0200
196 +++ cdrtools-2.01/libscg/scsi-linux-ata.c 2004-09-22 12:57:24.330983984 +0200
201 - f = open(device, O_RDONLY | O_NONBLOCK);
202 + f = open(device, O_RDWR | O_NONBLOCK);
214 scan_internal(scgp, nopen)
216 @@ -293,118 +296,62 @@
225 * try always with devfs
226 * unfortunatelly the solution with test of existing
227 * of '/dev/.devfsd' don't work, because it root.root 700
228 * and i don't like run suid root
231 + BOOL DEVFS = FALSE;
234 - for (i = 0; ; i++) {
235 - sprintf(device, "/dev/cdroms/cdrom%i", i);
236 - if ((f = open(device, O_RDONLY | O_NONBLOCK)) < 0) {
237 - if (errno != ENOENT && errno != ENXIO && errno != ENODEV && errno != EACCES) {
238 - if (scgp->debug > 4) {
239 - js_fprintf((FILE *) scgp->errfile,
240 - "try open(%s) return %i, errno %i, cancel\n", device, f, errno);
243 - } else if (errno == ENOENT || errno == ENODEV) {
244 - if (scgp->debug > 4) {
245 - js_fprintf((FILE *) scgp->errfile,
246 - "try open(%s) return %i, errno %i\n", device, f, errno);
250 - if (scgp->debug > 4) {
251 - js_fprintf((FILE *) scgp->errfile,
252 - "DEVFS not detected, continuing with old dev\n");
257 + glob("/dev/cdroms/cdrom*",
260 + glob("/dev/hd[a-z]",
261 + GLOB_NOSORT|GLOB_APPEND,
263 + /*glob("/dev/scd*",
264 + GLOB_NOSORT|GLOB_APPEND,
267 + for (i = 0; globbuf.gl_pathv && globbuf.gl_pathv[i] != NULL ; i++) {
268 + device = globbuf.gl_pathv[i];
269 + if ((f = open(device, O_RDWR | O_NONBLOCK)) < 0) {
270 + if (errno != ENOENT && errno != ENXIO && errno != ENODEV && errno != EACCES) {
271 if (scgp->debug > 4) {
272 - if (errno == EACCES) {
273 - js_fprintf((FILE *) scgp->errfile,
274 - "errno (EACCESS), you don't have the needed rights for %s\n",
277 js_fprintf((FILE *) scgp->errfile,
278 - "try open(%s) return %i, errno %i, trying next cdrom\n",
280 + "try open(%s) return %i, errno %i, cancel\n", device, f, errno);
283 - if (scgp->debug > 4) {
284 + globfree(&globbuf);
287 + if (scgp->debug > 4) {
288 + if (errno == EACCES) {
289 js_fprintf((FILE *) scgp->errfile,
290 - "try open(%s) return %i errno %i calling sg_mapdev(...)\n",
293 - if (sg_amapdev(scgp, f, device, &schilly_bus, &target, &lun)) {
297 + "errno (EACCESS), you don't have the needed rights for %s\n",
300 + js_fprintf((FILE *) scgp->errfile,
301 + "try open(%s) return %i, errno %i, trying next cdrom\n",
307 - /* for /dev/sr0 - /dev/sr? */
308 - for (i = 0; ; i++) {
309 - sprintf(device, "/dev/sr%i", i);
310 - if ((f = open(device, O_RDONLY | O_NONBLOCK)) < 0) {
311 - if (errno != ENOENT && errno != ENXIO && errno != ENODEV && errno != EACCES) {
312 - if (scgp->debug > 4) {
313 - js_fprintf((FILE *) scgp->errfile,
314 - "try open(%s) return %i, errno %i, cancel\n",
318 - } else if (errno == ENOENT || errno == ENODEV) {
322 - if (sg_amapdev(scgp, f, device, &schilly_bus, &target, &lun)) {
328 + if (scgp->debug > 4) {
329 + js_fprintf((FILE *) scgp->errfile,
330 + "try open(%s) return %i errno %i calling sg_mapdev(...)\n",
335 - /* for /dev/hda - /dev/hdz */
336 - for (i = 'a'; i <= 'z'; i++) {
337 - sprintf(device, "/dev/hd%c", i);
338 - if ((f = open(device, O_RDONLY | O_NONBLOCK)) < 0) {
339 - if (errno != ENOENT && errno != ENXIO && errno != EACCES) {
340 - if (scgp->debug > 4) {
341 - js_fprintf((FILE *) scgp->errfile,
342 - "try open(%s) return %i, errno %i, cancel\n",
346 - } else if (errno == ENOENT || errno == ENODEV) {
349 + if (sg_amapdev(scgp, f, device, &schilly_bus, &target, &lun)) {
352 - /* ugly hack, make better, when you can. Alex */
353 - if (0 > ioctl(f, CDROM_DRIVE_STATUS, CDSL_CURRENT)) {
354 - if (scgp->debug > 4) {
355 - js_fprintf((FILE *) scgp->errfile,
356 - "%s is not a cdrom, skipping\n",
360 - } else if (sg_amapdev(scgp, f, device, &schilly_bus, &target, &lun)) {
369 + globfree(&globbuf);
373 --- cdrtools-2.01/libscg/scsi-linux-pg.c.scan 2004-01-15 01:54:36.000000000 +0100
374 +++ cdrtools-2.01/libscg/scsi-linux-pg.c 2004-09-22 12:59:04.107815600 +0200
382 scgo_open(scgp, device)
386 register int nopen = 0;
391 if (busno >= MAX_SCG || tgt >= MAX_TGT || tlun >= MAX_LUN) {
393 @@ -217,10 +221,14 @@
394 scglocal(scgp)->scgfiles[busno][tgt][tlun] = f;
399 - for (tgt = 0; tgt < MAX_TGT; tgt++) {
400 - js_snprintf(devname, sizeof (devname), "/dev/pg%d", tgt);
401 - f = open(devname, O_RDWR | O_NONBLOCK);
402 + glob("/dev/pg[0-9]", GLOB_NOSORT, NULL, &globbuf);
403 + glob("/dev/pg[0-9][0-9]", GLOB_NOSORT|GLOB_APPEND, NULL, &globbuf);
404 + for (i = 0; globbuf.gl_pathv && globbuf.gl_pathv[i] != NULL ; i++) {
405 + dev = globbuf.gl_pathv[i];
406 + tgt = atoi(&dev[7]);
407 + f = open(dev, O_RDWR | O_NONBLOCK);
410 * Set up error string but let us clear it later
412 if (errno != ENOENT && errno != ENXIO && errno != ENODEV) {
414 js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE,
415 - "Cannot open '%s'", devname);
416 + "Cannot open '%s'", dev);
417 + globfree(&globbuf);
425 + globfree(&globbuf);
428 if (nopen > 0 && scgp->errstr)
429 scgp->errstr[0] = '\0';