chiark / gitweb /
fix NAME= and OPTION+="string_escape=..." logic
[elogind.git] / extras / usb_id / usb_id.c
index 28352eb08a239d9c36e812b893b10ce2c9c12626..3d007f9ee5a66f62e7cd277c3fc9b2e137b51ec6 100644 (file)
@@ -62,7 +62,7 @@ static void set_usb_iftype(char *to, int if_class_num, size_t len)
        case 5: /* Physical */
                break;
        case 6:
        case 5: /* Physical */
                break;
        case 6:
-               type = "image";
+               type = "media";
                break;
        case 7:
                type = "printer";
                break;
        case 7:
                type = "printer";
@@ -107,7 +107,7 @@ static int set_usb_mass_storage_ifsubtype(char *to, const char *from, size_t len
        if (eptr != from) {
                switch (type_num) {
                case 2:
        if (eptr != from) {
                switch (type_num) {
                case 2:
-                       type = "cd";
+                       type = "atapi";
                        break;
                case 3:
                        type = "tape";
                        break;
                case 3:
                        type = "tape";
@@ -127,7 +127,6 @@ static int set_usb_mass_storage_ifsubtype(char *to, const char *from, size_t len
                }
        }
        util_strlcpy(to, type, len);
                }
        }
        util_strlcpy(to, type, len);
-
        return type_num;
 }
 
        return type_num;
 }
 
@@ -192,7 +191,7 @@ static int usb_id(struct udev_device *dev)
        dbg(udev, "syspath %s\n", udev_device_get_syspath(dev));
 
        /* usb interface directory */
        dbg(udev, "syspath %s\n", udev_device_get_syspath(dev));
 
        /* usb interface directory */
-       dev_interface = udev_device_get_parent_with_subsystem(dev, "usb");
+       dev_interface = udev_device_get_parent_with_subsystem_devtype(dev, "usb", "usb_interface");
        if (dev_interface == NULL) {
                info(udev, "unable to access usb_interface device of '%s'\n",
                     udev_device_get_syspath(dev));
        if (dev_interface == NULL) {
                info(udev, "unable to access usb_interface device of '%s'\n",
                     udev_device_get_syspath(dev));
@@ -205,8 +204,10 @@ static int usb_id(struct udev_device *dev)
                     udev_device_get_sysname(dev));
                return 1;
        }
                     udev_device_get_sysname(dev));
                return 1;
        }
+
        if_class_num = strtoul(if_class, NULL, 16);
        if (if_class_num == 8) {
        if_class_num = strtoul(if_class, NULL, 16);
        if (if_class_num == 8) {
+               /* mass storage */
                if_subclass = udev_device_get_sysattr_value(dev_interface, "bInterfaceSubClass");
                if (if_subclass != NULL)
                        protocol = set_usb_mass_storage_ifsubtype(type_str, if_subclass, sizeof(type_str)-1);
                if_subclass = udev_device_get_sysattr_value(dev_interface, "bInterfaceSubClass");
                if (if_subclass != NULL)
                        protocol = set_usb_mass_storage_ifsubtype(type_str, if_subclass, sizeof(type_str)-1);
@@ -218,21 +219,21 @@ static int usb_id(struct udev_device *dev)
             udev_device_get_syspath(dev_interface), if_class_num, protocol);
 
        /* usb device directory */
             udev_device_get_syspath(dev_interface), if_class_num, protocol);
 
        /* usb device directory */
-       dev_usb = udev_device_get_parent_with_subsystem(dev_interface, "usb");
+       dev_usb = udev_device_get_parent_with_subsystem_devtype(dev_interface, "usb", "usb_device");
        if (!dev_usb) {
                info(udev, "unable to find parent 'usb' device of '%s'\n",
                     udev_device_get_syspath(dev));
                return 1;
        }
 
        if (!dev_usb) {
                info(udev, "unable to find parent 'usb' device of '%s'\n",
                     udev_device_get_syspath(dev));
                return 1;
        }
 
-       /* mass storage */
-       if (protocol == 6 && !use_usb_info) {
+       /* mass storage : SCSI or ATAPI */
+       if ((protocol == 6 || protocol == 2) && !use_usb_info) {
                struct udev_device *dev_scsi;
                const char *scsi_model, *scsi_vendor, *scsi_type, *scsi_rev;
                int host, bus, target, lun;
 
                /* get scsi device */
                struct udev_device *dev_scsi;
                const char *scsi_model, *scsi_vendor, *scsi_type, *scsi_rev;
                int host, bus, target, lun;
 
                /* get scsi device */
-               dev_scsi = udev_device_get_parent_with_subsystem(dev, "scsi");
+               dev_scsi = udev_device_get_parent_with_subsystem_devtype(dev, "scsi", "scsi_device");
                if (dev_scsi == NULL) {
                        info(udev, "unable to find parent 'scsi' device of '%s'\n",
                             udev_device_get_syspath(dev));
                if (dev_scsi == NULL) {
                        info(udev, "unable to find parent 'scsi' device of '%s'\n",
                             udev_device_get_syspath(dev));
@@ -395,7 +396,7 @@ int main(int argc, char **argv)
                        printf("Usage: usb_id [--usb-info] [--num-info] [--export] [--help] <devpath>\n"
                               "  --usb-info  use usb strings instead\n"
                               "  --num-info  use numerical values\n"
                        printf("Usage: usb_id [--usb-info] [--num-info] [--export] [--help] <devpath>\n"
                               "  --usb-info  use usb strings instead\n"
                               "  --num-info  use numerical values\n"
-                              "  --export    print values as environemt keys\n"
+                              "  --export    print values as environment keys\n"
                               "  --help      print this help text\n\n");
                default:
                        retval = 1;
                               "  --help      print this help text\n\n");
                default:
                        retval = 1;