]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
[PATCH] update udev to include scsi_id 0.6
authorpatmans@us.ibm.com <patmans@us.ibm.com>
Wed, 6 Oct 2004 04:30:54 +0000 (21:30 -0700)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 04:37:02 +0000 (21:37 -0700)
Here's a patch updating udev's copy of scsi_id to version 0.6.

extras/scsi_id/ChangeLog
extras/scsi_id/Makefile
extras/scsi_id/TODO
extras/scsi_id/release-notes
extras/scsi_id/scsi.h
extras/scsi_id/scsi_id.8
extras/scsi_id/scsi_id.c
extras/scsi_id/scsi_id.h
extras/scsi_id/scsi_serial.c

index bfa353431b7a17101dc2637c3b19fb2f954e4d76..724977dbf49169a170e56e9c581459cd0a7c30b5 100644 (file)
@@ -1,3 +1,26 @@
+2004-jul-30:
+       * scsi_id.c, scsi_serial.c: Align the buffer passed to scsi_serial,
+         don't bother aligning and memcpy-ing the result in scsi_inquiry.
+         Aligning to 512 probably does not help, since the IO length of
+         254 is not a multiple of 512.
+
+2004-jul-30:
+       * scsi.h, scsi_serial.c: Use a define for the SCSI INQUIRY buffer
+         length.
+
+2004-jul-30:
+       * scsi_id.c: Patch from <christophe.varoqui@free.fr> add a -u flag
+        to substitute white space with underscores so it is easier to use
+        the output as a device name.
+
+2004-jul-30:
+       * scsi_serial.c: Patch from Hannes Reinecke <hare@suse.de> use 254
+         bytes for SCSI INQUIRY commands.
+
+2004-jul-28:
+       * scsi_id.h, scsi_serial.c: get rid of dumb/dead code, and use a
+         512 byte aligned buffer.
+
 2004-jun-23:
        * scsi_id.h: increase MAX_SERIAL_LEN from 128 to 256, as some
          devices (maybe broken ones) are giving really long id's.
index 8fe29f3647daaee335fb14531ba3b359f49b32e4..7ccc4c51181f0471c388318093bdcc278a14e78c 100644 (file)
@@ -14,7 +14,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
-SCSI_ID_VERSION=0.5
+SCSI_ID_VERSION=0.6
 
 prefix =
 etcdir =        ${prefix}/etc
index e0283cf444af5adbc5407d55f38455a3491f5332..857c22b87a1c13a3d70ad5e4b5457cc50bc42bbb 100644 (file)
@@ -1,6 +1,3 @@
-- Add an option to replace blanks with spaces, so the generated id can be
-  more easily used as a /dev name.
-
 - Add a bus white/black list option. So for example, all scsi devices
   under USB could easily be blacklisted. This should allow multiple busses
   to be listed.
index 29967131174b67d2066019927566fda92f46c0b1..302817ea7f0e0fa478f0daa93beef00d672bb09c 100644 (file)
@@ -1,6 +1,6 @@
-Version 0.5 of scsi_id is available at:
+Version 0.6 of scsi_id is available at:
 
-http://www-124.ibm.com/storageio/scsi_id/scsi_id-0.5.tar.gz
+http://www-124.ibm.com/storageio/scsi_id/scsi_id-0.6.tar.gz
 
 scsi_id is a program to generate a unique identifier for a given SCSI
 device.
@@ -9,34 +9,18 @@ It is primarily for use with the udev program key, or hotplug scripts that
 want persistent naming of scsi devices. It could also be used for
 automatic multi-path configuration or device mapper configuration.
 
-Version 0.5 requires:
+Requires:
 
 - Linux kernel 2.6
 - libsysfs 0.4.0
 
 Major changes since the last release:
+       
+       - add -u option, patch from Christoph Varoqui, to substitute white
+         space with underscores so it is easier to use the output as a
+         device name.
 
-       - Ken Brush <ken@cgi101.com> have the command line options
-         override generic options.
+       - Use 254 bytes for SCSI INQUIRY commands, patch from Hannes
+         Reinecke.
 
