summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2015-10-02 17:44:21 +0200
committerDavid Sterba <dsterba@suse.com>2015-10-02 17:56:43 +0200
commit49ac9aa1e8185f84c00e9ae1ce12b290c2df2830 (patch)
treecf23fa4346699458454177c3218268d284765697
parent1491d246c427f4fe13521b13fab64c91459ffd9e (diff)
btrfs-progs: fix error checking in load_device_info
load_device_info queries the FS_INFO ioctl and this may fail with EPERM on older kernels. The check did not verify the ioctl return value and incorrectly returned EPERM if it was previously stored in errno. This fixes 'btrfs fi usage' that will print the overall summary for all users (provided that the FS_INFO ioctl is already unprivileged). Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--cmds-fi-usage.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/cmds-fi-usage.c b/cmds-fi-usage.c
index 54b8b1c1..50d63337 100644
--- a/cmds-fi-usage.c
+++ b/cmds-fi-usage.c
@@ -504,7 +504,7 @@ static int cmp_device_info(const void *a, const void *b)
static int load_device_info(int fd, struct device_info **device_info_ptr,
int *device_info_count)
{
- int ret, i, ndevs, e;
+ int ret, i, ndevs;
struct btrfs_ioctl_fs_info_args fi_args;
struct btrfs_ioctl_dev_info_args dev_info;
struct device_info *info;
@@ -513,12 +513,11 @@ static int load_device_info(int fd, struct device_info **device_info_ptr,
*device_info_ptr = 0;
ret = ioctl(fd, BTRFS_IOC_FS_INFO, &fi_args);
- e = errno;
- if (e == EPERM)
- return -e;
if (ret < 0) {
+ if (errno == EPERM)
+ return -errno;
fprintf(stderr, "ERROR: cannot get filesystem info - %s\n",
- strerror(e));
+ strerror(errno));
return 1;
}