diff options
author | Anand Jain <anand.jain@oracle.com> | 2015-09-15 16:46:22 +0800 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2015-10-02 17:52:10 +0200 |
commit | 94789777b9e8f350ba815b07baa5383e99cd1944 (patch) | |
tree | c7874b6f83c52ecbac8dd8f9747004963004ae20 /utils.c | |
parent | 3276a9f519155486383e20958e0c5eb55d4c0b4f (diff) | |
download | btrfs-progs-94789777b9e8f350ba815b07baa5383e99cd1944.tar.gz |
btrfs-progs: provide fail safe for BTRFS_IOC_GET_FSLABEL ioctl
Old kernels before 3.9 do not provide ioctl BTRFS_IOC_GET_FSLABEL.
So we need to provide a fail safe logic for btrfs-progs running
on those kernel.
In this patch when get_label_mounted() fails on the old kernel
it will fail back to the old method and uses get_label_unmounted(),
where it will read from the disk directly.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -1740,7 +1740,7 @@ static int set_label_mounted(const char *mount_path, const char *label) return 0; } -static int get_label_unmounted(const char *dev, char *label) +int get_label_unmounted(const char *dev, char *label) { struct btrfs_root *root; int ret; @@ -1750,11 +1750,6 @@ static int get_label_unmounted(const char *dev, char *label) fprintf(stderr, "FATAL: error checking %s mount status\n", dev); return -1; } - if (ret > 0) { - fprintf(stderr, "ERROR: dev %s is mounted, use mount point\n", - dev); - return -1; - } /* Open the super_block at the default location * and as read-only. @@ -1779,6 +1774,7 @@ int get_label_mounted(const char *mount_path, char *labelp) { char label[BTRFS_LABEL_SIZE]; int fd; + int ret; fd = open(mount_path, O_RDONLY | O_NOATIME); if (fd < 0) { @@ -1787,10 +1783,14 @@ int get_label_mounted(const char *mount_path, char *labelp) } memset(label, '\0', sizeof(label)); - if (ioctl(fd, BTRFS_IOC_GET_FSLABEL, label) < 0) { - fprintf(stderr, "ERROR: unable get label %s\n", strerror(errno)); + ret = ioctl(fd, BTRFS_IOC_GET_FSLABEL, label); + if (ret < 0) { + if (errno != ENOTTY) + fprintf(stderr, "ERROR: unable to get label %s\n", + strerror(errno)); + ret = -errno; close(fd); - return -1; + return ret; } strncpy(labelp, label, sizeof(label)); |