]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
Fix /sys to /dev node name translation
authorStanislav Brabec <sbrabec@suse.cz>
Mon, 25 May 2015 16:21:36 +0000 (18:21 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 26 May 2015 09:42:38 +0000 (11:42 +0200)
linux/drivers/base/core.c: device_get_devnode() defines a translation of
'!' in sysfs nodes to '/' in /dev nodes. The same translation has to be
done to properly support device nodes with slash (e. g. device nodes of
cciss driver and several other drivers).

Introduce new helper sysfs_devname_to_devno() and use it where
appropriate.

Fixes for example lsblk -f on devices using cciss driver.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
include/sysfs.h
lib/sysfs.c
libblkid/src/devno.c
misc-utils/lsblk.c

index 1de624aadcb14d697ee38951cc56ef19ae59615a..4564124df0ddaf58eed286966d273ac6aa6cc9c9 100644 (file)
@@ -91,4 +91,22 @@ extern int sysfs_scsi_host_is(struct sysfs_cxt *cxt, const char *type);
 extern int sysfs_scsi_has_attribute(struct sysfs_cxt *cxt, const char *attr);
 extern int sysfs_scsi_path_contains(struct sysfs_cxt *cxt, const char *pattern);
 
+/**
+ * sysfs_devname_to_dev_name:
+ * @name: devname to be converted in place
+ *
+ * Linux kernel linux/drivers/base/core.c: device_get_devnode()
+ * defines a replacement of '!' in the /sys device name by '/' in the
+ * /dev device name. This helper replaces all ocurrences of '!' in
+ * @name by '/'.
+ */
+static inline void sysfs_devname_to_dev_name (char *name)
+{
+       char *c;
+
+       if (name)
+               while ((c = strchr(name, '!')))
+                       c[0] = '/';
+}
+
 #endif /* UTIL_LINUX_SYSFS_H */
index 759d97be6170b6c4c3511b059e06868677b8e238..8417d2d76873e1a53e414c96a4b6a48b242f1722 100644 (file)
@@ -131,6 +131,7 @@ char *sysfs_devno_to_devpath(dev_t devno, char *buf, size_t bufsiz)
                return NULL;
 
        /* create the final "/dev/<name>" string */
+       sysfs_devname_to_dev_name(name);
        memmove(buf + 5, name, sz + 1);
        memcpy(buf, "/dev/", 5);
 
@@ -789,6 +790,7 @@ int sysfs_devno_to_wholedisk(dev_t dev, char *diskname,
         if (!name)
             goto err;
 
+       sysfs_devname_to_dev_name(name);
         if (diskname && len) {
             strncpy(diskname, name, len);
             diskname[len - 1] = '\0';
index f4a36e4f566e5ca2be76eef80414011e86607966..3c082271beae55f1089b1b1360f9609f70e6befe 100644 (file)
@@ -208,6 +208,7 @@ static char *scandev_devno_to_devpath(dev_t devno)
                        new_list = NULL;
                }
        }
+       sysfs_devname_to_dev_name(devname);
        free_dirlist(&list);
        free_dirlist(&new_list);
 
index 1b4ffc1286ddaf6c0169075fdf69d080ac075c6a..d826c778f2e6c720fa54d043b5c0162015e745e2 100644 (file)
@@ -421,6 +421,7 @@ static char *get_device_path(struct blkdev_cxt *cxt)
                return canonicalize_dm_name(cxt->name);
 
        snprintf(path, sizeof(path), "/dev/%s", cxt->name);
+       sysfs_devname_to_dev_name(path);
        return xstrdup(path);
 }