chiark / gitweb /
add ID_TYPE to the id probers
authorKay Sievers <kay.sievers@suse.de>
Mon, 27 Jun 2005 15:04:56 +0000 (17:04 +0200)
committerKay Sievers <kay.sievers@suse.de>
Mon, 27 Jun 2005 15:04:56 +0000 (17:04 +0200)
Export the type of device from ata_id and scsi_id, also strip
leading and trailing whitespace and substitute consecutive
whitespace with a single underline char.

From: Hannes Reinecke <hare@suse.de>
Signed-off-by: Kay Sievers <kay.sievers@suse.de>
extras/ata_id/ata_id.c
extras/scsi_id/scsi_id.c
udev_rules.c
udev_utils.c
udevd.c

index 59e2b3987b376b6dc58aed5144c0b32d345c393b..34b1ccdff1203be22f444626ef9ad63879fab7a4 100644 (file)
@@ -67,25 +67,30 @@ static void set_str(char *to, const unsigned char *from, int count)
        int i, j;
        int len;
 
+       /* strip trailing whitespace */
        len = strnlen(from, count);
        while (isspace(from[len-1]))
                len--;
 
+       /* strip leading whitespace */
        i = 0;
        while (isspace(from[i]) && (i < len))
                i++;
 
        j = 0;
        while (i < len) {
-               switch(from[i]) {
-               case '/':
-               case ' ':
+               /* substitute multiple whitespace */
+               if (isspace(from[i])) {
+                       while (isspace(from[i]))
+                               i++;
                        to[j++] = '_';
-                       break;
-               default:
-                       to[j++] = from[i];
                }
-               i++;
+               /* skip chars */
+               if (from[i] == '/') {
+                       i++;
+                       continue;
+               }
+               to[j++] = from[i++];
        }
        to[j] = '\0';
 }
