chiark / gitweb /
libudev: switch API from devpath to syspath
authorKay Sievers <kay.sievers@vrfy.org>
Tue, 16 Sep 2008 00:12:47 +0000 (17:12 -0700)
committerKay Sievers <kay.sievers@vrfy.org>
Tue, 16 Sep 2008 00:12:47 +0000 (17:12 -0700)
TODO
udev/lib/exported_symbols
udev/lib/libudev-device.c
udev/lib/libudev-enumerate.c
udev/lib/libudev-monitor.c
udev/lib/libudev-private.h
udev/lib/libudev-util.c
udev/lib/libudev.h
udev/lib/test-libudev.c
udev/udevadm-info.c

diff --git a/TODO b/TODO
index 18f75b5..74f6936 100644 (file)
--- a/TODO
+++ b/TODO
@@ -11,5 +11,5 @@ These things will change in future udev versions:
   o symlink names to udevadm will no longer be resolved to old command names
 
 before next release:
-  o switch libudev API to syspath instead of devpath
+  o replace list.h with gpl or later version
   o udev_* prefix for private methods (ctrl_*)?
index aa3854d..ab12ff5 100644 (file)
@@ -7,7 +7,7 @@ udev_get_log_priority
 udev_set_log_priority
 udev_get_sys_path
 udev_get_dev_path
-udev_device_new_from_devpath
+udev_device_new_from_syspath
 udev_device_get_parent
 udev_device_ref
 udev_device_unref
index 918398b..782d662 100644 (file)
@@ -56,14 +56,14 @@ struct udev_device {
        struct list_head attr_list;
 };
 
-static size_t devpath_to_db_path(struct udev *udev, const char *devpath, char *filename, size_t len)
+static size_t syspath_to_db_path(struct udev_device *udev_device, char *filename, size_t len)
 {
        size_t start;
 
        /* translate to location of db file */
-       util_strlcpy(filename, udev_get_dev_path(udev), len);
+       util_strlcpy(filename, udev_get_dev_path(udev_device->udev), len);
        start = util_strlcat(filename, "/.udev/db/", len);
-       util_strlcat(filename, devpath, len);
+       util_strlcat(filename, udev_device->devpath, len);
        return util_path_encode(&filename[start], len - start);
 }
 
@@ -75,7 +75,7 @@ static int device_read_db(struct udev_device *udev_device)
        FILE *f;
        int rc = 0;
 
-       devpath_to_db_path(udev_device->udev, udev_device->devpath, filename, sizeof(filename));
+       syspath_to_db_path(udev_device, filename, sizeof(filename));
 
        if (lstat(filename, &stats) != 0) {
                info(udev_device->udev, "no db file to read %s: %s\n", filename, strerror(errno));
@@ -172,20 +172,20 @@ struct udev_device *device_init(struct udev *udev)
 }
 
 /**
- * udev_device_new_from_devpath:
+ * udev_device_new_from_syspath:
  * @udev: udev library context
- * @devpath: sys device path
+ * @syspath: sys device path including sys directory
  *
- * Create new udev device, and fill in information from the sysfs
- * device and the udev database entry. The devpath must not contain
- * the sysfs mount path, and must contain a leading '/'.
+ * Create new udev device, and fill in information from the sys
+ * device and the udev database entry. The sypath is the absolute
+ * path to the device, including the sys mount point.
  *
  * The initial refcount is 1, and needs to be decremented to
  * release the ressources of the udev device.
  *
  * Returns: a new udev device, or #NULL, if it does not exist
  **/
