From: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH] Btrfs-progs: add sanity checks for btrfs device operations
Date: Thu, 12 Dec 2013 15:47:00 +0800 [thread overview]
Message-ID: <1386834420-1007-1-git-send-email-wangsl.fnst@cn.fujitsu.com> (raw)
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>
---
cmds-device.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/cmds-device.c b/cmds-device.c
index bc4a8dc..ea20919 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);
--
1.8.3.1
reply other threads:[~2013-12-12 7:47 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1386834420-1007-1-git-send-email-wangsl.fnst@cn.fujitsu.com \
--to=wangsl.fnst@cn.fujitsu.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).