@@ -137,6 +142,28 @@ int main(int argc, char *argv[])
        set_str(revision, id.fw_rev, 8);
 
        if (export) {
+               if ((id.config >> 8) & 0x80) {
+                       /* This is an ATAPI device */
+                       switch ((id.config >> 8) & 0x1f) {
+                       case 0:
+                               printf("ID_TYPE=cd\n");
+                               break;
+                       case 1:
+                               printf("ID_TYPE=tape\n");
+                               break;
+                       case 5:
+                               printf("ID_TYPE=cd\n");
+                               break;
+                       case 7:
+                               printf("ID_TYPE=optical\n");
+                               break;
+                       default:
+                               printf("ID_TYPE=generic\n");
+                               break;
+                       }
+               } else {
+                       printf("ID_TYPE=disk\n");
+               }
                printf("ID_MODEL=%s\n", model);
                printf("ID_SERIAL=%s\n", serial);
                printf("ID_REVISION=%s\n", revision);
index 86b84bee30e6337e4c04680d75771b98fa3003f9..4003ee6af5a66dcaf436cf06a7097eb144856240 100644 (file)
@@ -74,6 +74,8 @@ static int reformat_serial;
 static int export;
 static char vendor_str[64];
 static char model_str[64];
+static char revision_str[16];
+static char type_str[16];
 
 void log_message (int level, const char *format, ...)
 {
@@ -103,27 +105,70 @@ static void set_str(char *to, const unsigned char *from, int count)
        int i, j;
        int len;
 
+       /* strip trailing whitespace */
        len = strnlen(from, count);
        while (isspace(from[len-1]))
                len--;
 
+       /* strip leading whitespace */
        i = 0;
        while (isspace(from[i]) && (i < len))
                i++;
 
        j = 0;
        while (i < len) {
-               switch(from[i]) {
-               case '/':
-               case ' ':
+               /* substitute multiple whitespace */
+               if (isspace(from[i])) {
+                       while (isspace(from[i]))
+                               i++;
                        to[j++] = '_';
+               }
+               /* skip chars */
+               if (from[i] == '/') {
+                       i++;
+                       continue;
+               }
+               to[j++] = from[i++];
+       }
+       to[j] = '\0';
+}
+
+static void set_type(char *to, const char *from, int count)
+{
+       int type_num;
+       char *eptr;
+
+       type_num = strtoul(from, &eptr, 0);
+       if (eptr != from) {
+               switch (type_num) {
+               case 0:
+                       sprintf(to, "disk");
+                       break;
+               case 1:
+                       sprintf(to, "tape");
+                       break;
+               case 4:
+                       sprintf(to, "optical");
+                       break;
+               case 5:
+                       sprintf(to, "cd");
+                       break;
+               case 7:
+                       sprintf(to, "optical");
+                       break;
+               case 0xe:
+                       sprintf(to, "disk");
+                       break;
+               case 0xf:
+                       sprintf(to, "optical");
                        break;
                default:
-                       to[j++] = from[i];
+                       sprintf(to, "generic");
+                       break;
                }
-               i++;
+       } else {
+               sprintf(to, "generic");
        }
-       to[j] = '\0';
 }
 
 static int get_major_minor(struct sysfs_class_device *class_dev, int *maj,
@@ -521,7 +566,7 @@ static int per_dev_options(struct sysfs_device *scsi_dev, int *good_bad,
        int retval;
        int newargc;
        char **newargv = NULL;
-       struct sysfs_attribute *vendor, *model;
+       struct sysfs_attribute *vendor, *model, *type;
        int option;
 
        *good_bad = all_good;
@@ -547,6 +592,22 @@ static int per_dev_options(struct sysfs_device *scsi_dev, int *good_bad,
        }
        set_str(model_str, model->value, sizeof(model_str)-1);
 
+       type = sysfs_get_device_attr(scsi_dev, "type");
+       if (!type) {
+               log_message(LOG_WARNING, "%s: cannot get type attribute\n",
+                           scsi_dev->name);
+               return -1;
+       }
+       set_type(type_str, type->value, sizeof(type_str)-1);
+
+       type = sysfs_get_device_attr(scsi_dev, "rev");
+       if (!type) {
+               log_message(LOG_WARNING, "%s: cannot get type attribute\n",
+                           scsi_dev->name);
+               return -1;
+       }
+       set_str(revision_str, type->value, sizeof(revision_str)-1);
+
        retval = get_file_options(vendor->value, model->value, &newargc,
                                  &newargv);
 
@@ -616,7 +677,6 @@ static void format_serial(char *serial)
                        *p = '_';
                p++;
        }
-return;
 }
 
 /*
@@ -759,8 +819,10 @@ static int scsi_id(const char *target_path, char *maj_min_dev)
                        static char serial_str[64];
                        printf("ID_VENDOR=%s\n", vendor_str);
                        printf("ID_MODEL=%s\n", model_str);
+                       printf("ID_REVISION=%s\n", revision_str);
                        set_str(serial_str, serial, sizeof(serial_str));
                        printf("ID_SERIAL=%s\n", serial_str);
+                       printf("ID_TYPE=%s\n", type_str);
                } else {
                        if (reformat_serial)
                                format_serial(serial);
index 9b9454e8fbcd53f8b0654975bb8b8c598c327dbd..9606f04d3df64f88b0eb2cbce40d87379ce32ac8 100644 (file)
@@ -793,7 +793,7 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule,
                                        len = strlen(value);
                                        while (len > 0 && isspace(value[len-1]))
                                                value[--len] = '\0';
-                                       dbg("removed %i trailing whitespace chars from '%s'", strlen(value)-len, value);
+                                       dbg("removed %zi trailing whitespace chars from '%s'", strlen(value)-len, value);
                                }
 
                                dbg("compare attribute '%s' value '%s' with '%s'", pair->name, value, pair->value);
index 3ab9e433486aa55f2f95027155327b2c50a22902..073cde1074f921ef920a44aeddb5aa5fb2189875 100644 (file)
@@ -485,7 +485,7 @@ int execute_program(const char *command, const char *subsystem,
 
                                len += count;
                                if (len >= ressize-1) {
-                                       err("ressize %d too short", ressize);
+                                       err("ressize %ld too short", (long)ressize);
                                        retval = -1;
                                        break;
                                }
diff --git a/udevd.c b/udevd.c
index 209b9fcd870074ed0db22e8c1a932e98b959f0a2..e3ee1457cb894993cf4f33d668953efe06156d32 100644 (file)
--- a/udevd.c
+++ b/udevd.c
@@ -600,7 +600,7 @@ static struct uevent_msg *get_netlink_msg(void)
        if ((size_t)size > sizeof(buffer)-1)
                size = sizeof(buffer)-1;
        buffer[size] = '\0';
-       dbg("uevent_size=%i", size);
+       dbg("uevent_size=%li", (long)size);
 
        /* start of event payload */
        bufpos = strlen(buffer)+1;