chiark / gitweb /
fix more compiler warnings ...
[elogind.git] / extras / scsi_id / scsi_serial.c
index 0db756404c721c25499495297190570ed563009e..73d66ee615659adf9576db0f181cfafa753fa546 100644 (file)
@@ -89,6 +89,7 @@ static const char hex_str[]="0123456789abcdef";
 #define SG_ERR_CAT_RESET       2      /* interpreted from sense buffer */
 #define SG_ERR_CAT_TIMEOUT     3
 #define SG_ERR_CAT_RECOVERED   4  /* Successful command after recovered err */
+#define SG_ERR_CAT_NOTSUPPORTED 5 /* Illegal / unsupported command */
 #define SG_ERR_CAT_SENSE       98     /* Something else in the sense buffer */
 #define SG_ERR_CAT_OTHER       99     /* Some other error/warning */
 
@@ -130,6 +131,8 @@ static int sg_err_category_new(int scsi_status, int msg_status, int
                                        return SG_ERR_CAT_MEDIA_CHANGED;
                                if (0x29 == asc)
                                        return SG_ERR_CAT_RESET;
+                       } else if (sense_key == ILLEGAL_REQUEST) {
+                               return SG_ERR_CAT_NOTSUPPORTED;
                        }
                }
                return SG_ERR_CAT_SENSE;
@@ -291,9 +294,9 @@ static int scsi_dump(struct sysfs_device *scsi_dev, struct sg_io_hdr *io)
                return -1;
 }
 
-static int scsi_inquiry(struct sysfs_device *scsi_dev, int fd, unsigned
-                       char evpd, unsigned char page, unsigned char *buf,
-                       unsigned int buflen)
+static int scsi_inquiry(struct sysfs_device *scsi_dev, int fd,
+                       unsigned char evpd, unsigned char page,
+                       unsigned char *buf, unsigned int buflen)
 {
        unsigned char inq_cmd[INQUIRY_CMDLEN] =
                { INQUIRY_CMD, evpd, page, 0, buflen, 0 };
@@ -331,6 +334,9 @@ resend:
        retval = sg_err_category3(&io_hdr);
 
        switch (retval) {
+               case SG_ERR_CAT_NOTSUPPORTED:
+                       buf[1] = 0;
+                       /* Fallthrough */
                case SG_ERR_CAT_CLEAN:
                case SG_ERR_CAT_RECOVERED:
                        retval = 0;
@@ -361,10 +367,10 @@ error:
 
 /* Get list of supported EVPD pages */
 static int do_scsi_page0_inquiry(struct sysfs_device *scsi_dev, int fd,
-                                char *buffer, int len)
+                                unsigned char *buffer, unsigned int len)
 {
        int retval;
-       char vendor[MAX_ATTR_LEN];
+       struct sysfs_attribute *vendor;
 
        memset(buffer, 0, len);
        retval = scsi_inquiry(scsi_dev, fd, 1, 0x0, buffer, len);
@@ -394,14 +400,15 @@ static int do_scsi_page0_inquiry(struct sysfs_device *scsi_dev, int fd,
                 * If the vendor id appears in the page assume the page is
                 * invalid.
                 */
-               if (sysfs_get_attr(scsi_dev->path, "vendor", vendor,
-                                  MAX_ATTR_LEN)) {
+               vendor = sysfs_get_device_attr(scsi_dev, "vendor");
+               if (!vendor) {
                        log_message(LOG_WARNING,
                                    "%s: cannot get model attribute\n",
                                    scsi_dev->name);
                        return 1;
                }
-               if (!strncmp(&buffer[VENDOR_LENGTH], vendor, VENDOR_LENGTH)) {
+               if (!strncmp((char *)&buffer[VENDOR_LENGTH], vendor->value,
+                            VENDOR_LENGTH)) {
                        log_message(LOG_WARNING, "%s: invalid page0 data\n",
                                    scsi_dev->name);
                        return 1;
@@ -416,15 +423,16 @@ static int do_scsi_page0_inquiry(struct sysfs_device *scsi_dev, int fd,
  */
 static int prepend_vendor_model(struct sysfs_device *scsi_dev, char *serial)
 {
-       char attr[MAX_ATTR_LEN];
+       struct sysfs_attribute *attr;
        int ind;
 
-       if (sysfs_get_attr(scsi_dev->path, "vendor", attr, MAX_ATTR_LEN)) {
+       attr = sysfs_get_device_attr(scsi_dev, "vendor");
+       if (!attr) {
                log_message(LOG_WARNING, "%s: cannot get vendor attribute\n",
                            scsi_dev->name);
                return 1;
        }
-       strncpy(serial, attr, VENDOR_LENGTH);
+       strncpy(serial, attr->value, VENDOR_LENGTH);
        ind = strlen(serial) - 1;
        /*
         * Remove sysfs added newlines.
@@ -432,12 +440,13 @@ static int prepend_vendor_model(struct sysfs_device *scsi_dev, char *serial)
        if (serial[ind] == '\n')
                serial[ind] = '\0';
 
-       if (sysfs_get_attr(scsi_dev->path, "model", attr, MAX_ATTR_LEN)) {
+       attr = sysfs_get_device_attr(scsi_dev, "model");
+       if (!attr) {
                log_message(LOG_WARNING, "%s: cannot get model attribute\n",
                            scsi_dev->name);
                return 1;
        }
-       strncat(serial, attr, MODEL_LENGTH);
+       strncat(serial, attr->value, MODEL_LENGTH);
        ind = strlen(serial) - 1;
        if (serial[ind] == '\n')
                serial[ind] = '\0';
@@ -461,8 +470,9 @@ static int prepend_vendor_model(struct sysfs_device *scsi_dev, char *serial)
  * check_fill_0x83_id - check the page 0x83 id, if OK allocate and fill
  * serial number.
  **/
-static int check_fill_0x83_id(struct sysfs_device *scsi_dev, char
-                             *page_83, const struct scsi_id_search_values
+static int check_fill_0x83_id(struct sysfs_device *scsi_dev,
+                             unsigned char *page_83,
+                             const struct scsi_id_search_values
                              *id_search, char *serial, int max_len)
 {
        int i, j, len;
@@ -553,7 +563,7 @@ static int do_scsi_page83_inquiry(struct sysfs_device *scsi_dev, int fd,
                                  char *serial, int len)
 {
        int retval;
-       int id_ind, j;
+       unsigned int id_ind, j;
        unsigned char page_83[SCSI_INQ_BUFF_LEN];
 
        memset(page_83, 0, SCSI_INQ_BUFF_LEN);
@@ -584,8 +594,7 @@ static int do_scsi_page83_inquiry(struct sysfs_device *scsi_dev, int fd,
                 * Examine each descriptor returned. There is normally only
                 * one or a small number of descriptors.
                 */
-               for (j = 4; j <= page_83[3] + 3;
-                       j += page_83[j + 3] + 4) {
+               for (j = 4; j <= (unsigned int)page_83[3] + 3; j += page_83[j + 3] + 4) {
                        retval = check_fill_0x83_id(scsi_dev, &page_83[j],
                                                    &id_search_list[id_ind],
                                                    serial, len);