chiark / gitweb /
libudev: device - handle /sys/block/<disk-device-link>/<partition>
authorKay Sievers <kay.sievers@vrfy.org>
Wed, 1 Oct 2008 08:22:47 +0000 (10:22 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Wed, 1 Oct 2008 08:22:47 +0000 (10:22 +0200)
udev/lib/libudev-device.c
udev/udevadm-info.c

index 893ec080a6159b5dc31e4f4f745b5fcd6855d952..a512537140b19ff76ab46d55518ab4a2d5077f0f 100644 (file)
@@ -231,8 +231,8 @@ struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *
 {
        size_t len;
        const char *subdir;
-       const char *pos;
        char path[UTIL_PATH_SIZE];
+       char *pos;
        struct stat statbuf;
        struct udev_device *udev_device;
 
@@ -260,6 +260,23 @@ struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *
        util_strlcpy(path, syspath, sizeof(path));
        util_resolve_sys_link(udev, path, sizeof(path));
 
+       /* try to resolve the silly block layout if needed */
+       if (strncmp(&path[len], "/block/", 7) == 0) {
+               char block[UTIL_PATH_SIZE];
+               char part[UTIL_PATH_SIZE];
+
+               util_strlcpy(block, path, sizeof(block));
+               pos = strrchr(block, '/');
+               if (pos == NULL)
+                       return NULL;
+               util_strlcpy(part, pos, sizeof(part));
+               pos[0] = '\0';
+               if (util_resolve_sys_link(udev, block, sizeof(block)) == 0) {
+                       util_strlcpy(path, block, sizeof(path));
+                       util_strlcat(path, part, sizeof(path));
+               }
+       }
+
        /* path exists in sys */
        if (strncmp(&syspath[len], "/devices/", 9) == 0 ||
            strncmp(&syspath[len], "/class/", 7) == 0 ||
index c2ff0bbea3c135a9add01ecb333b263a5eedde9a..4da9881dbe6593e104a061b8035294188caf360b 100644 (file)
@@ -341,7 +341,7 @@ int udevadm_info(struct udev *udev, int argc, char *argv[])
                                break;
                        }
                        fprintf(stderr, "unknown query type\n");
-                       rc = 2;
+                       rc = 3;
                        goto exit;
                case 'r':
                        if (action == ACTION_NONE)
@@ -407,9 +407,16 @@ int udevadm_info(struct udev *udev, int argc, char *argv[])
                                printf("%s\n", udev_device_get_devnode(device));
                        } else {
                                size_t len;
+                               const char *node;
 
                                len = strlen(udev_get_dev_path(udev));
-                               printf("%s\n", &udev_device_get_devnode(device)[len+1]);
+                               node = udev_device_get_devnode(device);
+                               if (node == NULL) {
+                                       fprintf(stderr, "no device node found\n");
+                                       rc = 5;
+                                       goto exit;
+                               }
+                                       printf("%s\n", &udev_device_get_devnode(device)[len+1]);
                        }
                        break;
                case QUERY_SYMLINK:
@@ -450,14 +457,14 @@ int udevadm_info(struct udev *udev, int argc, char *argv[])
        case ACTION_ATTRIBUTE_WALK:
                if (device == NULL) {
                        fprintf(stderr, "query needs a valid device specified by --path= or --name=\n");
-                       rc = 5;
+                       rc = 4;
                        goto exit;
                }
                print_device_chain(device);
                break;
        case ACTION_DEVICE_ID_FILE:
                if (stat_device(name, export, export_prefix) != 0)
-                       rc = 6;
+                       rc = 1;
                break;
        case ACTION_ROOT:
                printf("%s\n", udev_get_dev_path(udev));