chiark / gitweb /
[PATCH] get_dev_number() in extras/ide-devfs.sh
[elogind.git] / extras / scsi_id / scsi_serial.c
index 302429c0d4b5459544ace8a3e8bd0311ad5ee435..80a1d5163516785f92ada6515b876234efa7f821 100644 (file)
 #include <unistd.h>
 #include <syslog.h>
 #include <scsi/sg.h>
-#include <sys/libsysfs.h>
+#ifdef __KLIBC__
+/*
+ * Assume built under udev with KLIBC
+ */
+#include <libsysfs.h>
+#else
+#include <sysfs/libsysfs.h>
+#endif
 #include "scsi_id.h"
 #include "scsi.h"
 
@@ -348,6 +355,11 @@ resend:
                        retval = scsi_dump(scsi_dev, &io_hdr);
        }
 
+       /*
+        * XXX where is the length checked? That is, was our request
+        * buffer long enough?
+        */
+
        if (!retval) {
                retval = buflen;
                memcpy(buf, buffer, retval);
@@ -369,11 +381,11 @@ resend:
  * Ending here.
  */
 
-int do_scsi_page0_inquiry(struct sysfs_class_device *scsi_dev, int fd,
-                         char *buffer, int len)
+static int do_scsi_page0_inquiry(struct sysfs_class_device *scsi_dev, int fd,
+                                char *buffer, int len)
 {
        int retval;
-       char *vendor;
+       char vendor[MAX_ATTR_LEN];
 
        memset(buffer, 0, len);
        retval = scsi_inquiry(scsi_dev, fd, 1, 0x0, buffer, len);
@@ -403,9 +415,10 @@ int do_scsi_page0_inquiry(struct sysfs_class_device *scsi_dev, int fd,
                 * If the vendor id appears in the page assume the page is
                 * invalid.
                 */
-               vendor = sysfs_get_attr(scsi_dev, "vendor");
-               if (!vendor) {
-                       log_message(LOG_WARNING, "%s: no vendor attribute\n",
+               if (sysfs_get_attr(scsi_dev->path, "vendor", vendor,
+                                  MAX_ATTR_LEN)) {
+                       log_message(LOG_WARNING,
+                                   "%s: cannot get model attribute\n",
                                    scsi_dev->name);
                        return 1;
                }
@@ -425,12 +438,11 @@ int do_scsi_page0_inquiry(struct sysfs_class_device *scsi_dev, int fd,
 static int prepend_vendor_model(struct sysfs_class_device *scsi_dev,
                                char *serial)
 {
-       char *attr;
+       char attr[MAX_ATTR_LEN];
        int ind;
 
-       attr = sysfs_get_attr(scsi_dev, "vendor");
-       if (!attr) {
-               log_message(LOG_WARNING, "%s: no vendor attribute\n",
+       if (sysfs_get_attr(scsi_dev->path, "vendor", attr, MAX_ATTR_LEN)) {
+               log_message(LOG_WARNING, "%s: cannot get vendor attribute\n",
                            scsi_dev->name);
                return 1;
        }
@@ -442,9 +454,8 @@ static int prepend_vendor_model(struct sysfs_class_device *scsi_dev,
        if (serial[ind] == '\n')
                serial[ind] = '\0';
 
-       attr = sysfs_get_attr(scsi_dev, "model");
-       if (!attr) {
-               log_message(LOG_WARNING, "%s: no model attribute\n",
+       if (sysfs_get_attr(scsi_dev->path, "model", attr, MAX_ATTR_LEN)) {
+               log_message(LOG_WARNING, "%s: cannot get model attribute\n",
                            scsi_dev->name);
                return 1;
        }
@@ -527,8 +538,10 @@ static int check_fill_0x83_id(struct sysfs_class_device *scsi_dev,
        serial[0] = hex_str[id_search->id_type];
 
        /*
-        * Prepend the vendor and model before the id since if it is not
-        * unique across all vendors and models.
+        * For SCSI_ID_VENDOR_SPECIFIC prepend the vendor and model before
+        * the id since it is not unique across all vendors and models,
+        * this differs from SCSI_ID_T10_VENDOR, where the vendor is
+        * included in the identifier.
         */
        if (id_search->id_type == SCSI_ID_VENDOR_SPECIFIC)
                if (prepend_vendor_model(scsi_dev, &serial[1]) < 0) {
@@ -575,6 +588,12 @@ static int do_scsi_page83_inquiry(struct sysfs_class_device *scsi_dev, int fd,
                            scsi_dev->name);
                return 1;
        }
+       
+       /*
+        * XXX Some devices (IBM 3542) return all spaces for an identifier if
+        * the LUN is not actually configured. This leads to identifers of
+        * the form: "1            ".
+        */
 
        /*
         * Search for a match in the prioritized id_search_list.
@@ -609,8 +628,8 @@ static int do_scsi_page83_inquiry(struct sysfs_class_device *scsi_dev, int fd,
        return 1;
 }
 
-int do_scsi_page80_inquiry(struct sysfs_class_device *scsi_dev, int fd,
-                          char *serial, int max_len)
+static int do_scsi_page80_inquiry(struct sysfs_class_device *scsi_dev, int fd,
+                                 char *serial, int max_len)
 {
        int retval;
        int ser_ind;