summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorAnand Jain <anand.jain@oracle.com>2013-07-26 01:35:27 +0800
committerDavid Sterba <dsterba@suse.cz>2013-09-03 19:40:51 +0200
commit689ad3e362c1e6d54ef7b6876dbb64e1e51b8cf1 (patch)
tree2aafcf343e9de147cf42d92d8dbb07a85a0816e8 /utils.c
parentbbe9df154b2c9bc122e1099382d1658c8cf0e904 (diff)
btrfs-progs: cmd_start_replace() to use test_dev_for_mkfs()
test_dev_for_mkfs() is a common place where we check if a device is fit for the btrfs use. cmd_start_replace() should make use of test_dev_for_mkfs(), and here the test_dev_for_mkfs() is further enhanced to fit the cmd_start_replace() needs. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/utils.c b/utils.c
index 15b991ff..c1469a9b 100644
--- a/utils.c
+++ b/utils.c
@@ -1807,6 +1807,7 @@ int test_dev_for_mkfs(char *file, int force_overwrite, char *estr)
{
int ret, fd;
size_t sz = 100;
+ struct stat st;
ret = is_swap_device(file);
if (ret < 0) {
@@ -1841,6 +1842,15 @@ int test_dev_for_mkfs(char *file, int force_overwrite, char *estr)
strerror(errno));
return 1;
}
+ if (fstat(fd, &st)) {
+ snprintf(estr, sz, "unable to stat %s: %s\n", file,
+ strerror(errno));
+ return 1;
+ }
+ if (!S_ISBLK(st.st_mode)) {
+ fprintf(stderr, "'%s' is not a block device\n", file);
+ return 1;
+ }
close(fd);
return 0;
}