Index: VERSION =================================================================== RCS file: /home/cvsroot/scsidev/VERSION,v retrieving revision 1.8.2.15 retrieving revision 1.8.2.16 diff -u -p -r1.8.2.15 -r1.8.2.16 --- VERSION 14 May 2005 21:35:27 -0000 1.8.2.15 +++ VERSION 18 Jul 2007 22:50:37 -0000 1.8.2.16 @@ -1 +1 @@ -2.36 +2.37 Index: scsidev.c =================================================================== RCS file: /home/cvsroot/scsidev/scsidev.c,v retrieving revision 1.28.2.64 retrieving revision 1.28.2.69 diff -u -p -r1.28.2.64 -r1.28.2.69 --- scsidev.c 17 Aug 2005 22:55:12 -0000 1.28.2.64 +++ scsidev.c 18 Jul 2007 23:01:16 -0000 1.28.2.69 @@ -192,6 +192,11 @@ * * * 2005-05-14: Kurt Garloff * - For 2.4, search for more devices when finding matching sd dev. + * + * * 2005-07-15: Nathanael Burton + * - When creating the non-rewinding tape device, the symlink + * mode failed due to a missing oldscsiname(spnt1). + * * * 2005-08-16: Kurt Garloff * - The 2.6 kernel now reports the 'RAID' type. * - Cleanup sysfs parsing. @@ -199,11 +204,15 @@ * - SG_IO support. * - Improve ID parsing (page 0x83), support EUI64 and NAA (mostly) * -> 2.36 + * + * * 2007-07-19: Kurt Garloff + * - Support the new sysfs names for 2.6.18+ + * -> 2.37 * * TODO: * Change wwid to string type to handle T10 ... * handle more identifiers to match devices - * + * */ #include @@ -224,8 +233,8 @@ #include #include -static char rcsid[] ="$Id: scsidev.c,v 1.28.2.64 2005/08/17 22:55:12 garloff Exp $"; -static char *versid = "scsidev " VERSION " 2005-08-16"; +static char rcsid[] ="$Id: scsidev.c,v 1.28.2.69 2007/07/18 23:01:16 garloff Exp $"; +static char *versid = "scsidev " VERSION " 2007-07-19"; static char *copyright = "Copyright: GNU GPL (see file COPYING)\n" \ " (w) 1994--1997 Eric Youngdale \n"\ " 2000--2005 Kurt Garloff "; @@ -1033,6 +1042,7 @@ int getidlun (int fd, sname *spnt, int s int status; int id[2]; + id[0] = 0; id[1] = 0; status = ioctl (fd, SCSI_IOCTL_GET_IDLUN, &id); if (status == -1) { @@ -1075,7 +1085,7 @@ int getscsihostname (int fd, sname *spnt spnt->major, spnt->minor, status, errno); spnt->hostname = 0; return -1; - }; + } spnt->hostname = hostname? strdup (hostname): 0; rmv_trail_ws (spnt->hostname); return status; @@ -1084,19 +1094,19 @@ int getscsihostname (int fd, sname *spnt /** Do hostname, idlun lookup, do inquiry and make name */ int getscsiinfo (int fd, sname *spnt, int setidlun) { - int status; - - if ((status = getidlun (fd, spnt, setidlun))) + int status; + + if ((status = getidlun (fd, spnt, setidlun))) + return status; + if ((status = getscsihostname (fd, spnt)) < 0) + return status; + + status = inquiry (fd, spnt); + get_hsv_os_id (fd, spnt); + scsiname (spnt); + if (setidlun) + oldscsiname (spnt); return status; - if ((status = getscsihostname (fd, spnt)) < 0) - return status; - - status = inquiry (fd, spnt); - get_hsv_os_id(fd,spnt); - scsiname (spnt); - if (setidlun) - oldscsiname (spnt); - return status; } @@ -1286,7 +1296,7 @@ int build_tape (sname * spnt, int no) /* And create the no-rewind alias */ spnt1 = sname_dup (spnt1); spnt1->minor |= 0x80; - scsiname (spnt1); + scsiname (spnt1); oldscsiname (spnt1); spnt1->next = reglist; reglist = spnt1; create_dev (spnt1, use_symlink); @@ -2011,6 +2021,24 @@ void sysfs_get_generic_nm (char* nm, str strcpy (sysfsdevptr->nm, ptr+1); } +FILE* sysfs_fopen_pattern(const char* basenm, const char* pat, char* nm) +{ + DIR *dir = opendir(basenm); + struct dirent *dent; + const ssize_t ln = strlen(pat); + if (!dir) + return NULL; + while (dent = readdir(dir)) { + if (0 == memcmp(pat, dent->d_name, ln)) { + strcpy(nm, basenm); + strcat(nm, dent->d_name); + strcat(nm, "/dev"); + return fopen(nm, "r"); + } + } + return NULL; +} + int sysfs_read_devinfo(char* basenm, struct sysfsdev* sysfsptr, sname * spnt, char* suffix, char blk) { @@ -2018,9 +2046,13 @@ int sysfs_read_devinfo(char* basenm, str char nm[128]; strcpy(nm, basenm); strcat(nm, suffix); + strcat(nm, "/dev"); f = fopen(nm, "r"); - if (!f) - return 0; + if (!f) { + f = sysfs_fopen_pattern(basenm, suffix, nm); + if (!f) + return 0; + } sysfsptr->blk = blk; fscanf(f, "%i:%i", &sysfsptr->maj, &sysfsptr->min); sysfs_get_dev_nm(nm, sysfsptr); @@ -2046,9 +2078,9 @@ int sysfs_getinfo (sname * spnt) spnt->hostnum, spnt->chan, spnt->id, spnt->lun); strcat (nm, "/device/"); /* sysfs devs */ - dev += sysfs_read_devinfo(nm, sysfsdevs+dev, spnt, "block/dev", 1); - dev += sysfs_read_devinfo(nm, sysfsdevs+dev, spnt, "tape/dev", 0); - dev += sysfs_read_devinfo(nm, sysfsdevs+dev, spnt, "generic/dev", 0); + dev += sysfs_read_devinfo(nm, sysfsdevs+dev, spnt, "block", 1); + dev += sysfs_read_devinfo(nm, sysfsdevs+dev, spnt, "tape", 0); + dev += sysfs_read_devinfo(nm, sysfsdevs+dev, spnt, "generic", 0); strcat (nm, "type"); f = fopen (nm, "r");