Index: VERSION =================================================================== RCS file: /home/cvsroot/scsidev/VERSION,v retrieving revision 1.8.2.11 retrieving revision 1.8.2.12 diff -u -p -r1.8.2.11 -r1.8.2.12 --- VERSION 9 Feb 2004 23:59:18 -0000 1.8.2.11 +++ VERSION 10 Feb 2004 20:10:23 -0000 1.8.2.12 @@ -1 +1 @@ -2.32 +2.33 Index: boot.scsidev =================================================================== RCS file: /home/cvsroot/scsidev/Attic/boot.scsidev,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.5 diff -u -p -r1.1.2.2 -r1.1.2.5 --- boot.scsidev 4 Oct 2002 12:19:42 -0000 1.1.2.2 +++ boot.scsidev 27 Feb 2004 20:03:36 -0000 1.1.2.5 @@ -8,7 +8,6 @@ ### BEGIN INIT INFO # Provides: boot.scsidev # Required-Start: boot.proc -# X-UnitedLinux-Should-Start: boot.idedma # Required-Stop: # Default-Start: B # Default-Stop: @@ -29,17 +28,23 @@ test "$SCSIDEV_ARGS" = "disable" && exit rc_reset case "$1" in start|try-restart|restart|force-reload|reload) + unset RW + if test -r /proc/mounts; then + RW=`sed '/^rootfs/d;s/^[^ ]\+ \/ [^ ]\+ \([^ ]\+\).*$/\1/p;d' 2.32 * + * * 2004-02-10: Kurt Garloff : + * - Hannes Reineke found a bug that could result in creating devices + * with the wrong type (block vs. char). + * - Another patch from Hannes adding support for ASCII T10 data in + * page EVPD INQUIRY page 0x83. + * - dumppage() was using the wrong field to determine the length. + * - check association in page 0x83 to be for the device (Pat Mansfield) + * + * * 2004-02-16: Kurt Garloff : + * - Fix quiet option (Ulli Horlacher + /me) + * - Allow alternative location of scsi.alias file (-A, Ulli Horlacher) + * - Fix ASCII T10 data retrieval from EVPD INQ 0x83. + * - Fix assumption about minor being only 8bit. + * - Increase max length of hostname from 64 to 160. (Wolfgang Celeda) + * -> 2.33 + * * TODO: other char devices - * other WWID / serial formats * */ @@ -183,7 +198,7 @@ #include #include -static char rcsid[] ="$Id: scsidev.c,v 1.28.2.36 2004/02/10 00:00:06 garloff Exp $"; +static char rcsid[] ="$Id: scsidev.c,v 1.28.2.45 2004/02/26 17:00:16 garloff Exp $"; static char *versid = "scsidev " VERSION " 2004-02-09"; static char *copyright = "Copyright: GNU GPL (see file COPYING)\n" \ " (w) 1994--1997 Eric Youngdale \n"\ @@ -221,7 +236,8 @@ int nm_cbtu = 0; int supp_rmvbl = 0; int supp_multi = 0; int override_link_perm = 1; -char * no_serial = "No serial number"; +char *no_serial = "No serial number"; +char *scsialias = ""; unsigned long long no_wwid = 0; int no_hsv_os_id = -1; @@ -232,7 +248,7 @@ int no_hsv_os_id = -1; enum devtype_t { NONE=0, SG, SD, SR, ST, OSST, SCH, }; char* devtp_nm[] = { "", "Generic", "Disk", "Rom", "Tape", "OnStreamTape", "Changer", }; -char* devtp_nm26[] = { "", "sg", "sd", "sr", "st", "osst", "sch", }; +char* devtp_nm26[] = { "", "sg", "sd.", "sr", "st", "osst", "sch", }; /* * This program builds entries in /dev/scsi that have names that are tied @@ -264,7 +280,7 @@ typedef struct regnames char inq_devtp; char rmvbl; char unsafe; - char partition; + signed char partition; int hostid; int major; int minor; @@ -343,9 +359,16 @@ inline char isblk (enum devtype_t devtp) enum devtype_t nm26_to_devtp (char* nm) { enum devtype_t i; - for (i = NONE; i <= SCH; ++i) - if (!strcmp (devtp_nm26[i], nm)) - return i; + for (i = NONE; i <= SCH; ++i) { + const char* dtp = devtp_nm26[i]; + int ln; + if (!strcmp (dtp, nm)) + return i; + ln = strlen(dtp); + if (dtp[ln-1] == '.' && + !memcmp(dtp, nm, ln-1)) + return i; + } return 0; } @@ -363,7 +386,7 @@ void dumpentry (sname * pnt) pnt->hostnum, pnt->hostid, pnt->hostname, pnt->chan, pnt->id, pnt->lun); if (pnt->devtp == SD && pnt->partition != -1) printf ("p%d", pnt->partition); - printf (" %c %x-%x ", (isblk(pnt->devtp)? 'b': 'c'), + printf (" %c %03x:%05x ", (isblk(pnt->devtp)? 'b': 'c'), pnt->major, pnt->minor); printf (" SCSI %s\n", devtp_nm[(int)pnt->devtp]); } @@ -502,7 +525,7 @@ char * scsiname (sname *spnt) dnm = "sch"; break; default: - fprintf (stderr, "scsidev: PANIC: Illegal major 0x%02x!\n", + fprintf (stderr, "scsidev: PANIC: Illegal major 0x%03x!\n", spnt->major); abort (); } @@ -620,7 +643,7 @@ void oldscsiname (sname *spnt) sprintf (genpart+strlen(genpart), "%d", (spnt->minor & 0x0f)); break; default: - fprintf (stderr, "scsidev: PANIC: Illegal device type major 0x%02x!\n", + fprintf (stderr, "scsidev: PANIC: Illegal device type major 0x%03x!\n", spnt->major); abort (); } @@ -795,8 +818,9 @@ void create_symlink (const char *linkto, int status; int recreate = 0; - printf ("create_symlink(%s, %s, %o, %x, %x)\n", - linkto, nm, fmode, major, minor); + if (!quiet) + printf ("create_symlink(%s, %s, %o, %03x, %05x)\n", + linkto, nm, fmode, major, minor); get_perm (nm, linkto, &statbuf2, (major == SCSI_CDROM_MAJOR)); status = lstat (nm, &statbuf); @@ -833,7 +857,7 @@ void create_symlink (const char *linkto, apply_perm (linkto, &statbuf2, fmode); } else { if (statbuf.st_rdev != makedev (major, minor)) { - fprintf (stderr, "scsidev: Inconsistency %s == %02x:%02x != %02x:%02x\n", + fprintf (stderr, "scsidev: Inconsistency %s == %03x:%05x != %03x:%05x\n", linkto, major(statbuf.st_rdev), minor(statbuf.st_rdev), major, minor); abort (); @@ -980,7 +1004,7 @@ int getidlun (int fd, sname *spnt, int s if (status == -1) { if (verbose == 2) - fprintf (stderr, "idlun(%x/%x) returned %d (%d)\n", + fprintf (stderr, "idlun(%03x:%05x) returned %d (%d)\n", spnt->major, spnt->minor, status, errno); close (fd); return -2; @@ -996,7 +1020,7 @@ int getidlun (int fd, sname *spnt, int s spnt->hostid = id[1]; if (verbose == 2) - fprintf (stderr, "Found %x:%x with idlun %08x\n", + fprintf (stderr, "Found %03x:%05x with idlun %08x\n", spnt->major, spnt->minor, id[0]); return status; @@ -1007,19 +1031,19 @@ int getidlun (int fd, sname *spnt, int s int getscsihostname (int fd, sname *spnt) { int status; - char hostname[64]; - *(int*)hostname = 63; + char hostname[160]; + *(int*)hostname = 159; status = ioctl (fd, SCSI_IOCTL_PROBE_HOST, hostname); - hostname[63] = '\0'; + hostname[159] = '\0'; if (status == -1) { if (verbose == 2) - fprintf (stderr, "probe host (%x/%x) returned %d (%d)\n", + fprintf (stderr, "probe host (%03x:%05x) returned %d (%d)\n", spnt->major, spnt->minor, status, errno); spnt->hostname = 0; return -1; }; - spnt->hostname = strdup (hostname); + spnt->hostname = hostname? strdup (hostname): 0; rmv_trail_ws (spnt->hostname); return status; } @@ -1045,15 +1069,16 @@ int getscsiinfo (int fd, sname *spnt, in void findscsidisk(sname * spnt, int no) { - int status,major,minor,i,fd,res; - int scsi_id,channel,lun,host; + int status, major, minor, i, fd, res; + int scsi_id, channel, lun, host; int id[2]; - printf("Findscsidisk: %d\n",no); + if (verbose >= 1) + printf("Findscsidisk: %d\n",no); /* only search up to 16 devices may be a bad assumption, but scanning * the whole list could take a long time */ for (i = no; i < no+16; ++i) { major = disknum_to_sd_major (i); - minor = (i << 4) & 0xf0; + minor = (i << 4) & ~0x0f; unlink (TESTDEV); status = mknod (TESTDEV, 0600 | S_IFBLK, @@ -1087,7 +1112,7 @@ void findscsidisk(sname * spnt, int no) /* If we did not find a match, return a good guess.. */ unlink (TESTDEV); spnt->major = disknum_to_sd_major (no); - spnt->minor = (no << 4) & 0xf0; + spnt->minor = (no << 4) & ~0x0f; } @@ -1209,6 +1234,16 @@ int build_tape (sname * spnt, int no) return 0; } +/* Create non-rew. alternative for a tape */ +void create_ntape (sname * spnt) +{ + sname * spnt1 = sname_dup (spnt); + spnt1->minor |= 0x80; + scsiname (spnt1); oldscsiname (spnt1); + create_dev (spnt1, use_symlink); + spnt1->next = reglist; reglist = spnt1; +} + int build_os_tape (sname * spnt, int no) { int fd; int status; @@ -1349,6 +1384,55 @@ int build_changer (sname * spnt, int no) return 0; } +/* Use /proc/partitions to scan for partitions */ +void create_partitions (sname * spnt) +{ + char pline[128]; char *ptr; + FILE *pf = fopen ("/proc/partitions", "r"); + if (!pf) { + fprintf (stderr, "scsidev: Couldn't read /proc/partitions: %s\n", + strerror (errno)); + return; + } + while (!feof (pf)) { + unsigned int maj, min, blk; + char nm[8], nm2[8]; + ptr = fgets (pline, 128, pf); + if (!ptr) + break; + if (sscanf (pline, " %d %d %d %8s", &maj, &min, &blk, nm) < 4) + continue; + + /* Strip part */ + strcpy (nm2, nm); + if (isdigit (nm2[strlen(nm2)-1])) { + for (ptr = nm2+strlen(nm2)-1; isdigit(*ptr); --ptr); + *(++ptr) = 0; + } + ptr = nm + strlen(nm2); + if (!strcmp (nm2, spnt->oldname)) { + /* Found it ! */ + if (maj != spnt->major || (min & ~0x0f) != (spnt->minor)) { + fprintf (stderr, "scsidev: Inconsistency found: /proc/partitions reports " + " %s as %03x:%05x\n whereas we have %03x:%05x\n", + nm2, maj, min & ~0x0f, spnt->major, spnt->minor); + dumpentry (spnt); + abort (); + } + if (isdigit (*ptr)) { + int part = atoi (ptr); + sname * spnt1 = sname_dup (spnt); + spnt1->minor |= part; spnt1->partition = part; + scsiname (spnt1); + spnt1->oldname = strdup (nm); + create_dev (spnt1, use_symlink); + spnt1->next = reglist; reglist = spnt1; + } + } + } + fclose (pf); +} + void build_sgdevlist () @@ -1374,7 +1458,7 @@ void build_sgdevlist () unlink (TESTDEV); if (verbose >= 1) - fprintf (stderr, "Building list for sg (%s dev major %i)\n", + fprintf (stderr, "Building list for sg (%s dev major %03x)\n", "char", major); while (minor <= 255) { @@ -1389,7 +1473,7 @@ void build_sgdevlist () unlink (TESTDEV); if (fd == -1) { if (verbose == 2) - fprintf (stderr, "open(%x/%x) returned %d (%d)\n", + fprintf (stderr, "open(%03x:%05x) returned %d (%d)\n", major, minor, fd, errno); miss++; if (miss > maxmiss) @@ -1414,7 +1498,7 @@ void build_sgdevlist () minor++; continue; } } - //scsiname (spnt); + //scsiname (spnt) called by getscsiinfo(); spnt->next = reglist; reglist = spnt; create_dev (spnt, use_symlink); @@ -1483,9 +1567,7 @@ int procscsi_readrecord (FILE* f) ptr = fgets (fourlnbuf[2], 128, f); /* Test for extensions ... */ c = fgetc (f); - if (c == EOF) - return 0; - else { + if (c != EOF) { ungetc (c, f); if (c != 'H') { ptr = fgets (fourlnbuf[3], 128, f); @@ -1494,9 +1576,12 @@ int procscsi_readrecord (FILE* f) ungetc (c, f); } } - //printf ("%s", fourlnbuf[0]); printf ("%s", fourlnbuf[1]); - //printf ("%s", fourlnbuf[2]); printf ("%s", fourlnbuf[3]); - //printf ("%i\n", fourlnbuf[3][0]); +#ifdef DEBUG + printf ("procscsi_readrecord:\n"); + printf ("%s", fourlnbuf[0]); printf ("%s", fourlnbuf[1]); + printf ("%s", fourlnbuf[2]); printf ("%s", fourlnbuf[3]); + printf ("%i\n", fourlnbuf[3][0]); +#endif return 0; } @@ -1575,15 +1660,15 @@ int procscsiext_parse (sname *spnt, int char tp; int n = sscanf (fourlnbuf[3], " Attached drivers: %16s %16s %16s %16s", hldev[0], hldev[1], hldev[2], hldev[3]); - if (idx >= n) - return -1; - else + if (idx >= n) { + return -1; + } else hdev = hldev[idx]; for (devptr = hdev; *devptr != '(' && *devptr != 0; ++devptr); *devptr++ = 0; spnt->oldname = strdup (hdev); - + sscanf (devptr, "%c:%x:%x)", &tp, &spnt->major, &spnt->minor); // We don't use tp (which can be 'b' or 'c') @@ -1592,7 +1677,8 @@ int procscsiext_parse (sname *spnt, int spnt->devtp = SG; else spnt->devtp = inq_devtp_to_devtp (spnt->inq_devtp, spnt); - + + scsiname (spnt); return 0; } @@ -1722,7 +1808,9 @@ void fill_in_proc (sname * spnt) if (!spnt->hostid) spnt->hostid = find_ioport (spnt->shorthostname); - fd = mknod (TESTDEV, 0600 | (isblk(spnt->inq_devtp)? S_IFBLK: S_IFCHR), + spnt->devtp = inq_devtp_to_devtp (spnt->inq_devtp, spnt); + + fd = mknod (TESTDEV, 0600 | (isblk(spnt->devtp)? S_IFBLK: S_IFCHR), makedev (spnt->major, spnt->minor)); if (fd) { fprintf (stderr, "scsidev: Can't mknod " TESTDEV ": %s\n", @@ -1730,17 +1818,22 @@ void fill_in_proc (sname * spnt) return; } fd = open (TESTDEV, O_RDWR | O_NONBLOCK); + if (fd == -1) { + perror("open"); + return; + } unlink (TESTDEV); inquiry (fd, spnt); get_hsv_os_id(fd, spnt); close (fd); - scsiname (spnt); + //scsiname (spnt); } void fill_in_sg (sname * spnt) { int status; int fd; + errno = 0; status = mknod (TESTDEV, 0600 | S_IFCHR, makedev (spnt->major, spnt->minor)); @@ -1758,65 +1851,6 @@ void fill_in_sg (sname * spnt) } -/* Create non-rew. alternative for a tape */ -void create_ntape (sname * spnt) -{ - sname * spnt1 = sname_dup (spnt); - spnt1->minor |= 0x80; - scsiname (spnt1); oldscsiname (spnt1); - create_dev (spnt1, use_symlink); - spnt1->next = reglist; reglist = spnt1; -} - -/* Use /proc/partitions to scan for partitions */ -void create_partitions (sname * spnt) -{ - char pline[128]; char *ptr; - FILE *pf = fopen ("/proc/partitions", "r"); - if (!pf) { - fprintf (stderr, "scsidev: Couldn't read /proc/partitions: %s\n", - strerror (errno)); - return; - } - while (!feof (pf)) { - unsigned int maj, min, blk; - char nm[8], nm2[8]; - ptr = fgets (pline, 128, pf); - if (!ptr) - break; - if (sscanf (pline, " %d %d %d %8s", &maj, &min, &blk, nm) < 4) - continue; - - /* Strip part */ - strcpy (nm2, nm); - if (isdigit (nm2[strlen(nm2)-1])) { - for (ptr = nm2+strlen(nm2)-1; isdigit(*ptr); --ptr); - *(++ptr) = 0; - } - ptr = nm + strlen(nm2); - if (!strcmp (nm2, spnt->oldname)) { - /* Found it ! */ - if (maj != spnt->major || (min & 0xf0) != (spnt->minor)) { - fprintf (stderr, "scsidev: Inconsistency found: /proc/partitions reports " - " %s as %02x:%02x\n whereas we have %02x:%02x\n", - nm2, maj, min & 0xf0, spnt->major, spnt->minor); - dumpentry (spnt); - abort (); - } - if (isdigit (*ptr)) { - int part = atoi (ptr); - sname * spnt1 = sname_dup (spnt); - spnt1->minor |= part; spnt1->partition = part; - scsiname (spnt1); - spnt1->oldname = strdup (nm); - create_dev (spnt1, use_symlink); - spnt1->next = reglist; reglist = spnt1; - } - } - } - fclose (pf); -} - /* Create device nodes etc. */ void dev_specific_setup (sname * spnt) @@ -1913,6 +1947,7 @@ int sysfs_getinfo (sname * spnt) { char nm[128]; char *nmptr; FILE* f; int dev = 0; + strcpy (nm, "/sys/class/scsi_device/"); sprintf (nm+strlen(nm), "%d:%d:%d:%d", spnt->hostnum, spnt->chan, spnt->id, spnt->lun); @@ -1958,6 +1993,7 @@ void sysfs_parse (sname *spnt, int idx) { char nm[7]; char *p1 = sysfsdevs[idx].nm, *p2 = nm; + while (!isdigit(*p1) && *p1) *p2++ = *p1++; *p2 = 0; @@ -1965,6 +2001,11 @@ void sysfs_parse (sname *spnt, int idx) spnt->major = sysfsdevs[idx].maj; spnt->minor = sysfsdevs[idx].min; spnt->devtp = nm26_to_devtp(nm); + if (verbose >= 1) { + dumpentry(spnt); + printf("Names %s, %s\n", spnt->oldname, nm); + } + scsiname(spnt); } @@ -2034,9 +2075,6 @@ void build_sgdevlist_procscsi () sysfs_parse (spnt, hl); if (spnt->devtp == SG) sgpnt = spnt; - if (verbose > 1) - printf(" %s(%02x:%02x) %i %p\n", spnt->oldname, - spnt->major, spnt->minor, spnt->devtp, sgpnt); } /* Fill in missing information (inquiry, host adapter name ...) */ if (sgpnt) @@ -2063,9 +2101,10 @@ void build_sgdevlist_procscsi () spnt->shorthostname = strdup (sgpnt->shorthostname); spnt->related = sgpnt; } +#if 1 /* This does the handling of the dev nodes */ - scsiname (spnt); dev_specific_setup (spnt); +#endif } } if (verbose >= 1) { @@ -2167,6 +2206,7 @@ void usage() fprintf (stderr, " -m mode: permissions to create dev nodes with\n"); fprintf (stderr, " -s : list Serial numbers /WWIDs /HSVs of devices (if available)\n"); fprintf (stderr, " -c mxms: Continue scanning until mxms missing devs found\n"); + fprintf (stderr, " -A file: alias file (default: /etc/scsi.alias)\n"); fprintf (stderr, " -r : trust Removeable media (only safe after boot)\n"); fprintf (stderr, " -e : use dEvfs like naming (cbtu chars)\n"); fprintf (stderr, " -o : for the Old names use scd instead of sr\n"); @@ -2177,7 +2217,7 @@ void usage() int main (int argc, char * argv[]) { - char c; + int c; int show_serial = 0; struct stat statbuf; sname * spnt; @@ -2191,7 +2231,7 @@ int main (int argc, char * argv[]) fprintf(stderr, DEVSCSI " either does not exist, or is not a directory\n"); exit(0); } - while ((c = getopt(argc, argv, "pflLvqshnderoMm:c:")) != EOF) { + while ((c = getopt(argc, argv, "pflLvqshnderoMm:c:A:")) != -1) { switch (c) { case 'p': no_procscsi = 1; break; @@ -2201,6 +2241,8 @@ int main (int argc, char * argv[]) filemode = strtoul (optarg, 0, 0); break; case 'c': maxmiss = strtoul (optarg, 0, 0); break; + case 'A': + scsialias = optarg; break; case 'l': use_symlink = 1; break; case 'L': @@ -2227,7 +2269,7 @@ int main (int argc, char * argv[]) case 'q': quiet = 1; break; default: - usage(); exit(1); break; + usage(); break; } } @@ -2249,9 +2291,11 @@ int main (int argc, char * argv[]) register_dev("/dev/scsi/rsth4-334c0i5l0", 9,128, ST, 6, 0x334, 0, 5, 0, -1, "debug", 0, NULL, NULL); #else if (no_procscsi || try_procscsi ()) { - if (find_sysfs () && !quiet) - fprintf (stderr, "/proc/scsi/scsi extensions not found. Fall back to scanning.\n"); - build_sgdevlist (); + if (find_sysfs ()) { + if (!quiet) + fprintf (stderr, "/proc/scsi/scsi extensions not found. Fall back to scanning.\n"); + build_sgdevlist (); + } } #endif @@ -2270,6 +2314,8 @@ int main (int argc, char * argv[]) printf("Device %s has no serial number\n", spnt->name); else printf("Serial number of %s: \"%s\"\n", spnt->name, spnt->serial); + if (!spnt->name) + dumpentry(spnt); if ( spnt->wwid != no_wwid ) printf (" WWID: %Lx\n", spnt->wwid); if ( spnt->hsv_os_id != no_hsv_os_id ) @@ -2463,13 +2509,14 @@ void build_special () unsigned long long wwid; /* host byte order ... */ enum devtype_t devtype_i; char *manufacturer, *model, *serial_number, *name, *devtype, *rev, *host; - char *scsialias; + if (!*scsialias) { #ifdef DEBUG - scsialias = "scsi.alias"; + scsialias = "scsi.alias"; #else - scsialias = "/etc/scsi.alias"; + scsialias = "/etc/scsi.alias"; #endif + } configfile = fopen (scsialias, "r"); if (!configfile) { @@ -2764,7 +2811,20 @@ void build_special () void dumppage (unsigned char* page) { - int ln = 4 + page[4]; + int ln = 4 + page[3]; + int i; + for (i = 0; i <= ln; i++) + { + printf (" %02x", page[i]); + if (!((i+1)%16)) printf ("\n"); + } + if (i%16) printf ("\n"); +} + + +void dumppage_83 (unsigned char* page) +{ + int ln = (page[2] << 8) + page[3]; int i; for (i = 0; i <= ln; i++) { @@ -2799,21 +2859,49 @@ char* getstr (char* page, int start, int unsigned long long extract_wwid (unsigned char* page) { unsigned int hi, lo; - if (page[1] != 0x83) - return no_wwid; + char vendor_id[9]; + char *device_id; + + if (page[1] != 0x83) { + printf("Page does not contain any WWID\n"); + return no_wwid; + } /* We only support binary data */ - if ((page[4] & 0x0f) != 1) + if ((page[4] & 0x0f) == 1) { + /* We support identifier types 2, 3 */ + if ((page[5] & 0x0f) != 3 && (page[5] & 0x0f) != 2) return no_wwid; - /* We support identifier types 2, 3 */ - if ((page[5] & 0x0f) != 3 && (page[5] & 0x0f) != 2) + /* Id length should be 8 (64 bits) */ + if (page[7] != 8) return no_wwid; - /* Id length should be 8 (64 bits) */ - if (page[7] != 8) + /* ASSOCIATION must be with the device (value 0) */ + if ((page[5] & 0x30) != 0) return no_wwid; - /* Now translate network byte order to host byte order */ - hi = ntohl (*(unsigned int*)(page+ 8)); - lo = ntohl (*(unsigned int*)(page+12)); - return ((unsigned long long) hi << 32) + (unsigned long long) lo; + /* Now translate network byte order to host byte order */ + hi = ntohl (*(unsigned int*)(page+ 8)); + lo = ntohl (*(unsigned int*)(page+12)); + return ((unsigned long long) hi << 32) + (unsigned long long) lo; + } else if ((page[4] & 0x0f) == 2) { + /* Get ASCII data */ + if ((page[5] & 0x0f) == 1) { + /* T-10 Identifier */ + memcpy(vendor_id, page+8, 8); + vendor_id[9] = '\0'; + if (verbose >= 1) + printf("Vendor: %s\n",vendor_id); + if (page[7] > 8) { + device_id = malloc(page[7]-7); + device_id[page[7]-8] = '\0'; + memcpy(device_id, page+16, page[7] - 8); + if (verbose >= 1) + printf("Device: %s\n", device_id); + free(device_id); + } + } + return no_wwid; + } else { + return no_wwid; + } } #define INQBUFSZ 512 @@ -2866,26 +2954,38 @@ int inquiry (int infile, sname * spnt) spnt->wwid = no_wwid; spnt->serial = no_serial; //infile = open(spnt->name, O_RDWR); - if (infile == -1) + if (infile == -1) { + fprintf(stderr,"No input file for inquiry!\n"); return -1; + } // Std. inquiry status = get_inq_page (infile, 0, buffer, 0, 0); if (status) { - fprintf (stderr, "INQUIRY failed for %s (%i-%i/%02x:%02x)!\n", + fprintf (stderr, "INQUIRY failed for %s (%i-%i/%03x:%05x)!\n", spnt->name, spnt->id, spnt->lun, spnt->major, spnt->minor); return -1; } - if (verbose == 2) - dumppage (pagestart); + if (verbose >= 2) { + printf("Calling dumppage\n"); + dumppage (pagestart); + } spnt->manufacturer = getstr (pagestart, 8, 15); spnt->model = getstr (pagestart, 16, 31); spnt->rev = getstr (pagestart, 32, 35); spnt->inq_devtp = pagestart[0] & 0x1f; + if (verbose >= 2) + printf("Device type: %X\n",spnt->inq_devtp); spnt->rmvbl = (pagestart[1] & 0x80) >> 7; + if (verbose >= 2) + printf("Device removable: %s\n",spnt->rmvbl?"yes":"no"); ansi = pagestart[2] & 7; - + if (verbose >= 2) + printf("ANSI SCSI version: %X\n", ansi); + if (verbose >= 2) + printf("Desc1: %X\n",pagestart[58]); + if (ansi >= 3) lun = 0; else @@ -2898,22 +2998,32 @@ int inquiry (int infile, sname * spnt) return 0; ln = pagestart[3]; for (off = 0; off < ln; ++off) { + if (verbose >= 2) + printf("Supported VPD page: %x\n", pagestart[4+off]); if (pagestart[4+off] == 0x80) - have_ser_page = 1; + have_ser_page = 1; if (pagestart[4+off] == 0x83) - have_wwid_page = 1; + have_wwid_page = 1; } if (have_ser_page && !get_inq_page (infile, lun, buffer, 0x80, 1)) { + if (verbose >= 2) { + printf("VPD Page 0x80\n"); + dumppage(pagestart); + } spnt->serial = getstr (pagestart, 4, 3+pagestart[3]); - if (verbose == 2) + if (verbose >= 2) printf ("Serial for %s: %s\n", spnt->name, spnt->serial); } if (have_wwid_page && !get_inq_page (infile, lun, buffer, 0x83, 1)) { + if (verbose >= 2) { + printf("VPD Page 0x83\n"); + dumppage_83(pagestart); + } spnt->wwid = extract_wwid (pagestart); - if (verbose == 2) + if (verbose >= 2) printf ("WWID for %s: %Lx\n", spnt->name, spnt->wwid); }