]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsblk: use internally sysfs devnames
authorKarel Zak <kzak@redhat.com>
Fri, 29 May 2015 08:55:01 +0000 (10:55 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 29 May 2015 08:55:01 +0000 (10:55 +0200)
It seems better to keep the strange sysfs devnames internally and
translate to real devnames only on output or when we read from /dev.

Signed-off-by: Karel Zak <kzak@redhat.com>
lib/sysfs.c
misc-utils/lsblk.c

index 1ea2e779a1a36e4072e67af6079ea8e35a626933..07b6b56cba3a78021caac567933acab1ca5a95ab 100644 (file)
@@ -69,9 +69,11 @@ dev_t sysfs_devname_to_devno(const char *name, const char *parent)
                char *_name = strdup(name), *_parent = strdup(parent);
                int len;
 
-               if (!_name || !_parent)
+               if (!_name || !_parent) {
+                       free(_name);
+                       free(_parent);
                        return 0;
-
+               }
                sysfs_devname_dev_to_sys(_name);
                sysfs_devname_dev_to_sys(_parent);
 
index c98e28a0e8fe92e49b55a668878aef64b27520d4..37fbb9af2d83f632671153cb886b314c9812cd4e 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_sys_to_dev(path);
        return xstrdup(path);
 }
 
@@ -790,6 +791,8 @@ static char *mk_name(const char *name)
                xasprintf(&p, "/dev/%s", name);
        else
                p = xstrdup(name);
+       if (p)
+               sysfs_devname_sys_to_dev(p);
        return p;
 }
 
@@ -1152,9 +1155,6 @@ static int set_cxt(struct blkdev_cxt *cxt,
        cxt->name = xstrdup(name);
        cxt->partition = wholedisk != NULL;
 
-       /* make sure that the name is usable in paths */
-       sysfs_devname_sys_to_dev(cxt->name);
-
        cxt->filename = get_device_path(cxt);
        if (!cxt->filename) {
                warnx(_("%s: failed to get device path"), cxt->name);
@@ -1207,8 +1207,7 @@ static int set_cxt(struct blkdev_cxt *cxt,
                }
        }
 
-       /* use "name" (sysfs-like name) here */
-       cxt->npartitions = sysfs_count_partitions(&cxt->sysfs, name);
+       cxt->npartitions = sysfs_count_partitions(&cxt->sysfs, cxt->name);
        cxt->nholders = sysfs_count_dirents(&cxt->sysfs, "holders");
        cxt->nslaves = sysfs_count_dirents(&cxt->sysfs, "slaves");