]>
Commit | Line | Data |
---|---|---|
b2f9b8e5 AM |
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 | |
3 | @@ -287,6 +287,8 @@ | |
4 | return (0); | |
5 | } | |
6 | ||
7 | +#include <glob.h> | |
8 | + | |
9 | LOCAL int | |
10 | scgo_open(scgp, device) | |
11 | SCSI *scgp; | |
12 | @@ -301,8 +303,9 @@ | |
13 | register int t; | |
14 | register int l; | |
15 | register int nopen = 0; | |
16 | - char devname[64]; | |
17 | - BOOL use_ata = FALSE; | |
18 | + char *devname; | |
19 | + BOOL use_ata = FALSE; | |
20 | + glob_t globbuf; | |
21 | ||
22 | if (busno >= MAX_SCG || tgt >= MAX_TGT || tlun >= MAX_LUN) { | |
23 | errno = EINVAL; | |
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. | |
27 | */ | |
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); | |
32 | - if (f < 0) { | |
33 | - /* | |
34 | - * Set up error string but let us clear it later | |
35 | - * if at least one open succeeded. | |
36 | - */ | |
37 | - if (scgp->errstr) | |
38 | - js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE, | |
39 | - "Cannot open '/dev/hd*'"); | |
40 | - if (errno != ENOENT && errno != ENXIO && errno != ENODEV) { | |
41 | + if (use_ata) { | |
42 | + glob("/dev/hd[a-z]", GLOB_NOSORT, NULL, &globbuf); | |
43 | + | |
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); | |
47 | + if (f < 0) { | |
48 | + /* | |
49 | + * Set up error string but let us clear it later | |
50 | + * if at least one open succeeded. | |
51 | + */ | |
52 | if (scgp->errstr) | |
53 | js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE, | |
54 | - "Cannot open '%s'", devname); | |
55 | - return (0); | |
56 | - } | |
57 | - } else { | |
58 | - int iparm; | |
59 | - | |
60 | - if (ioctl(f, SG_GET_TIMEOUT, &iparm) < 0) { | |
61 | - if (scgp->errstr) | |
62 | - js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE, | |
63 | - "SCSI unsupported with '/dev/hd*'"); | |
64 | - close(f); | |
65 | - continue; | |
66 | + "Cannot open '/dev/hd*'"); | |
67 | + if (errno != ENOENT && errno != ENXIO && errno != ENODEV && errno != EACCES) { | |
68 | + if (scgp->errstr) | |
69 | + js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE, | |
70 | + "Cannot open '%s'", devname); | |
71 | + globfree(&globbuf); | |
72 | + return (0); | |
73 | + } | |
74 | + } else { | |
75 | + int iparm; | |
76 | + | |
77 | + if (ioctl(f, SG_GET_TIMEOUT, &iparm) < 0) { | |
78 | + if (scgp->errstr) | |
79 | + js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE, | |
80 | + "SCSI unsupported with '/dev/hd*'"); | |
81 | + close(f); | |
82 | + continue; | |
83 | + } | |
84 | + sg_clearnblock(f); /* Be very proper about this */ | |
85 | + if (sg_setup(scgp, f, busno, tgt, tlun, devname[7]-'a')) { | |
86 | + globfree(&globbuf); | |
87 | + return (++nopen); | |
88 | + } | |
89 | + if (busno < 0 && tgt < 0 && tlun < 0) | |
90 | + nopen++; | |
91 | } | |
92 | - sg_clearnblock(f); /* Be very proper about this */ | |
93 | - if (sg_setup(scgp, f, busno, tgt, tlun, i)) | |
94 | - return (++nopen); | |
95 | - if (busno < 0 && tgt < 0 && tlun < 0) | |
96 | - nopen++; | |
97 | } | |
98 | + globfree(&globbuf); | |
99 | } | |
100 | if (use_ata && nopen == 0) | |
101 | return (0); | |
102 | if (nopen > 0 && scgp->errstr) | |
103 | scgp->errstr[0] = '\0'; | |
104 | ||
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); | |
109 | - if (f < 0) { | |
110 | - /* | |
111 | - * Set up error string but let us clear it later | |
112 | - * if at least one open succeeded. | |
113 | - */ | |
114 | - if (scgp->errstr) | |
115 | - js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE, | |
116 | - "Cannot open '/dev/sg*'"); | |
117 | - if (errno != ENOENT && errno != ENXIO && errno != ENODEV) { | |
118 | + if (nopen == 0) { | |
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);*/ | |
122 | + | |
123 | + for (i = 0; globbuf.gl_pathv && globbuf.gl_pathv[i] != NULL ; i++) { | |
124 | + devname = globbuf.gl_pathv[i]; | |
125 | + | |
126 | + f = open(devname, O_RDWR | O_NONBLOCK); | |
127 | + if (f < 0) { | |
128 | + /* | |
129 | + * Set up error string but let us clear it later | |
130 | + * if at least one open succeeded. | |
131 | + */ | |
132 | if (scgp->errstr) | |
133 | js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE, | |
134 | - "Cannot open '%s'", devname); | |
135 | - return (0); | |
136 | + "Cannot open '/dev/scd*'"); | |
137 | + if (errno != ENOENT && errno != ENXIO && errno != ENODEV) { | |
138 | + if (scgp->errstr) | |
139 | + js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE, | |
140 | + "Cannot open '%s'", devname); | |
141 | + globfree(&globbuf); | |
142 | + return (0); | |
143 | + } | |
144 | + } else { | |
145 | + sg_clearnblock(f); /* Be very proper about this */ | |
146 | + if (sg_setup(scgp, f, busno, tgt, tlun, -1)) { | |
147 | + globfree(&globbuf); | |
148 | + return (++nopen); | |
149 | + } | |
150 | + if (busno < 0 && tgt < 0 && tlun < 0) | |
151 | + nopen++; | |
152 | } | |
153 | - } else { | |
154 | - sg_clearnblock(f); /* Be very proper about this */ | |
155 | - if (sg_setup(scgp, f, busno, tgt, tlun, -1)) | |
156 | - return (++nopen); | |
157 | - if (busno < 0 && tgt < 0 && tlun < 0) | |
158 | - nopen++; | |
159 | } | |
160 | } | |
161 | if (nopen > 0 && scgp->errstr) | |
162 | scgp->errstr[0] = '\0'; | |
163 | ||
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); | |
168 | - if (f < 0) { | |
169 | - /* | |
170 | - * Set up error string but let us clear it later | |
171 | - * if at least one open succeeded. | |
172 | - */ | |
173 | - if (scgp->errstr) | |
174 | - js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE, | |
175 | - "Cannot open '/dev/sg*'"); | |
176 | - if (errno != ENOENT && errno != ENXIO && errno != ENODEV) { | |
177 | - if (scgp->errstr) | |
178 | - js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE, | |
179 | - "Cannot open '%s'", devname); | |
180 | - return (0); | |
181 | - } | |
182 | - } else { | |
183 | - sg_clearnblock(f); /* Be very proper about this */ | |
184 | - if (sg_setup(scgp, f, busno, tgt, tlun, -1)) | |
185 | - return (++nopen); | |
186 | - if (busno < 0 && tgt < 0 && tlun < 0) | |
187 | - nopen++; | |
188 | - } | |
189 | - } | |
190 | - if (nopen > 0 && scgp->errstr) | |
191 | - scgp->errstr[0] = '\0'; | |
192 | ||
193 | openbydev: | |
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 | |
197 | @@ -267,7 +267,7 @@ | |
198 | starget, | |
199 | slun; | |
200 | ||
201 | - f = open(device, O_RDONLY | O_NONBLOCK); | |
202 | + f = open(device, O_RDWR | O_NONBLOCK); | |
203 | ||
204 | if (f < 0) { | |
205 | if (scgp->errstr) | |
206 | @@ -283,6 +283,9 @@ | |
207 | return (nopen); | |
208 | } | |
209 | ||
210 | +#include <glob.h> | |
211 | + | |
212 | + | |
213 | LOCAL int | |
214 | scan_internal(scgp, nopen) | |
215 | SCSI *scgp; | |
216 | @@ -293,118 +296,62 @@ | |
217 | int schilly_bus, | |
218 | target, | |
219 | lun; | |
220 | - char device[128]; | |
221 | + char *device; | |
222 | + glob_t globbuf; | |
223 | + | |
224 | /* | |
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 | |
229 | */ | |
230 | - BOOL DEVFS = TRUE; | |
231 | + BOOL DEVFS = FALSE; | |
232 | ||
233 | - if (DEVFS) { | |
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); | |
241 | - } | |
242 | - return (-2); | |
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); | |
247 | - } | |
248 | - if (0 == i) { | |
249 | - DEVFS = FALSE; | |
250 | - if (scgp->debug > 4) { | |
251 | - js_fprintf((FILE *) scgp->errfile, | |
252 | - "DEVFS not detected, continuing with old dev\n"); | |
253 | - } | |
254 | - } | |
255 | - break; | |
256 | - } | |
257 | + glob("/dev/cdroms/cdrom*", | |
258 | + GLOB_NOSORT, | |
259 | + NULL, &globbuf); | |
260 | + glob("/dev/hd[a-z]", | |
261 | + GLOB_NOSORT|GLOB_APPEND, | |
262 | + NULL, &globbuf); | |
263 | + /*glob("/dev/scd*", | |
264 | + GLOB_NOSORT|GLOB_APPEND, | |
265 | + NULL, &globbuf);*/ | |
266 | + | |
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", | |
275 | - device); | |
276 | - } | |
277 | js_fprintf((FILE *) scgp->errfile, | |
278 | - "try open(%s) return %i, errno %i, trying next cdrom\n", | |
279 | - device, f, errno); | |
280 | + "try open(%s) return %i, errno %i, cancel\n", device, f, errno); | |
281 | } | |
282 | - } else { | |
283 | - if (scgp->debug > 4) { | |
284 | + globfree(&globbuf); | |
285 | + return (-2); | |
286 | + } | |
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", | |
291 | - device, f, errno); | |
292 | - } | |
293 | - if (sg_amapdev(scgp, f, device, &schilly_bus, &target, &lun)) { | |
294 | - (++(*nopen)); | |
295 | - } else { | |
296 | - close(f); | |
297 | + "errno (EACCESS), you don't have the needed rights for %s\n", | |
298 | + device); | |
299 | } | |
300 | + js_fprintf((FILE *) scgp->errfile, | |
301 | + "try open(%s) return %i, errno %i, trying next cdrom\n", | |
302 | + device, f, errno); | |
303 | } | |
304 | - } | |
305 | - } | |
306 | - if (!DEVFS) { | |
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", | |
315 | - device, f, errno); | |
316 | - } | |
317 | - return (-2); | |
318 | - } else if (errno == ENOENT || errno == ENODEV) { | |
319 | - break; | |
320 | - } | |
321 | - } else { | |
322 | - if (sg_amapdev(scgp, f, device, &schilly_bus, &target, &lun)) { | |
323 | - (++(*nopen)); | |
324 | - } else { | |
325 | - close(f); | |
326 | - } | |
327 | + } else { | |
328 | + if (scgp->debug > 4) { | |
329 | + js_fprintf((FILE *) scgp->errfile, | |
330 | + "try open(%s) return %i errno %i calling sg_mapdev(...)\n", | |
331 | + device, f, errno); | |
332 | } | |
333 | - } | |
334 | - | |
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", | |
343 | - device, f, errno); | |
344 | - } | |
345 | - return (-2); | |
346 | - } else if (errno == ENOENT || errno == ENODEV) { | |
347 | - break; | |
348 | - } | |
349 | + if (sg_amapdev(scgp, f, device, &schilly_bus, &target, &lun)) { | |
350 | + (++(*nopen)); | |
351 | } else { | |
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", | |
357 | - device); | |
358 | - } | |
359 | - close(f); | |
360 | - } else if (sg_amapdev(scgp, f, device, &schilly_bus, &target, &lun)) { | |
361 | - (++(*nopen)); | |
362 | - } else { | |
363 | - close(f); | |
364 | - } | |
365 | + close(f); | |
366 | } | |
367 | } | |
368 | } | |
369 | + globfree(&globbuf); | |
370 | return (0); | |
371 | } | |
372 | ||
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 | |
375 | @@ -130,6 +130,8 @@ | |
376 | return (0); | |
377 | } | |
378 | ||
379 | +#include <glob.h> | |
380 | + | |
381 | LOCAL int | |
382 | scgo_open(scgp, device) | |
383 | SCSI *scgp; | |
384 | @@ -146,6 +148,8 @@ | |
385 | #endif | |
386 | register int nopen = 0; | |
387 | char devname[32]; | |
388 | + glob_t globbuf; | |
389 | + int i; | |
390 | ||
391 | if (busno >= MAX_SCG || tgt >= MAX_TGT || tlun >= MAX_LUN) { | |
392 | errno = EINVAL; | |
393 | @@ -217,10 +221,14 @@ | |
394 | scglocal(scgp)->scgfiles[busno][tgt][tlun] = f; | |
395 | return (1); | |
396 | } else { | |
397 | + const char *dev; | |
398 | tlun = 0; | |
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); | |
408 | if (f < 0) { | |
409 | /* | |
410 | * Set up error string but let us clear it later | |
411 | @@ -232,7 +240,8 @@ | |
412 | if (errno != ENOENT && errno != ENXIO && errno != ENODEV) { | |
413 | if (scgp->errstr) | |
414 | js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE, | |
415 | - "Cannot open '%s'", devname); | |
416 | + "Cannot open '%s'", dev); | |
417 | + globfree(&globbuf); | |
418 | return (0); | |
419 | } | |
420 | } else { | |
421 | @@ -240,6 +249,8 @@ | |
422 | nopen++; | |
423 | } | |
424 | } | |
425 | + globfree(&globbuf); | |
426 | + | |
427 | } | |
428 | if (nopen > 0 && scgp->errstr) | |
429 | scgp->errstr[0] = '\0'; |