]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
loopdev: Properly translate errors from ul_path_read_*()
authorJan Kara <jack@suse.cz>
Thu, 20 Jan 2022 12:16:38 +0000 (13:16 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 25 Jan 2022 16:15:58 +0000 (17:15 +0100)
A few callsites do not translate error from ul_path_read_*() and just
treat it as error code leading to confusing EPERM errors.

Signed-off-by: Jan Kara <jack@suse.cz>
lib/loopdev.c

index b5da1516e37fc1a63a04d9574dfb66f33b607e9c..27ab06c668487c9cd879d34eea9977a88574aa80 100644 (file)
@@ -739,7 +739,8 @@ int loopcxt_get_offset(struct loopdev_cxt *lc, uint64_t *offset)
        int rc = -EINVAL;
 
        if (sysfs)
-               rc = ul_path_read_u64(sysfs, offset, "loop/offset");
+               if (ul_path_read_u64(sysfs, offset, "loop/offset") == 0)
+                       rc = 0;
 
        if (rc && loopcxt_ioctl_enabled(lc)) {
                struct loop_info64 *lo = loopcxt_get_info(lc);
@@ -767,7 +768,8 @@ int loopcxt_get_blocksize(struct loopdev_cxt *lc, uint64_t *blocksize)
        int rc = -EINVAL;
 
        if (sysfs)
-               rc = ul_path_read_u64(sysfs, blocksize, "queue/logical_block_size");
+               if (ul_path_read_u64(sysfs, blocksize, "queue/logical_block_size") == 0)
+                       rc = 0;
 
        /* Fallback based on BLKSSZGET ioctl */
        if (rc) {
@@ -799,7 +801,8 @@ int loopcxt_get_sizelimit(struct loopdev_cxt *lc, uint64_t *size)
        int rc = -EINVAL;
 
        if (sysfs)
-               rc = ul_path_read_u64(sysfs, size, "loop/sizelimit");
+               if (ul_path_read_u64(sysfs, size, "loop/sizelimit") == 0)
+                       rc = 0;
 
        if (rc && loopcxt_ioctl_enabled(lc)) {
                struct loop_info64 *lo = loopcxt_get_info(lc);