-struct udev_device *udev_device_new_from_devpath(struct udev *udev, const char *devpath)
+struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath)
 {
        char path[UTIL_PATH_SIZE];
        struct stat statbuf;
@@ -193,14 +193,13 @@ struct udev_device *udev_device_new_from_devpath(struct udev *udev, const char *
 
        if (udev == NULL)
                return NULL;
-       if (devpath == NULL)
+       if (syspath == NULL)
                return NULL;
 
-       util_strlcpy(path, udev_get_sys_path(udev), sizeof(path));
-       util_strlcat(path, devpath, sizeof(path));
+       util_strlcpy(path, syspath, sizeof(path));
        util_strlcat(path, "/uevent", sizeof(path));
        if (stat(path, &statbuf) != 0) {
-               info(udev, "not a device :%s\n", devpath);
+               info(udev, "not a device :%s\n", syspath);
                return NULL;
        }
 
@@ -209,9 +208,9 @@ struct udev_device *udev_device_new_from_devpath(struct udev *udev, const char *
                return NULL;
 
        /* resolve possible symlink to real path */
-       util_strlcpy(path, devpath, sizeof(path));
+       util_strlcpy(path, syspath, sizeof(path));
        util_resolve_sys_link(udev, path, sizeof(path));
-       device_set_devpath(udev_device, path);
+       device_set_syspath(udev_device, path);
        info(udev, "device %p has devpath '%s'\n", udev_device, udev_device_get_devpath(udev_device));
 
        if (device_read_db(udev_device) >= 0)
@@ -228,23 +227,23 @@ static struct udev_device *device_new_from_parent(struct udev_device *udev_devic
        if (udev_device == NULL)
                return NULL;
 
-       util_strlcpy(path, udev_device_get_devpath(udev_device), sizeof(path));
+       util_strlcpy(path, udev_device->syspath, sizeof(path));
        while (1) {
                pos = strrchr(path, '/');
                if (pos == path || pos == NULL)
                        break;
                pos[0] = '\0';
-               udev_device_parent = udev_device_new_from_devpath(udev_device->udev, path);
+               udev_device_parent = udev_device_new_from_syspath(udev_device->udev, path);
                if (udev_device_parent != NULL)
                        return udev_device_parent;
        }
 
-       /* follow "device" link in deprecated sysfs /sys/class/ layout */
+       /* follow "device" link in deprecated sys /sys/class/ layout */
        if (strncmp(udev_device->devpath, "/class/", 7) == 0) {
-               util_strlcpy(path, udev_device->devpath, sizeof(path));
+               util_strlcpy(path, udev_device->syspath, sizeof(path));
                util_strlcat(path, "/device", sizeof(path));
                if (util_resolve_sys_link(udev_device->udev, path, sizeof(path)) == 0) {
-                       udev_device_parent = udev_device_new_from_devpath(udev_device->udev, path);
+                       udev_device_parent = udev_device_new_from_syspath(udev_device->udev, path);
                        if (udev_device_parent != NULL)
                                return udev_device_parent;
                }
@@ -398,7 +397,7 @@ const char *udev_device_get_subsystem(struct udev_device *udev_device)
                return udev_device->subsystem;
 
        /* read "subsytem" link */
-       if (util_get_sys_subsystem(udev_device->udev, udev_device->devpath, subsystem, sizeof(subsystem)) == 0) {
+       if (util_get_sys_subsystem(udev_device->udev, udev_device->syspath, subsystem, sizeof(subsystem)) == 0) {
                udev_device->subsystem = strdup(subsystem);
                return udev_device->subsystem;
        }
@@ -490,7 +489,7 @@ const char *udev_device_get_driver(struct udev_device *udev_device)
                return NULL;
        if (udev_device->driver != NULL)
                return udev_device->driver;
-       if (util_get_sys_driver(udev_device->udev, udev_device->devpath, driver, sizeof(driver)) < 2)
+       if (util_get_sys_driver(udev_device->udev, udev_device->syspath, driver, sizeof(driver)) < 2)
                return NULL;
        udev_device->driver = strdup(driver);
        return udev_device->driver;
@@ -592,14 +591,18 @@ const char *udev_device_get_attr_value(struct udev_device *udev_device, const ch
 out:
        return val;
 }
-int device_set_devpath(struct udev_device *udev_device, const char *devpath)
+int device_set_syspath(struct udev_device *udev_device, const char *syspath)
 {
-       if (asprintf(&udev_device->syspath, "%s%s", udev_get_sys_path(udev_device->udev), devpath) < 0)
+       const char *pos;
+
+       udev_device->syspath = strdup(syspath);
+       if (udev_device->syspath ==  NULL)
                return -ENOMEM;
        udev_device->devpath = &udev_device->syspath[strlen(udev_get_sys_path(udev_device->udev))];
-       udev_device->sysname = strrchr(udev_device->syspath, '/');
-       if (udev_device->sysname != NULL)
-               udev_device->sysname = &udev_device->sysname[1];
+       pos = strrchr(udev_device->syspath, '/');
+       if (pos == NULL)
+               return -EINVAL;
+       udev_device->sysname = &pos[1];
        return 0;
 }
 
index 95a4076..458be58 100644 (file)
@@ -38,9 +38,8 @@ static int devices_scan_subsystem(struct udev *udev,
        char path[UTIL_PATH_SIZE];
        DIR *dir;
        struct dirent *dent;
-       size_t len;
 
-       len = util_strlcpy(path, udev_get_sys_path(udev), sizeof(path));
+       util_strlcpy(path, udev_get_sys_path(udev), sizeof(path));
        util_strlcat(path, basedir, sizeof(path));
        util_strlcat(path, "/", sizeof(path));
        util_strlcat(path, subsystem, sizeof(path));
@@ -50,15 +49,15 @@ static int devices_scan_subsystem(struct udev *udev,
        if (dir == NULL)
                return -1;
        for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
-               char devpath[UTIL_PATH_SIZE];
+               char syspath[UTIL_PATH_SIZE];
 
                if (dent->d_name[0] == '.')
                        continue;
-               util_strlcpy(devpath, &path[len], sizeof(devpath));
-               util_strlcat(devpath, "/", sizeof(devpath));
-               util_strlcat(devpath, dent->d_name, sizeof(devpath));
-               util_resolve_sys_link(udev, devpath, sizeof(devpath));
-               util_name_list_add(udev, device_list, devpath, NULL, 1);
+               util_strlcpy(syspath, path, sizeof(syspath));
+               util_strlcat(syspath, "/", sizeof(syspath));
+               util_strlcat(syspath, dent->d_name, sizeof(syspath));
+               util_resolve_sys_link(udev, syspath, sizeof(syspath));
+               util_name_list_add(udev, device_list, syspath, NULL, 1);
        }
        closedir(dir);
        return 0;
@@ -89,27 +88,30 @@ static int devices_scan_subsystems(struct udev *udev,
        return 0;
 }
 
-static int devices_delay(struct udev *udev, const char *devpath)
+static int devices_delay(struct udev *udev, const char *syspath)
 {
        static const char *delay_device_list[] = {
                "/block/md",
                "/block/dm-",
                NULL
        };
+       size_t len;
        int i;
 
+       len = strlen(udev_get_sys_path(udev));
+
        for (i = 0; delay_device_list[i] != NULL; i++) {
-               if (strstr(devpath, delay_device_list[i]) != NULL) {
-                       info(udev, "delaying: %s\n", devpath);
+               if (strstr(&syspath[len], delay_device_list[i]) != NULL) {
+                       info(udev, "delaying: %s\n", syspath);
                        return 1;
                }
        }
        return 0;
 }
 
-static int devices_call(struct udev *udev, const char *devpath,
+static int devices_call(struct udev *udev, const char *syspath,
                        int (*cb)(struct udev *udev,
-                                 const char *devpath, const char *subsystem, const char *name,
+                                 const char *syspath, const char *subsystem, const char *name,
                                  void *data),
                        void *data,
                        int *cb_rc)
@@ -117,14 +119,14 @@ static int devices_call(struct udev *udev, const char *devpath,
        char subsystem[UTIL_PATH_SIZE];
        const char *name;
 
-       name = strrchr(devpath, '/');
+       name = strrchr(syspath, '/');
        if (name == NULL)
                return -1;
        name++;
 
-       if (util_get_sys_subsystem(udev, devpath, subsystem, sizeof(subsystem)) < 2)
+       if (util_get_sys_subsystem(udev, syspath, subsystem, sizeof(subsystem)) < 2)
                return -1;
-       *cb_rc = cb(udev, devpath, subsystem, name, data);
+       *cb_rc = cb(udev, syspath, subsystem, name, data);
        return 0;
 }
 
@@ -143,7 +145,7 @@ static int devices_call(struct udev *udev, const char *devpath,
  **/
 int udev_enumerate_devices(struct udev *udev, const char *subsystem,
                           int (*cb)(struct udev *udev,
-                                    const char *devpath, const char *subsystem, const char *name, void *data),
+                                    const char *syspath, const char *subsystem, const char *name, void *data),
                           void *data)
 {
        char base[UTIL_PATH_SIZE];
index 8e9cf2d..f61ddb0 100644 (file)
@@ -302,7 +302,11 @@ struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monito
                bufpos += keylen + 1;
 
                if (strncmp(key, "DEVPATH=", 8) == 0) {
-                       device_set_devpath(udev_device, &key[8]);
+                       char path[UTIL_PATH_SIZE];
+
+                       util_strlcpy(path, udev_get_sys_path(udev_monitor->udev), sizeof(path));
+                       util_strlcat(path, &key[8], sizeof(path));
+                       device_set_syspath(udev_device, path);
                } else if (strncmp(key, "SUBSYSTEM=", 10) == 0) {
                        device_set_subsystem(udev_device, &key[10]);
                } else if (strncmp(key, "DEVNAME=", 8) == 0) {
@@ -336,6 +340,8 @@ struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monito
                } else if (strncmp(key, "TIMEOUT=", 8) == 0) {
                        device_set_timeout(udev_device, strtoull(&key[8], NULL, 10));
                }
+               if (strncmp(key, "PHYSDEV", 7) == 0)
+                       continue;
                device_add_property_from_string(udev_device, key);
        }
        device_set_devnum(udev_device, makedev(maj, min));
index f28bd9a..1756be5 100644 (file)
@@ -55,7 +55,7 @@ extern const char *udev_get_rules_path(struct udev *udev);
 extern int udev_get_run(struct udev *udev);
 
 /* libudev-device */
-extern int device_set_devpath(struct udev_device *udev_device, const char *devpath);
+extern int device_set_syspath(struct udev_device *udev_device, const char *syspath);
 extern int device_set_subsystem(struct udev_device *udev_device, const char *subsystem);
 extern int device_set_devname(struct udev_device *udev_device, const char *devname);
 extern int device_add_devlink(struct udev_device *udev_device, const char *devlink);
@@ -114,9 +114,9 @@ struct util_name_entry {
        char *value;
        int *i;
 };
-extern ssize_t util_get_sys_subsystem(struct udev *udev, const char *devpath, char *subsystem, size_t size);
-extern ssize_t util_get_sys_driver(struct udev *udev, const char *devpath, char *driver, size_t size);
-extern int util_resolve_sys_link(struct udev *udev, char *devpath, size_t size);
+extern ssize_t util_get_sys_subsystem(struct udev *udev, const char *syspath, char *subsystem, size_t size);
+extern ssize_t util_get_sys_driver(struct udev *udev, const char *syspath, char *driver, size_t size);
+extern int util_resolve_sys_link(struct udev *udev, char *syspath, size_t size);
 extern struct util_name_entry *util_name_list_add(struct udev *udev, struct list_head *name_list,
                                                  const char *name, const char *value, int sort);
 extern void util_name_list_cleanup(struct udev *udev, struct list_head *name_list);
@@ -127,5 +127,4 @@ extern void util_remove_trailing_chars(char *path, char c);
 extern size_t util_strlcpy(char *dst, const char *src, size_t size);
 extern size_t util_strlcat(char *dst, const char *src, size_t size);
 extern int util_replace_chars(char *str, const char *white);
-extern char *util_sysattr_get_value(struct udev *udev, const char *devpath, const char *attr_name);
 #endif
index 50eacdd..7053a2f 100644 (file)
 #include "libudev.h"
 #include "libudev-private.h"
 
-static ssize_t get_sys_link(struct udev *udev, const char *slink, const char *devpath, char *subsystem, size_t size)
+static ssize_t get_sys_link(struct udev *udev, const char *slink, const char *syspath, char *subsystem, size_t size)
 {
        char path[UTIL_PATH_SIZE];
        ssize_t len;
        const char *pos;
 
-       util_strlcpy(path, udev_get_sys_path(udev), sizeof(path));
-       util_strlcat(path, devpath, sizeof(path));
+       util_strlcpy(path, syspath, sizeof(path));
        util_strlcat(path, "/", sizeof(path));
        util_strlcat(path, slink, sizeof(path));
        len = readlink(path, path, sizeof(path));
@@ -54,46 +53,43 @@ static ssize_t get_sys_link(struct udev *udev, const char *slink, const char *de
        return util_strlcpy(subsystem, pos, size);
 }
 
-ssize_t util_get_sys_subsystem(struct udev *udev, const char *devpath, char *subsystem, size_t size)
+ssize_t util_get_sys_subsystem(struct udev *udev, const char *syspath, char *subsystem, size_t size)
 {
-       return get_sys_link(udev, "subsystem", devpath, subsystem, size);
+       return get_sys_link(udev, "subsystem", syspath, subsystem, size);
 }
 
-ssize_t util_get_sys_driver(struct udev *udev, const char *devpath, char *driver, size_t size)
+ssize_t util_get_sys_driver(struct udev *udev, const char *syspath, char *driver, size_t size)
 {
-       return get_sys_link(udev, "driver", devpath, driver, size);
+       return get_sys_link(udev, "driver", syspath, driver, size);
 }
 
-int util_resolve_sys_link(struct udev *udev, char *devpath, size_t size)
+int util_resolve_sys_link(struct udev *udev, char *syspath, size_t size)
 {
-       char link_path[UTIL_PATH_SIZE];
        char link_target[UTIL_PATH_SIZE];
 
        int len;
        int i;
        int back;
 
-       util_strlcpy(link_path, udev_get_sys_path(udev), sizeof(link_path));
-       util_strlcat(link_path, devpath, sizeof(link_path));
-       len = readlink(link_path, link_target, sizeof(link_target));
+       len = readlink(syspath, link_target, sizeof(link_target));
        if (len <= 0)
                return -1;
        link_target[len] = '\0';
-       dbg(udev, "path link '%s' points to '%s'\n", devpath, link_target);
+       dbg(udev, "path link '%s' points to '%s'\n", syspath, link_target);
 
        for (back = 0; strncmp(&link_target[back * 3], "../", 3) == 0; back++)
                ;
-       dbg(udev, "base '%s', tail '%s', back %i\n", devpath, &link_target[back * 3], back);
+       dbg(udev, "base '%s', tail '%s', back %i\n", syspath, &link_target[back * 3], back);
        for (i = 0; i <= back; i++) {
-               char *pos = strrchr(devpath, '/');
+               char *pos = strrchr(syspath, '/');
 
                if (pos == NULL)
                        return -1;
                pos[0] = '\0';
        }
-       dbg(udev, "after moving back '%s'\n", devpath);
-       util_strlcat(devpath, "/", size);
-       util_strlcat(devpath, &link_target[back * 3], size);
+       dbg(udev, "after moving back '%s'\n", syspath);
+       util_strlcat(syspath, "/", size);
+       util_strlcat(syspath, &link_target[back * 3], size);
        return 0;
 }
 
index 05f23e1..6996b47 100644 (file)
@@ -45,7 +45,7 @@ extern void udev_selinux_setfscreatecon(struct udev *udev, const char *file, uns
 extern void udev_selinux_lsetfilecon(struct udev *udev, const char *file, unsigned int mode);
 
 struct udev_device;
-extern struct udev_device *udev_device_new_from_devpath(struct udev *udev, const char *devpath);
+extern struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath);
 extern struct udev_device *udev_device_get_parent(struct udev_device *udev_device);
 extern struct udev_device *udev_device_ref(struct udev_device *udev_device);
 extern void udev_device_unref(struct udev_device *udev_device);
@@ -71,7 +71,7 @@ extern const char *udev_device_get_attr_value(struct udev_device *udev_device, c
 
 extern int udev_enumerate_devices(struct udev *udev, const char *subsystem,
                                  int (*cb)(struct udev *udev,
-                                           const char *devpath, const char *subsystem, const char *name, void *data),
+                                           const char *syspath, const char *subsystem, const char *name, void *data),
                                  void *data);
 
 struct udev_monitor;
index b301176..4dcc80a 100644 (file)
@@ -56,14 +56,14 @@ static void print_device(struct udev_device *device)
        int count;
 
        printf("*** device: %p ***\n", device);
+       str = udev_device_get_syspath(device);
+       printf("syspath:   '%s'\n", str);
        str = udev_device_get_devpath(device);
        printf("devpath:   '%s'\n", str);
        str = udev_device_get_subsystem(device);
        printf("subsystem: '%s'\n", str);
        str = udev_device_get_driver(device);
        printf("driver:    '%s'\n", str);
-       str = udev_device_get_syspath(device);
-       printf("syspath:   '%s'\n", str);
        str = udev_device_get_devname(device);
        printf("devname:   '%s'\n", str);
        count = udev_device_get_devlinks(device, print_devlinks_cb, NULL);
@@ -73,12 +73,12 @@ static void print_device(struct udev_device *device)
        printf("\n");
 }
 
-static int test_device(struct udev *udev, const char *devpath)
+static int test_device(struct udev *udev, const char *syspath)
 {
        struct udev_device *device;
 
-       printf("looking at device: %s\n", devpath);
-       device = udev_device_new_from_devpath(udev, devpath);
+       printf("looking at device: %s\n", syspath);
+       device = udev_device_new_from_syspath(udev, syspath);
        if (device == NULL) {
                printf("no device\n");
                return -1;
@@ -88,13 +88,13 @@ static int test_device(struct udev *udev, const char *devpath)
        return 0;
 }
 
-static int test_device_parents(struct udev *udev, const char *devpath)
+static int test_device_parents(struct udev *udev, const char *syspath)
 {
        struct udev_device *device;
        struct udev_device *device_parent;
 
-       printf("looking at device: %s\n", devpath);
-       device = udev_device_new_from_devpath(udev, devpath);
+       printf("looking at device: %s\n", syspath);
+       device = udev_device_new_from_syspath(udev, syspath);
        if (device == NULL)
                return -1;
 
@@ -185,7 +185,7 @@ int main(int argc, char *argv[], char *envp[])
 {
        struct udev *udev = NULL;
        static const struct option options[] = {
-               { "devpath", 1, NULL, 'p' },
+               { "syspath", 1, NULL, 'p' },
                { "subsystem", 1, NULL, 's' },
                { "socket", 1, NULL, 'S' },
                { "debug", 0, NULL, 'd' },
@@ -193,9 +193,10 @@ int main(int argc, char *argv[], char *envp[])
                { "version", 0, NULL, 'V' },
                {}
        };
-       const char *devpath = "/devices/virtual/mem/null";
+       const char *syspath = "/devices/virtual/mem/null";
        const char *subsystem = NULL;
        const char *socket = "@/org/kernel/udev/monitor";
+       char path[1024];
        const char *str;
 
        udev = udev_new();
@@ -216,7 +217,7 @@ int main(int argc, char *argv[], char *envp[])
 
                switch (option) {
                case 'p':
-                       devpath = optarg;
+                       syspath = optarg;
                        break;
                case 's':
                        subsystem = optarg;
@@ -229,7 +230,7 @@ int main(int argc, char *argv[], char *envp[])
                                udev_set_log_priority(udev, LOG_INFO);
                        break;
                case 'h':
-                       printf("--debug --devpath= --subsystem= --socket= --help\n");
+                       printf("--debug --syspath= --subsystem= --socket= --help\n");
                        goto out;
                case 'V':
                        printf("%s\n", VERSION);
@@ -244,8 +245,14 @@ int main(int argc, char *argv[], char *envp[])
        str = udev_get_dev_path(udev);
        printf("dev_path: '%s'\n", str);
 
-       test_device(udev, devpath);
-       test_device_parents(udev, devpath);
+       /* add sys path if needed */
+       if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) {
+               snprintf(path, sizeof(path), "%s%s", udev_get_sys_path(udev), syspath);
+               syspath = path;
+       }
+
+       test_device(udev, syspath);
+       test_device_parents(udev, syspath);
        test_enumerate(udev, subsystem);
        test_monitor(udev, socket);
 out:
index a2858e5..9ce83aa 100644 (file)
@@ -166,12 +166,12 @@ static void print_record(struct udev_device *device)
 }
 
 static int export_all_cb(struct udev *udev,
-                        const char *devpath, const char *subsystem, const char *name,
+                        const char *syspath, const char *subsystem, const char *name,
                         void *data)
 {
        struct udev_device *device;
 
-       device = udev_device_new_from_devpath(udev, devpath);
+       device = udev_device_new_from_syspath(udev, syspath);
        if (device == NULL)
                return 0;
        if (udev_device_get_devname(device) != NULL)
@@ -215,7 +215,9 @@ static struct udev_device *lookup_device_by_name(struct udev *udev, const char *
                        info(udev, "skip '%s', dev_t doesn't match\n", udevice_loop->name);
                        goto next;
                }
-               udev_device = udev_device_new_from_devpath(udev, udevice_loop->dev->devpath);
+               util_strlcpy(filename, udev_get_sys_path(udev), sizeof(filename));
+               util_strlcat(filename,  udevice_loop->dev->devpath, sizeof(filename));
+               udev_device = udev_device_new_from_syspath(udev, filename);
                udev_device_cleanup(udevice_loop);
                break;
 next:
@@ -348,13 +350,15 @@ int udevadm_info(struct udev *udev, int argc, char *argv[])
                                rc = 2;
                                goto exit;
                        }
-                       /* remove /sys if given */
-                       if (strncmp(optarg, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) == 0)
-                               util_strlcpy(path, &optarg[strlen(udev_get_sys_path(udev))], sizeof(path));
-                       else
+                       /* add /sys if needed */
+                       if (strncmp(optarg, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) {
+                               util_strlcpy(path, udev_get_sys_path(udev), sizeof(path));
+                               util_strlcat(path, optarg, sizeof(path));
+                       } else {
                                util_strlcpy(path, optarg, sizeof(path));
+                       }
                        util_remove_trailing_chars(path, '/');
-                       device = udev_device_new_from_devpath(udev, path);
+                       device = udev_device_new_from_syspath(udev, path);
                        break;
                case 'q':
                        action = ACTION_QUERY;