]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/sysfs: Fix /dev to /sys node name translation
authorStanislav Brabec <sbrabec@suse.cz>
Wed, 27 May 2015 13:12:08 +0000 (15:12 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 28 May 2015 08:27:20 +0000 (10:27 +0200)
d0dc6c1 introduced translation of /sys names to /dev names, as required
by the kernel linux/drivers/base/core.c: device_get_devnode(). But there
are other places of code that use /dev names in /sys. They need reverse
translation from '/' to '!'.

For example, fdisk -l returns empty list since a22c6eb for device nodes
in subdirectories (used e. g. by cciss driver).

Introduce yet another helper sysfs_dev_name_to_devname() and use it where
appropriate.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
include/sysfs.h
lib/sysfs.c

index 4564124df0ddaf58eed286966d273ac6aa6cc9c9..6b08bbed5efb9cccecfba53a8484088a6873f8d4 100644 (file)
@@ -98,7 +98,7 @@ extern int sysfs_scsi_path_contains(struct sysfs_cxt *cxt, const char *pattern);
  * 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 '/'.
+ * @name by '/' to convert from /sys to /dev.
  */
 static inline void sysfs_devname_to_dev_name (char *name)
 {
@@ -109,4 +109,22 @@ static inline void sysfs_devname_to_dev_name (char *name)
                        c[0] = '/';
 }
 
+/**
+ * sysfs_dev_name_to_devname:
+ * @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 '!' to convert from /dev to /sys.
+ */
+static inline void sysfs_dev_name_to_devname (char *name)
+{
+       char *c;
+
+       if (name)
+               while ((c = strchr(name, '/')))
+                       c[0] = '!';
+}
+
 #endif /* UTIL_LINUX_SYSFS_H */
index 8417d2d76873e1a53e414c96a4b6a48b242f1722..34a520758b147ac85d7a2de8344f58e16961b023 100644 (file)
@@ -74,10 +74,14 @@ dev_t sysfs_devname_to_devno(const char *name, const char *parent)
 
        } else if (!dev) {
                /*
-                * Create path to /sys/block/<name>/dev
+                * Create path to /sys/block/<sysname>/dev
                 */
+               char sysname[PATH_MAX];
+
+               strncpy(sysname, name, sizeof(sysname));
+               sysfs_dev_name_to_devname(sysname);
                int len = snprintf(buf, sizeof(buf),
-                               _PATH_SYS_BLOCK "/%s/dev", name);
+                               _PATH_SYS_BLOCK "/%s/dev", sysname);
                if (len < 0 || (size_t) len + 1 > sizeof(buf))
                        return 0;
                path = buf;