[Debburn-changes] r734 - in cdrkit/trunk: icedax libusal
libusal/usal wodim
Eduard Bloch
blade at alioth.debian.org
Tue Apr 10 15:01:49 UTC 2007
Author: blade
Date: 2007-04-10 15:01:46 +0000 (Tue, 10 Apr 2007)
New Revision: 734
Modified:
cdrkit/trunk/icedax/interface.c
cdrkit/trunk/libusal/scsi-linux-sg.c
cdrkit/trunk/libusal/scsihack.c
cdrkit/trunk/libusal/scsiopen.c
cdrkit/trunk/libusal/usal/usalops.h
cdrkit/trunk/wodim/scsi_scan.c
cdrkit/trunk/wodim/wodim.c
Log:
Rewrite of native device name management, inified the scan method with libusal, rewrote scandevs code with sth. based on scanbus method.
Modified: cdrkit/trunk/icedax/interface.c
===================================================================
--- cdrkit/trunk/icedax/interface.c 2007-04-09 14:23:17 UTC (rev 733)
+++ cdrkit/trunk/icedax/interface.c 2007-04-10 15:01:46 UTC (rev 734)
@@ -613,7 +613,7 @@
}
if (global.scandevs) {
- scan_devices();
+ list_devices(stdout);
exit(0);
}
Modified: cdrkit/trunk/libusal/scsi-linux-sg.c
===================================================================
--- cdrkit/trunk/libusal/scsi-linux-sg.c 2007-04-09 14:23:17 UTC (rev 733)
+++ cdrkit/trunk/libusal/scsi-linux-sg.c 2007-04-10 15:01:46 UTC (rev 734)
@@ -162,7 +162,7 @@
* XXX Should add extra space in buscookies and usalfiles for a "PP bus"
* XXX and for two or more "ATAPI busses".
*/
-#define MAX_SCG 256 /* Max # of SCSI controllers */
+#define MAX_SCG 1256 /* Max # of SCSI controllers */
#define MAX_TGT 16
#define MAX_LUN 8
@@ -181,6 +181,7 @@
struct usal_local {
int usalfile; /* Used for SG_GET_BUFSIZE ioctl()*/
short usalfiles[MAX_SCG][MAX_TGT][MAX_LUN];
+ char *filenames[MAX_SCG][MAX_TGT][MAX_LUN];
short buscookies[MAX_SCG];
int pgbus;
int pack_id; /* Should be a random number */
@@ -199,7 +200,6 @@
/*
* Flag definitions
*/
-#define LF_ATA 0x01 /* Using /dev/hd* ATA interface */
#ifdef SG_BIG_BUFF
#define MAX_DMA_LINUX SG_BIG_BUFF /* Defined in include/scsi/sg.h */
@@ -234,7 +234,7 @@
#endif
static void sg_clearnblock(int f);
static BOOL sg_setup(SCSI *usalp, int f, int busno, int tgt, int tlun,
- int ataidx);
+ int ataidx, char *origname);
static void sg_initdev(SCSI *usalp, int f);
static int sg_mapbus(SCSI *usalp, int busno, int ino);
static BOOL sg_mapdev(SCSI *usalp, int f, int *busp, int *tgtp, int *lunp,
@@ -312,6 +312,7 @@
{
if (usalp != (SCSI *)0) {
#ifdef USE_PG
+#error pg-junk
/*
* If we only have a Parallel port or only opened a handle
* for PP, just return PP version.
@@ -370,45 +371,24 @@
#define in_scanmode (busno < 0 && tgt < 0 && tlun < 0)
-#if 0
-static int
-usalo_open(SCSI *usalp, char *device)
-{
- if(!usalp && dev && strncmp("ATA", dev, 3) ) {
- char *dalt;
- int len=5+strlen(dev);
-
- fprintf(stderr, "Unable to open, trying with ATA: prefix...\n");
- dalt=calloc(len, sizeof(char));
- strcat(dalt, "ATA:");
- strcat(dalt+4, dev);
- usalp = usal_open(dalt, errstr, sizeof (errstr),
- debug, lverbose);
- }
-
-
-}
-#endif
-
/*
* b/t/l is chopped of the device string.
*/
static int
usalo_open(SCSI *usalp, char *device)
{
- int busno = usal_scsibus(usalp);
- int tgt = usal_target(usalp);
- int tlun = usal_lun(usalp);
- register int f;
- register int i;
- register int b;
- register int t;
- register int l;
- register int nopen = 0;
- char devname[64];
- BOOL use_ata = FALSE;
+ int busno = usal_scsibus(usalp);
+ int tgt = usal_target(usalp);
+ int tlun = usal_lun(usalp);
+ register int f;
+ register int i;
+ register int b;
+ register int t;
+ register int l;
+ register int nopen = 0;
+ char devname[64];
+ int fake_atabus=0;
-
if (busno >= MAX_SCG || tgt >= MAX_TGT || tlun >= MAX_LUN) {
errno = EINVAL;
if (usalp->errstr)
@@ -430,37 +410,46 @@
}
if (device != NULL && *device != '\0') {
- if(check_linux_26()) {
- if(0==strncmp(device, "ATAPI:", 6))
- {
- device+=6;
- fprintf(stderr, "\nWarning, the ATAPI: method is considered deprecated on modern kernels!\n"
- "Mapping device specification to dev=%s now.\n"
- "To force the old ATAPI: method, replace ATAPI: with OLDATAPI:\n", device);
- }
- if(0==strncmp(device, "OLDATAPI:", 9))
- device+=3;
- }
-
-#ifdef USE_OLD_ATAPI
- if (strncmp(device, "ATAPI", 5) == 0) {
+ fake_atabus=0;
+ if(0==strncmp(device, "OLDATAPI", 8)) {
+ device+=3;
usalp->ops = &ata_ops;
return (SCGO_OPEN(usalp, device));
}
-#endif
- if (strcmp(device, "ATA") == 0) {
- use_ata = TRUE;
- device = NULL;
+ else if(0==strncmp(device, "ATAPI", 5)) {
+ if(check_linux_26()) {
+ device+=5;
+ fake_atabus=1;
+ fprintf(stderr, "WARNING: the ATAPI: method is considered deprecated on modern kernels!\n"
+ "Mapping device specification to ATA: method now.\n"
+ "To force the old ATAPI: method, replace ATAPI: with OLDATAPI:\n");
+ }
+ else {
+ usalp->ops = &ata_ops;
+ return (SCGO_OPEN(usalp, device));
+ }
}
+ else if(0==strncmp(device, "ATA", 3)) {
+ fprintf(stderr, "WARNING: the ATA: method is considered deprecated on modern kernels!\n"
+ "Use --devices to display the native names.\n");
+ fake_atabus=1;
+ device+=3;
+ }
+ if(device[0]==':')
+ device++;
+
}
else if( ! in_scanmode ) {
- fprintf(stderr, "\nWarning, the deprecated pseudo SCSI syntax found as device specification.\n"
+ fprintf(stderr, "WARNING: the deprecated pseudo SCSI syntax found as device specification.\n"
"Support for that may cease in the future versions of wodim. For now,\n"
"the device will be mapped to a block device file where possible.\n"
"Run \"wodim --devices\" for details.\n" );
sleep(5);
}
+#warning fallbacks hier?
+#warning teste ATA: und ATA
+
if (usalp->local == NULL) {
usalp->local = malloc(sizeof (struct usal_local));
if (usalp->local == NULL)
@@ -473,8 +462,6 @@
usallocal(usalp)->drvers = -1;
usallocal(usalp)->isold = -1;
usallocal(usalp)->flags = 0;
- if (use_ata)
- usallocal(usalp)->flags |= LF_ATA;
usallocal(usalp)->xbufsize = 0L;
usallocal(usalp)->xbuf = NULL;
@@ -483,199 +470,24 @@
for (t = 0; t < MAX_TGT; t++) {
for (l = 0; l < MAX_LUN; l++)
usallocal(usalp)->usalfiles[b][t][l] = (short)-1;
+ usallocal(usalp)->filenames[b][t][l] = NULL;
}
}
}
- if (use_ata)
- goto scanopen;
-
- if ((device != NULL && *device != '\0') || (busno == -2 && tgt == -2))
- goto openbydev;
-
-scanopen:
- if (use_ata) {
- for (i=2*busno+tgt >= 0 ? 2*busno+tgt:0; i <= 25; i++) {
- snprintf(devname, sizeof (devname), "/dev/hd%c", i+'a');
- /* O_NONBLOCK is dangerous */
- f = sg_open_excl(devname, O_RDWR | O_NONBLOCK, in_scanmode);
- if (f < 0) {
- /*
- * Set up error string but let us clear it later
- * if at least one open succeeded.
- */
- if (usalp->errstr)
- snprintf(usalp->errstr, SCSI_ERRSTR_SIZE,
- "Cannot open '%s'", devname);
- if (errno != ENOENT && errno != ENXIO && errno != ENODEV) {
- if (usalp->errstr)
- snprintf(usalp->errstr, SCSI_ERRSTR_SIZE,
- "Cannot open '%s'", devname);
- continue;
- }
- } else {
- int iparm;
-
- if (ioctl(f, SG_GET_TIMEOUT, &iparm) < 0) {
- if (usalp->errstr)
- snprintf(usalp->errstr, SCSI_ERRSTR_SIZE,
- "SCSI unsupported with '%s'", devname);
- close(f);
- continue;
- }
- sg_clearnblock(f); /* Be very proper about this */
- if (sg_setup(usalp, f, busno, tgt, tlun, i))
- return (++nopen);
- if (in_scanmode)
- nopen++;
- }
- }
-
- if(nopen==0)
- return(0);
- }
- /*
- else if(in_scanmode) {
- fprintf(stderr, "ATAPI devices not scanned.\n"
- "wodim: HINT : To surely see all drives try option: --devices\n"
- "wodim: HINT : Or try options: dev=ATA -scanbus\n"
- );
- }
- */
-
- if (nopen > 0 && usalp->errstr)
- usalp->errstr[0] = '\0';
-
- if(nopen == 0 && check_linux_26())
+ if (device != NULL && *device != '\0')
{
- for (i = 0; i < 32; i++) {
- snprintf(devname, sizeof (devname), "/dev/sr%d", i);
- /* O_NONBLOCK is dangerous */
- f = sg_open_excl(devname, O_RDWR | O_NONBLOCK, in_scanmode);
- if (f < 0) {
- /*
- * Set up error string but let us clear it later
- * if at least one open succeeded.
- */
- if (usalp->errstr)
- snprintf(usalp->errstr, SCSI_ERRSTR_SIZE,
- "Cannot open '%s'", devname);
- /*
- * Stop this paranoia, continue scanning.
- if(errno == EACCES || errno==EPERM || errno == EBUSY)
- continue;
- if (errno != ENOENT && errno != ENXIO && errno != ENODEV) {
- if (usalp->errstr)
- snprintf(usalp->errstr, SCSI_ERRSTR_SIZE,
- "Cannot open '%s'", devname);
- return (0);
- }
- */
- } else {
- sg_clearnblock(f); /* Be very proper about this */
- if (sg_setup(usalp, f, busno, tgt, tlun, -1))
- return (++nopen);
- if (in_scanmode)
- nopen++;
- }
- }
- }
- if (nopen > 0 && usalp->errstr)
- usalp->errstr[0] = '\0';
-
- if (nopen == 0) { /* don't do it if sr driver is working */
- for (i = 0; i < 32; i++) {
- snprintf(devname, sizeof (devname), "/dev/sg%d", i);
- /* O_NONBLOCK is dangerous */
- f = sg_open_excl(devname, O_RDWR | O_NONBLOCK, in_scanmode);
- if (f < 0) {
- /*
- * Set up error string but let us clear it later
- * if at least one open succeeded.
- */
- if (usalp->errstr)
- snprintf(usalp->errstr, SCSI_ERRSTR_SIZE,
- "Cannot open '%s'", devname);
- /*
- * Stop this paranoia, continue scanning.
- if(errno == EACCES || errno==EPERM || errno==EBUSY)
- continue;
- if (errno != ENOENT && errno != ENXIO && errno != ENODEV) {
- if (usalp->errstr)
- snprintf(usalp->errstr, SCSI_ERRSTR_SIZE,
- "Cannot open '%s'", devname);
- return (0);
- }
- */
- } else {
- sg_clearnblock(f); /* Be very proper about this */
- if (sg_setup(usalp, f, busno, tgt, tlun, -1))
- return (++nopen);
- if (in_scanmode)
- nopen++;
- }
- }
- }
- if (nopen > 0 && usalp->errstr)
- usalp->errstr[0] = '\0';
-
- if (nopen == 0) {
- for (i = 0; i <= 25; i++) {
- snprintf(devname, sizeof (devname), "/dev/sg%c", i+'a');
- /* O_NONBLOCK is dangerous */
- f = sg_open_excl(devname, O_RDWR | O_NONBLOCK, in_scanmode);
- if (f < 0) {
- /*
- * Set up error string but let us clear it later
- * if at least one open succeeded.
- */
- if (usalp->errstr)
- snprintf(usalp->errstr, SCSI_ERRSTR_SIZE,
- "Cannot open '%s'", devname);
- /*
- * Stop this paranoia, continue scanning.
- if(errno == EACCES || errno==EPERM || errno=EBUSY)
- continue;
- if (errno != ENOENT && errno != ENXIO && errno != ENODEV) {
- if (usalp->errstr)
- snprintf(usalp->errstr, SCSI_ERRSTR_SIZE,
- "Cannot open '%s'", devname);
- return (0);
- }
- */
- } else {
- sg_clearnblock(f); /* Be very proper about this */
- if (sg_setup(usalp, f, busno, tgt, tlun, -1))
- return (++nopen);
- if (in_scanmode)
- nopen++;
- }
- }
- }
- if (nopen > 0 && usalp->errstr)
- usalp->errstr[0] = '\0';
-
-openbydev:
-
- if (device != NULL && *device != '\0') {
+ /* open ONE directly */
b = -1;
- char buf[100];
- if (strlen(device) == 8 && strncmp(device, "/dev/hd", 7) == 0) {
+ if (device && strncmp(device, "/dev/hd", 7) == 0 && device[8]=='\0') {
b = device[7] - 'a';
if (b < 0 || b > 25)
- b = -1;
- }
- /* O_NONBLOCK is dangerous */
- /* Let the user open what he wants this time, the mapping is sysfs depending anyway and may be unreliable
- if(0==strncmp(device, "/dev/sg", 7)) {
- strncpy(buf, device, sizeof(buf)-1);
- map_sg_to_block(buf, sizeof(buf));
- device=buf;
- }
- * */
+ b = -1;
+ }
+ if(b>=0 && fake_atabus)
+ b+=1000;
+
f = sg_open_excl(device, O_RDWR | O_NONBLOCK, FALSE);
-/* if (f < 0 && errno == ENOENT)*/
-/* goto openpg;*/
if (f < 0) {
/*
@@ -685,37 +497,116 @@
*/
if (usalp->errstr)
snprintf(usalp->errstr, SCSI_ERRSTR_SIZE,
- "Cannot open '%s'",
- device);
+ "Cannot open '%s'",
+ device);
return (0);
}
-
- sg_clearnblock(f); /* Be very proper about this */
- if (!sg_mapdev(usalp, f, &busno, &tgt, &tlun, 0, 0, b)) {
- close(f);
- /*
- * If sg_mapdev() failes, this may be /dev/pg* device.
- */
- goto openpg;
- }
-
-#ifdef OOO
- if (usal_scsibus(usalp) < 0)
- usal_scsibus(usalp) = busno;
- if (usal_target(usalp) < 0)
- usal_target(usalp) = tgt;
- if (usal_lun(usalp) < 0)
- usal_lun(usalp) = tlun;
-#endif
-
+ sg_clearnblock(f);
+ /* get some fake SCSI data */
+ sg_mapdev(usalp, f, &busno, &tgt, &tlun, 0, 0, b);
usal_settarget(usalp, busno, tgt, tlun);
- if (sg_setup(usalp, f, busno, tgt, tlun, b))
+ if (sg_setup(usalp, f, busno, tgt, tlun, b, device))
return (++nopen);
}
-openpg:
-#ifdef USE_PG
- nopen += pg_open(usalp, device);
+ else {
+ /* scan and maybe keep one open, sg_setup decides */
+#define HDX 0
+#define SCD 1
+#define SG 2
+ int h;
+retry_scan_open:
+ for(h=HDX; h <= (fake_atabus ? HDX : SG) ; h++) {
+ char *pattern;
+ unsigned int first, last;
+ switch(h) {
+ case(HDX):
+ {
+ pattern="/dev/hd%c";
+ first='a';
+ last='z';
+ break;
+ }
+ case(SCD):
+ {
+ if(!check_linux_26())
+ continue;
+ pattern="/dev/scd%d";
+ first=0;
+ last=255;
+ break;
+ }
+ case(SG):
+ {
+ if(check_linux_26())
+ continue;
+#if 0
+ /*
+ * Don't touch it on 2.6 until we have a proper locking scheme
+ */
+ if(nopen<=0)
+ fprintf(stderr, "Warning, using /dev/sg* for SG_IO operation. This method is considered harmful.\n");
+ else if(found_scd)
+ continue;
#endif
+ pattern="/dev/sg%d";
+ first=0;
+ last=255;
+ break;
+ }
+ }
+ for(i=first; i<=last; i++) {
+ snprintf(devname, sizeof (devname), pattern, i);
+ f = sg_open_excl(devname, O_RDWR | O_NONBLOCK, in_scanmode);
+ if (f < 0) {
+ if (usalp->errstr)
+ snprintf(usalp->errstr, SCSI_ERRSTR_SIZE,
+ "Cannot open '%s'", devname);
+ } else {
+ if(h == HDX) { // double-check the capabilities on ATAPI devices
+ int iparm;
+
+ if (ioctl(f, SG_GET_TIMEOUT, &iparm) < 0) {
+ if (usalp->errstr)
+ snprintf(usalp->errstr, SCSI_ERRSTR_SIZE,
+ "SCSI unsupported with '%s'", devname);
+ close(f);
+ continue;
+ }
+ }
+ sg_clearnblock(f); /* Be very proper about this */
+
+ /* construct the fake bus number hint, keep it readable */
+ b=-1;
+ if(h==HDX) {
+ b=i-'a';
+ if(!fake_atabus)
+ b+=1000;
+ }
+
+ /* sg_setup returns false in scan mode, true if one single target was specified and opened */
+ if (sg_setup(usalp, f, busno, tgt, tlun, b, devname))
+ return (++nopen);
+
+ if (in_scanmode)
+ nopen++;
+ }
+ }
+
+ if (nopen > 0 && usalp->errstr)
+ usalp->errstr[0] = '\0';
+
+ /* that's crap, should not be reached in non-scan mode.
+ * Let's see whether it can be mapped to an atapi
+ * device to emulate some old cludge's behaviour. */
+ if(!in_scanmode && busno < 1000 && busno >=0) {
+ fake_atabus=1;
+ fprintf(stderr, "Unable to open this SCSI ID. Trying to map to old ATA syntax."
+ "This workaround will disappear in the near future. Fix your configuration.");
+ goto retry_scan_open;
+ }
+ }
+ }
+
if (usalp->debug > 0) for (b = 0; b < MAX_SCG; b++) {
fprintf((FILE *)usalp->errfile,
"Bus: %d cookie: %X\n",
@@ -730,11 +621,6 @@
}
}
}
- if(nopen==0 && !use_ata) {
- use_ata=TRUE;
- fprintf(stderr, "Unable to open, trying with ATA: prefix...\n");
- goto scanopen;
- }
return (nopen);
}
@@ -760,6 +646,10 @@
if (f >= 0)
close(f);
usallocal(usalp)->usalfiles[b][t][l] = (short)-1;
+ if(usallocal(usalp)->filenames[b][t][l]) {
+ free(usallocal(usalp)->filenames[b][t][l]);
+ usallocal(usalp)->filenames[b][t][l]=NULL;
+ }
}
}
}
@@ -794,11 +684,11 @@
/*!
*
- * Return: TRUE when single target is chosen and was opened successfully, FALSE otherwise
+ * Return: TRUE when single target is chosen and was opened successfully, FALSE otherwise (on scans, etc).
*/
static BOOL
-sg_setup(SCSI *usalp, int f, int busno, int tgt, int tlun, int ataidx)
+sg_setup(SCSI *usalp, int f, int busno, int tgt, int tlun, int ataidx, char *origname)
{
int n;
int Chan;
@@ -846,6 +736,9 @@
if (usallocal(usalp)->usalfiles[Bus][Target][Lun] == (short)-1)
usallocal(usalp)->usalfiles[Bus][Target][Lun] = (short)f;
+ if (usallocal(usalp)->filenames[Bus][Target][Lun] == NULL)
+ usallocal(usalp)->filenames[Bus][Target][Lun] = strdup(origname);
+
if (onetarget) {
if (Bus == busno && Target == tgt && Lun == tlun) {
sg_initdev(usalp, f);
@@ -939,8 +832,10 @@
usallocal(usalp)->buscookies[busno] = ino;
return (busno);
}
- if (usallocal(usalp)->buscookies[busno] != (short)ino)
+ /*
+ * if (usallocal(usalp)->buscookies[busno] != (short)ino)
errmsgno(EX_BAD, "Warning Linux Bus mapping botch.\n");
+ */
return (busno);
} else for (i = 0; i < MAX_SCG; i++) {
@@ -974,8 +869,8 @@
* The badly designed /dev/hd* interface maps everything
* to 0,0,0 so we need to do the mapping ourselves.
*/
- *busp = ataidx / 2;
- *tgtp = ataidx % 2;
+ *busp = (ataidx/1000) * 1000;
+ *tgtp = ataidx%1000;
*lunp = 0;
if (chanp)
*chanp = 0;
@@ -1262,6 +1157,12 @@
static int
usalo_isatapi(SCSI *usalp)
{
+ return -1;
+#if 0
+ /*
+ * Who exactly needs this information? Just for some bitching in wodim?
+ * Is this an _abstraction_ layer or spam layer?
+ */
#ifdef USE_PG
if (usal_scsibus(usalp) == usallocal(usalp)->pgbus)
return (pg_isatapi(usalp));
@@ -1288,6 +1189,7 @@
}
#endif
return (-1);
+#endif
}
static int
@@ -1841,4 +1743,11 @@
if (sp->timeout != usalp->deftimeout)
sg_settimeout(f, usalp->deftimeout);
return (0);
+};
+
+#define HAVE_NAT_NAMES
+static char * usalo_natname(SCSI *usalp, int busno, int tgt, int tlun) {
+ if (busno >= MAX_SCG || tgt >= MAX_TGT || tlun >= MAX_LUN)
+ return "BADID";
+ return usallocal(usalp)->filenames[busno][tgt][tlun];
}
Modified: cdrkit/trunk/libusal/scsihack.c
===================================================================
--- cdrkit/trunk/libusal/scsihack.c 2007-04-09 14:23:17 UTC (rev 733)
+++ cdrkit/trunk/libusal/scsihack.c 2007-04-10 15:01:46 UTC (rev 734)
@@ -84,6 +84,7 @@
static BOOL usalo_havebus(SCSI *usalp, int busno);
static int usalo_fileno(SCSI *usalp, int busno, int tgt, int tlun);
+static char * usalo_natname(SCSI *usalp, int busno, int tgt, int tlun);
static int usalo_initiator_id(SCSI *usalp);
static int usalo_isatapi(SCSI *usalp);
static int usalo_reset(SCSI *usalp, int what);
@@ -104,6 +105,7 @@
usalo_initiator_id,
usalo_isatapi,
usalo_reset,
+ usalo_natname,
};
/*#undef sun*/
@@ -317,6 +319,7 @@
usalo_dinitiator_id,
usalo_disatapi,
usalo_dreset,
+ usalo_natname,
};
usal_ops_t usal_dummy_ops = {
@@ -333,6 +336,7 @@
usalo_dinitiator_id,
usalo_disatapi,
usalo_dreset,
+ usalo_natname,
};
/*
@@ -444,6 +448,14 @@
return (-1);
}
+#ifndef HAVE_NAT_NAMES /* to be defined in included source if supported */
+static char * usalo_natname(SCSI *usalp, int busno, int tgt, int tlun) {
+ static char namebuf[81];
+ snprintf(namebuf, 80, "%d,%d,%d", usal_scsibus(usalp), usal_target(usalp), usal_lun(usalp));
+ return namebuf;
+}
+#endif
+
static int
usalo_dinitiator_id(SCSI *usalp)
{
Modified: cdrkit/trunk/libusal/scsiopen.c
===================================================================
--- cdrkit/trunk/libusal/scsiopen.c 2007-04-09 14:23:17 UTC (rev 733)
+++ cdrkit/trunk/libusal/scsiopen.c 2007-04-10 15:01:46 UTC (rev 734)
@@ -378,6 +378,14 @@
return (0);
}
+char * usal_natname(SCSI *usalp, int busno, int tgt, int tlun) {
+ return usalp->ops->usalo_natname(usalp, busno, tgt, tlun);
+}
+
+int usal_fileno(SCSI *usalp, int busno, int tgt, int tlun) {
+ return usalp->ops->usalo_fileno(usalp, busno, tgt, tlun);
+}
+
void
usal_settimeout(SCSI *usalp, int timeout)
{
Modified: cdrkit/trunk/libusal/usal/usalops.h
===================================================================
--- cdrkit/trunk/libusal/usal/usalops.h 2007-04-09 14:23:17 UTC (rev 733)
+++ cdrkit/trunk/libusal/usal/usalops.h 2007-04-10 15:01:46 UTC (rev 734)
@@ -54,9 +54,12 @@
BOOL (*usalo_havebus)(SCSI *usalp, int busno);
int (*usalo_fileno)(SCSI *usalp, int busno, int tgt, int tlun);
+
int (*usalo_initiator_id)(SCSI *usalp);
int (*usalo_isatapi)(SCSI *usalp);
int (*usalo_reset)(SCSI *usalp, int what);
+
+ char * (*usalo_natname)(SCSI *usalp, int busno, int tgt, int tlun);
} usal_ops_t;
#define SCGO_SEND(usalp) (*(usalp)->ops->usalo_send)(usalp)
Modified: cdrkit/trunk/wodim/scsi_scan.c
===================================================================
--- cdrkit/trunk/wodim/scsi_scan.c 2007-04-09 14:23:17 UTC (rev 733)
+++ cdrkit/trunk/wodim/scsi_scan.c 2007-04-10 15:01:46 UTC (rev 734)
@@ -57,9 +57,6 @@
static void print_product(FILE *f, struct scsi_inquiry *ip);
int select_target(SCSI *usalp, FILE *f);
-#ifdef DEAD_CODE
-static int select_unit(SCSI *usalp, FILE *f);
-#endif
extern BOOL check_linux_26();
@@ -75,133 +72,110 @@
#define MAXDEVCOUNT (256+26)
-int scan_devices() {
- struct stat statbuf;
- char *lines[MAXDEVCOUNT];
- char buf[256], devname[256], perms[8];
- SCSI *usalp;
- int i, ndevs=0;
- BOOL have_tgt;
-#ifdef linux
- const char *srdev = check_linux_26() ? "/dev/scd" : "/dev/sg";
- fprintf(stderr, "Beginning native device scan. This may take a while if devices are busy...\n");
+# warning Check windows SPT driver
- for(i=0;i<MAXDEVCOUNT;i++) {
- if(i<26)
- snprintf(devname, sizeof (devname), "/dev/hd%c", 'a'+i);
- else
- snprintf(devname, sizeof (devname), "%s%d", srdev, i-26);
+int list_devices(SCSI *usalp, FILE *f) {
+ int initiator;
+#ifdef FMT
+ int cscsibus = usal_scsibus(usalp);
+ int ctarget = usal_target(usalp);
+ int clun = usal_lun(usalp);
+#endif
+ int n, i;
+ int low = -1;
+ int high = -1;
+ int amt = 0;
+ int bus;
+ int tgt;
+ int lun = 0;
+ BOOL have_tgt;
- if(stat(devname, &statbuf))
- continue;
+ int fd, ndevs=0;
+ struct stat statbuf;
+ char *lines[MAXDEVCOUNT];
+ char buf[256], perms[8], *p;
- usalp = usal_open(devname, buf, sizeof (buf), 0, 0);
- if(!usalp) continue;
- usalp->silent++;
- have_tgt = unit_ready(usalp) || usalp->scmd->error != SCG_FATAL;
+ usalp->silent++;
- strcpy(perms,"------");
- if(statbuf.st_mode&S_IRUSR) perms[0]= 'r';
- if(statbuf.st_mode&S_IWUSR) perms[1]= 'w';
- if(statbuf.st_mode&S_IRGRP) perms[2]= 'r';
- if(statbuf.st_mode&S_IWGRP) perms[3]= 'w';
- if(statbuf.st_mode&S_IROTH) perms[4]= 'r';
- if(statbuf.st_mode&S_IWOTH) perms[5]= 'w';
+ /* XXX should be done before opening usal fprintf(stderr, "Beginning native device scan. This may take a while if devices are busy...\n"); */
- if(have_tgt) {
- char *p;
+ for (bus = 0; bus < 1256; bus++) {
+ usal_settarget(usalp, bus, 0, 0);
- getdev(usalp, FALSE);
- for(p=usalp->inq->vendor_info + 7 ; p >= usalp->inq->vendor_info; p--) {
- if(isspace((unsigned char)*p))
- *p='\0';
- else
- break;
- }
- for(p=usalp->inq->prod_ident + 15 ; p >= usalp->inq->prod_ident; p--) {
- if(isspace((unsigned char)*p))
- *p='\0';
- else
- break;
- }
- snprintf(buf, sizeof(buf), "%d dev='%s' %s : '%.8s' '%.16s'\n", ndevs, devname, perms, usalp->inq->vendor_info, usalp->inq->prod_ident);
- lines[ndevs++]=strdup(buf);
- usal_close(usalp);
- }
- }
- fprintf(stdout, "%s: Overview of accessible drives (%d found) :\n"
- "----------------------------------------------------------------------\n",
- get_progname(), ndevs);
- for(i=0;i<ndevs;i++) {
- fprintf(stdout, "%s", lines[i]);
- free(lines[i]);
- }
- fprintf(stdout, "----------------------------------------------------------------------\n");
-
- return 0;
-
-#endif
-
-#ifdef __CYGWIN32__
- fprintf(stderr, "Beginning native device scan. This may take a while if devices are busy...\n");
- devname[1]='\0';
- for(i=2;i<26;i++) {
- devname[0]='A'+i;
- usalp = usal_open(devname, buf, sizeof (buf), 0, 0);
- if(!usalp) continue;
- if('\0' != usalp->device[0]) // must have been consumed by the pickup code!
- {
- usal_close(usalp);
+ if (!usal_havebus(usalp, bus))
continue;
- }
- usalp->silent++;
- //usalp->verbose=3;
- have_tgt = unit_ready(usalp) || usalp->scmd->error != SCG_FATAL;
- strcpy(perms,"------");
- if(statbuf.st_mode&S_IRUSR) perms[0]= 'r';
- if(statbuf.st_mode&S_IWUSR) perms[1]= 'w';
- if(statbuf.st_mode&S_IRGRP) perms[2]= 'r';
- if(statbuf.st_mode&S_IWGRP) perms[3]= 'w';
- if(statbuf.st_mode&S_IROTH) perms[4]= 'r';
- if(statbuf.st_mode&S_IWOTH) perms[5]= 'w';
+ initiator = usal_initiator_id(usalp);
+ //fprintf(f, "scsibus%d:\n", bus);
- if(have_tgt) {
- char *p;
+ for (tgt = 0; tgt < 16; tgt++) {
+ n = bus*100 + tgt;
- getdev(usalp, FALSE);
- for(p=usalp->inq->vendor_info + 7 ; p >= usalp->inq->vendor_info; p--) {
- if(isspace((unsigned char)*p))
- *p='\0';
- else
+ usal_settarget(usalp, bus, tgt, lun);
+ have_tgt = unit_ready(usalp) || usalp->scmd->error != SCG_FATAL;
+
+ if (!have_tgt && tgt > 7) {
+ if (usalp->scmd->ux_errno == EINVAL)
break;
+ continue;
}
- for(p=usalp->inq->prod_ident + 15 ; p >= usalp->inq->prod_ident; p--) {
- if(isspace((unsigned char)*p))
- *p='\0';
- else
- break;
+
+ fd=usal_fileno(usalp, bus, tgt, lun);
+ strcpy(perms,"------");
+ if(fd>=0 && 0==fstat(fd, &statbuf)) {
+ if(statbuf.st_mode&S_IRUSR) perms[0]= 'r';
+ if(statbuf.st_mode&S_IWUSR) perms[1]= 'w';
+ if(statbuf.st_mode&S_IRGRP) perms[2]= 'r';
+ if(statbuf.st_mode&S_IWGRP) perms[3]= 'w';
+ if(statbuf.st_mode&S_IROTH) perms[4]= 'r';
+ if(statbuf.st_mode&S_IWOTH) perms[5]= 'w';
}
- snprintf(buf, sizeof(buf), "%d dev='%s' %s : '%.8s' '%.16s'\n", ndevs, devname, perms, usalp->inq->vendor_info, usalp->inq->prod_ident);
- lines[ndevs++]=strdup(buf);
- usal_close(usalp);
+ getdev(usalp, FALSE);
+ if(usalp->inq->type == INQ_ROMD || usalp->inq->type == INQ_WORM) {
+ char *p;
+ for(p=usalp->inq->vendor_info + 7 ; p >= usalp->inq->vendor_info; p--) {
+ if(isspace((unsigned char)*p))
+ *p='\0';
+ else
+ break;
+ }
+ for(p=usalp->inq->prod_ident + 15 ; p >= usalp->inq->prod_ident; p--) {
+ if(isspace((unsigned char)*p))
+ *p='\0';
+ else
+ break;
+ }
+ snprintf(buf, sizeof(buf), "%2d dev='%s'\t%s : '%.8s' '%.16s'\n", ndevs, usal_natname(usalp, bus, tgt, lun), perms, usalp->inq->vendor_info, usalp->inq->prod_ident);
+ lines[ndevs++]=strdup(buf);
+ }
+
}
}
+ usalp->silent--;
+
fprintf(stdout, "%s: Overview of accessible drives (%d found) :\n"
- "----------------------------------------------------------------------\n",
+ "-------------------------------------------------------------------------\n",
get_progname(), ndevs);
- for(i=0;i<ndevs;i++)
+ for(i=0;i<ndevs;i++) {
fprintf(stdout, "%s", lines[i]);
- fprintf(stdout, "----------------------------------------------------------------------\n");
+ free(lines[i]);
+ }
+ fprintf(stdout, "-------------------------------------------------------------------------\n");
- return 0;
-#endif
+ n = -1;
+#ifdef FMT
+ getint("Select target", &n, low, high);
+ bus = n/100;
+ tgt = n%100;
+ usal_settarget(usalp, bus, tgt, lun);
+ return (select_unit(usalp));
- fprintf(stderr, "Native device scanning is not supported on this plattform. Please use -scanbus.\n");
- return 0;
+ usal_settarget(usalp, cscsibus, ctarget, clun);
+#endif
+ return (amt);
}
int select_target(SCSI *usalp, FILE *f) {
@@ -222,7 +196,7 @@
usalp->silent++;
- for (bus = 0; bus < 256; bus++) {
+ for (bus = 0; bus < 1256; bus++) {
usal_settarget(usalp, bus, 0, 0);
if (!usal_havebus(usalp, bus))
Modified: cdrkit/trunk/wodim/wodim.c
===================================================================
--- cdrkit/trunk/wodim/wodim.c 2007-04-09 14:23:17 UTC (rev 733)
+++ cdrkit/trunk/wodim/wodim.c 2007-04-10 15:01:46 UTC (rev 734)
@@ -402,9 +402,10 @@
exit(0);
}
+ /*
if (scandevs)
return (scan_devices(usalp, stdout, stderr));
-
+*/
usalp = usal_open(dev, errstr, sizeof (errstr),
debug, lverbose);
if(!usalp)
@@ -510,6 +511,9 @@
if ((buf = usal_getbuf(usalp, bufsize)) == NULL)
comerr("Cannot get SCSI I/O buffer.\n");
+ if (scandevs)
+ return (list_devices(usalp, stdout));
+
if ((flags & F_SCANBUS) != 0) {
select_target(usalp, stdout);
exit(0);
@@ -527,9 +531,9 @@
/*
* First try to check which type of SCSI device we
* have.
- */
if (debug || lverbose)
printf("atapi: %d\n", usal_isatapi(usalp));
+ */
usalp->silent++;
test_unit_ready(usalp); /* eat up unit attention */
usalp->silent--;
More information about the Debburn-changes
mailing list