]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
blockdev: use new ul_path_* API
authorKarel Zak <kzak@redhat.com>
Wed, 30 May 2018 09:24:40 +0000 (11:24 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 21 Jun 2018 11:19:28 +0000 (13:19 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/blockdev.c

index f1ea53347ff290eb8dd0c46cd20380523a92e32b..5122460f0947d065e65c9ae0f18901f9f24a16a5 100644 (file)
@@ -468,18 +468,21 @@ static void report_device(char *device, int quiet)
 
        ro = ssz = bsz = 0;
        ra = 0;
-       if (fstat(fd, &st) == 0 && !sysfs_devno_is_wholedisk(st.st_rdev)) {
-               struct sysfs_cxt cxt;
-
-               if (sysfs_init(&cxt, st.st_rdev, NULL))
-                       err(EXIT_FAILURE,
-                               _("%s: failed to initialize sysfs handler"),
-                               device);
-               if (sysfs_read_u64(&cxt, "start", &start))
-                       err(EXIT_FAILURE,
-                               _("%s: failed to read partition start from sysfs"),
-                               device);
-               sysfs_deinit(&cxt);
+       if (fstat(fd, &st) == 0) {
+               dev_t disk;
+               struct path_cxt *pc;
+
+               pc = ul_new_sysfs_path(st.st_rdev, NULL, NULL);
+               if (pc &&
+                   sysfs_blkdev_get_wholedisk(pc, NULL, 0, &disk) == 0 &&
+                   disk != st.st_rdev) {
+
+                       if (ul_path_read_u64(pc, &start, "start") != 0)
+                               err(EXIT_FAILURE,
+                                       _("%s: failed to read partition start from sysfs"),
+                                       device);
+               }
+               ul_unref_path(pc);
        }
        if (ioctl(fd, BLKROGET, &ro) == 0 &&
            ioctl(fd, BLKRAGET, &ra) == 0 &&