diff options
-rw-r--r-- | include/sysfs.h | 18 | ||||
-rw-r--r-- | lib/sysfs.c | 2 | ||||
-rw-r--r-- | libblkid/src/devno.c | 1 | ||||
-rw-r--r-- | misc-utils/lsblk.c | 1 |
4 files changed, 22 insertions, 0 deletions
diff --git a/include/sysfs.h b/include/sysfs.h index 1de624aad..4564124df 100644 --- a/include/sysfs.h +++ b/include/sysfs.h @@ -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 */ diff --git a/lib/sysfs.c b/lib/sysfs.c index 759d97be6..8417d2d76 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -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'; diff --git a/libblkid/src/devno.c b/libblkid/src/devno.c index f4a36e4f5..3c082271b 100644 --- a/libblkid/src/devno.c +++ b/libblkid/src/devno.c @@ -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); diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index 1b4ffc128..d826c778f 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -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); } |