aboutsummaryrefslogtreecommitdiffstats
path: root/cmds-device.c
diff options
context:
space:
mode:
authorZhao Lei <zhaolei@cn.fujitsu.com>2015-08-26 17:04:23 +0800
committerDavid Sterba <dsterba@suse.com>2015-08-31 19:25:14 +0200
commitabe48ca8600be7c8a7ec3c018b449ad3bd56c7a4 (patch)
tree90c49ec2b442d4dc6d27c19d478a6cb819e12b81 /cmds-device.c
parent87c25626c4bef0700c4b165ddc128061ea31bd58 (diff)
downloadbtrfs-progs-abe48ca8600be7c8a7ec3c018b449ad3bd56c7a4.tar.gz
btrfs-progs-abe48ca8600be7c8a7ec3c018b449ad3bd56c7a4.tar.xz
btrfs-progs-abe48ca8600be7c8a7ec3c018b449ad3bd56c7a4.zip
btrfs-progs: use btrfs_open_dir for btrfs device command
We can use btrfs_open_dir() to check whether the target dir is under btrfs mount point before openning, instead of checking it in kernel through ioctl, and returning a fuzzy error message. Before patch: # (/mnt/tmp is not btrfs mountpoint) # # btrfs device add -f /dev/sda13 /mnt/tmp ERROR: error adding the device '/dev/sda13' - Inappropriate ioctl for device # After patch: # btrfs device add -f /dev/sda13 /mnt/tmp ERROR: not btrfs filesystem: /mnt/tmp # Similar fix for device remove and device usage. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> [renamed to btrfs_open_dir] Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'cmds-device.c')
-rw-r--r--cmds-device.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/cmds-device.c b/cmds-device.c
index 8e69b88..844289a 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -84,11 +84,9 @@ static int cmd_device_add(int argc, char **argv)
mntpnt = argv[optind + argc - 1];
- fdmnt = open_file_or_dir(mntpnt, &dirstream);
- if (fdmnt < 0) {
- fprintf(stderr, "ERROR: can't access '%s'\n", mntpnt);
+ fdmnt = btrfs_open_dir(mntpnt, &dirstream, 1);
+ if (fdmnt < 0)
return 1;
- }
for (i = optind; i < optind + argc - 1; i++){
struct btrfs_ioctl_vol_args ioctl_args;
@@ -157,11 +155,9 @@ static int _cmd_device_remove(int argc, char **argv,
mntpnt = argv[argc - 1];
- fdmnt = open_file_or_dir(mntpnt, &dirstream);
- if (fdmnt < 0) {
- fprintf(stderr, "ERROR: can't access '%s'\n", mntpnt);
+ fdmnt = btrfs_open_dir(mntpnt, &dirstream, 1);
+ if (fdmnt < 0)
return 1;
- }
for(i=1 ; i < argc - 1; i++ ){
struct btrfs_ioctl_vol_args arg;
@@ -588,10 +584,8 @@ int cmd_device_usage(int argc, char **argv)
if (more_than_one)
printf("\n");
- fd = open_file_or_dir(argv[i], &dirstream);
+ fd = btrfs_open_dir(argv[i], &dirstream, 1);
if (fd < 0) {
- fprintf(stderr, "ERROR: can't access '%s'\n",
- argv[1]);
ret = 1;
goto out;
}