]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsblk: use sysfs_blkdev_is_removable()
authorKarel Zak <kzak@redhat.com>
Tue, 24 Jan 2023 16:38:49 +0000 (17:38 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 24 Jan 2023 16:38:49 +0000 (17:38 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/lsblk.c

index cbe307a74b7e8d2287c9da73dbe65da903fa4c21..fae918bd3f4fc5e37559f36590875db115dff7d8 100644 (file)
@@ -703,21 +703,20 @@ static int is_removable_device(struct lsblk_device *dev, struct lsblk_device *pa
 
        if (dev->removable != -1)
                goto done;
-       if (ul_path_scanf(dev->sysfs, "removable", "%d", &dev->removable) == 1)
-               goto done;
 
-       if (parent) {
+       dev->removable = sysfs_blkdev_is_removable(dev->sysfs);
+
+       if (!dev->removable && parent) {
                pc = sysfs_blkdev_get_parent(dev->sysfs);
                if (!pc)
                        goto done;
 
-               /* dev is partition and parent is whole-disk  */
                if (pc == parent->sysfs)
+                       /* dev is partition and parent is whole-disk  */
                        dev->removable = is_removable_device(parent, NULL);
-
-               /* parent is something else, use sysfs parent */
-               else if (ul_path_scanf(pc, "removable", "%d", &dev->removable) != 1)
-                       dev->removable = 0;
+               else
+                       /* parent is something else, use sysfs parent */
+                       dev->removable = sysfs_blkdev_is_removable(pc);
        }
 done:
        if (dev->removable == -1)