-       - Fix the gen_scsi_id_udev_rules.sh to handle spaces in the id.
-
-       - Don't supply a makedev() when built with klibc. Also, the
-         scsi_id supplied makedev() was using the old major/minor method.
-
-       - Include compiler.h so we can build against klibc, as recent sg.h
-         changes need a define for __user.
-
-Other changes:
-
-       - Increase the MAX_SERIAL_LEN from 128 to 256, as some (possibly
-         broken devics) are returning very long id's
-
-       - Add spotless target (via Olaf Hering's udev patch)
-
-       - minor wording changes in scsi_id.config
-
-       - Log INQUIRY failure, including the failing page code and vpd
-         values
-
-       - Escape '-' with '\-' in the man page.
+See ChangeLog for more details.
index 780e001576d21668cb4077662b84e7245a2a9d08..212765a17d367c6708e321ea0cbf5933ba68588e 100644 (file)
@@ -37,6 +37,13 @@ struct scsi_ioctl_command {
 
 #define SENSE_BUFF_LEN 32
 
+/*
+ * The request buffer size passed to the SCSI INQUIRY commands, use 254,
+ * as this is a nice value for some devices, especially some of the usb
+ * mass storage devices.
+ */
+#define        SCSI_INQ_BUFF_LEN       254
+
 /*
  * SCSI INQUIRY vendor and model (really product) lengths.
  */
index 69dd2a998ada9ca4ab58df578c6a6be8c5ee984e..591bb79366a03bad8769fcdf45b84800cf66175a 100644 (file)
@@ -95,6 +95,9 @@ Generate an id for the
 The sysfs mount point must not be included. For example, use /block/sd,
 not /sys/block/sd.
 .TP
+.BI \-u
+Reformat the output : replace all whitespaces by underscores
+.TP
 .BI \-v
 Generate verbose debugging output.
 .TP
index e893987868cf2f7a7ddb5674b0d6dda975c764d5..6395b822ced7925ff0118d0c89feb728796d7ee0 100644 (file)
@@ -52,7 +52,7 @@
  * options are not supported, but other code is still left in place for
  * now.
  */
-static const char short_options[] = "bd:f:gip:s:vV";
+static const char short_options[] = "bd:f:gip:s:uvV";
 /*
  * Just duplicate per dev options.
  */
@@ -70,6 +70,7 @@ static int default_page_code;
 static int use_stderr;
 static int debug;
 static int hotplug_mode;
+static int reformat_serial;
 
 void log_message (int level, const char *format, ...)
 {
@@ -469,6 +470,10 @@ static int set_options(int argc, char **argv, const char *short_opts,
                        strncat(target, optarg, MAX_NAME_LEN);
                        break;
 
+               case 'u':
+                       reformat_serial = 1;
+                       break;
+
                case 'v':
                        debug++;
                        break;
@@ -572,6 +577,23 @@ static int per_dev_options(struct sysfs_device *scsi_dev, int *good_bad,
        return retval;
 }
 
+/*
+ * format_serial: replace to whitespaces by underscores for calling
+ * programs that use the serial for device naming (multipath, Suse
+ * naming, etc...)
+ */
+static void format_serial(char *serial)
+{
+       char *p = serial;
+
+       while (*p != '\0') {
+               if (isspace(*p))
+                       *p = '_';
+               p++;
+       }
+       return;
+}
+
 /*
  * scsi_id: try to get an id, if one is found, printf it to stdout.
  * returns a value passed to exit() - 0 if printed an id, else 1. This
@@ -583,7 +605,7 @@ static int scsi_id(const char *target_path, char *maj_min_dev)
 {
        int retval;
        int dev_type = 0;
-       char serial[MAX_SERIAL_LEN];
+       char *serial, *unaligned_buf;
        struct sysfs_class_device *class_dev; /* of target_path */
        struct sysfs_class_device *class_dev_parent; /* for partitions */
        struct sysfs_device *scsi_dev; /* the scsi_device */
@@ -689,6 +711,12 @@ static int scsi_id(const char *target_path, char *maj_min_dev)
        dprintf("per dev options: good %d; page code 0x%x; callout '%s'\n",
                good_dev, page_code, callout);
 
+#define ALIGN   512
+       unaligned_buf = malloc(MAX_SERIAL_LEN + ALIGN);
+       serial = (char*) (((int) unaligned_buf + (ALIGN - 1)) & ~(ALIGN - 1));
+       dprintf("buffer unaligned 0x%p; aligned 0x%p\n", unaligned_buf, serial);
+#undef ALIGN
+
        if (!good_dev) {
                retval = 1;
        } else if (callout[0] != '\0') {
@@ -703,6 +731,8 @@ static int scsi_id(const char *target_path, char *maj_min_dev)
                retval = 0;
        }
        if (!retval) {
+               if (reformat_serial)
+                       format_serial(serial);
                if (display_bus_id)
                        printf("%s: ", scsi_dev->name);
                printf("%s", serial);
index 10599ebb5f8b75258feb5b04a85178fb33cf3f71..0ca7cd420696b1dd6cbcef23bd26e01869d660e6 100644 (file)
@@ -25,7 +25,6 @@
        log_message(LOG_DEBUG, "%s: " format, __FUNCTION__ , ## arg)
 
 #define        MAX_NAME_LEN    72
-#define OFFSET (2 * sizeof(unsigned int))
 
 /*
  * MAX_ATTR_LEN: maximum length of the result of reading a sysfs
index e0074b662d3a9692b1c17f253c753eebfbc825b8..0db756404c721c25499495297190570ed563009e 100644 (file)
@@ -300,17 +300,12 @@ static int scsi_inquiry(struct sysfs_device *scsi_dev, int fd, unsigned
        unsigned char sense[SENSE_BUFF_LEN];
        struct sg_io_hdr io_hdr;
        int retval;
-       unsigned char *inq;
-       unsigned char *buffer;
        int retry = 3; /* rather random */
 
-       if (buflen > 255) {
+       if (buflen > SCSI_INQ_BUFF_LEN) {
                log_message(LOG_WARNING, "buflen %d too long\n", buflen);
                return -1;
        }
-       inq = malloc(OFFSET + sizeof (inq_cmd) + 512);
-       memset(inq, 0, OFFSET + sizeof (inq_cmd) + 512);
-       buffer = inq + OFFSET;
 
 resend:
        dprintf("%s evpd %d, page 0x%x\n", scsi_dev->name, evpd, page);
@@ -321,7 +316,7 @@ resend:
        io_hdr.mx_sb_len = sizeof(sense);
        io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
        io_hdr.dxfer_len = buflen;
-       io_hdr.dxferp = buffer;
+       io_hdr.dxferp = buf;
        io_hdr.cmdp = inq_cmd;
        io_hdr.sbp = sense;
        io_hdr.timeout = DEF_TIMEOUT;
@@ -329,7 +324,8 @@ resend:
        if (ioctl(fd, SG_IO, &io_hdr) < 0) {
                log_message(LOG_WARNING, "%s: ioctl failed: %s\n",
                            scsi_dev->name, strerror(errno));
-               return -1;
+               retval = -1;
+               goto error;
        }
 
        retval = sg_err_category3(&io_hdr);
@@ -346,7 +342,6 @@ resend:
 
        if (!retval) {
                retval = buflen;
-               memcpy(buf, buffer, retval);
        } else if (retval > 0) {
                if (--retry > 0) {
                        dprintf("%s: Retrying ...\n", scsi_dev->name);
@@ -355,15 +350,16 @@ resend:
                retval = -1;
        }
 
+error:
        if (retval < 0)
                log_message(LOG_WARNING,
                            "%s: Unable to get INQUIRY vpd %d page 0x%x.\n",
                            scsi_dev->name, evpd, page);
 
-       free(inq);
        return retval;
 }
 
+/* Get list of supported EVPD pages */
 static int do_scsi_page0_inquiry(struct sysfs_device *scsi_dev, int fd,
                                 char *buffer, int len)
 {
@@ -552,15 +548,17 @@ static int check_fill_0x83_id(struct sysfs_device *scsi_dev, char
        return 0;
 }
 
+/* Get device identification VPD page */
 static int do_scsi_page83_inquiry(struct sysfs_device *scsi_dev, int fd,
                                  char *serial, int len)
 {
        int retval;
        int id_ind, j;
-       unsigned char page_83[256];
+       unsigned char page_83[SCSI_INQ_BUFF_LEN];
 
-       memset(page_83, 0, 256);
-       retval = scsi_inquiry(scsi_dev, fd, 1, 0x83, page_83, 255);
+       memset(page_83, 0, SCSI_INQ_BUFF_LEN);
+       retval = scsi_inquiry(scsi_dev, fd, 1, 0x83, page_83,
+                             SCSI_INQ_BUFF_LEN);
        if (retval < 0)
                return 1;
 
@@ -609,6 +607,7 @@ static int do_scsi_page83_inquiry(struct sysfs_device *scsi_dev, int fd,
        return 1;
 }
 
+/* Get unit serial number VPD page */
 static int do_scsi_page80_inquiry(struct sysfs_device *scsi_dev, int fd,
                                  char *serial, int max_len)
 {
@@ -616,10 +615,10 @@ static int do_scsi_page80_inquiry(struct sysfs_device *scsi_dev, int fd,
        int ser_ind;
        int i;
        int len;
-       unsigned char buf[256];
+       unsigned char buf[SCSI_INQ_BUFF_LEN];
 
-       memset(buf, 0, 256);
-       retval = scsi_inquiry(scsi_dev, fd, 1, 0x80, buf, 255);
+       memset(buf, 0, SCSI_INQ_BUFF_LEN);
+       retval = scsi_inquiry(scsi_dev, fd, 1, 0x80, buf, SCSI_INQ_BUFF_LEN);
        if (retval < 0)
                return retval;
 
@@ -652,13 +651,11 @@ static int do_scsi_page80_inquiry(struct sysfs_device *scsi_dev, int fd,
 int scsi_get_serial (struct sysfs_device *scsi_dev, const char *devname,
                     int page_code, char *serial, int len)
 {
-       unsigned char page0[256];
+       unsigned char page0[SCSI_INQ_BUFF_LEN];
        int fd;
        int ind;
        int retval;
 
-       if (len > 255) {
-       }
        memset(serial, 0, len);
        dprintf("opening %s\n", devname);
        fd = open(devname, O_RDONLY | O_NONBLOCK);
@@ -694,7 +691,7 @@ int scsi_get_serial (struct sysfs_device *scsi_dev, const char *devname,
         * Get page 0, the page of the pages. By default, try from best to
         * worst of supported pages: 0x83 then 0x80.
         */
-       if (do_scsi_page0_inquiry(scsi_dev, fd, page0, 255)) {
+       if (do_scsi_page0_inquiry(scsi_dev, fd, page0, SCSI_INQ_BUFF_LEN)) {
                /*
                 * Don't try anything else. Black list if a specific page
                 * should be used for this vendor+model, or maybe have an