diff options
author | Wang Shilong <wangsl.fnst@cn.fujitsu.com> | 2013-12-12 15:47:00 +0800 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2014-01-31 08:22:17 -0800 |
commit | e3c9596d3fc8b0df647a6cbae55c2d77570de759 (patch) | |
tree | 0a774b0b0ebe339b78ff0b1f1a329678ee7d63c1 | |
parent | fd777c3695727e03b0ba46e5577240bee86024b0 (diff) |
Btrfs-progs: add sanity checks for btrfs device operations
Make sure we are a block device firstly, this can avoid some
unnecessary ioctls operations.
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
-rw-r--r-- | cmds-device.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/cmds-device.c b/cmds-device.c index bc4a8dcd..ea20919e 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -161,6 +161,12 @@ static int cmd_rm_dev(int argc, char **argv) struct btrfs_ioctl_vol_args arg; int res; + if (!is_block_device(argv[i])) { + fprintf(stderr, + "ERROR: %s is not a block device\n", argv[i]); + ret++; + continue; + } strncpy_null(arg.name, argv[i]); res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg); e = errno; @@ -222,6 +228,12 @@ static int cmd_scan_dev(int argc, char **argv) struct btrfs_ioctl_vol_args args; int ret; + if (!is_block_device(argv[i])) { + fprintf(stderr, + "ERROR: %s is not a block device\n", argv[i]); + close(fd); + return 1; + } printf("Scanning for Btrfs filesystems in '%s'\n", argv[i]); strncpy_null(args.name, argv[i]); @@ -265,6 +277,12 @@ static int cmd_ready_dev(int argc, char **argv) perror("failed to open /dev/btrfs-control"); return 1; } + if (!is_block_device(argv[1])) { + fprintf(stderr, + "ERROR: %s is not a block device\n", argv[1]); + close(fd); + return 1; + } strncpy(args.name, argv[argc - 1], BTRFS_PATH_NAME_MAX); ret = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args); |