btrfs-progs: fix is_block_device() return checks

it was highlighted to me is_block_device(), returns
 1 if the file is a block device,
 < 0 in case of an error (eg: file not found)
 0 otherwise

This patch makes proper return checks at all the places
where is_block_device() is used. Thanks to Goffredo.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Suggested-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Anand Jain 2015-08-28 22:11:30 +08:00 committed by David Sterba
parent 5e561cef1d
commit 54fdddfdc1
3 changed files with 10 additions and 9 deletions

View File

@ -163,7 +163,7 @@ static int _cmd_device_remove(int argc, char **argv,
struct btrfs_ioctl_vol_args arg; struct btrfs_ioctl_vol_args arg;
int res; int res;
if (!is_block_device(argv[i])) { if (is_block_device(argv[i]) != 1) {
fprintf(stderr, fprintf(stderr,
"ERROR: %s is not a block device\n", argv[i]); "ERROR: %s is not a block device\n", argv[i]);
ret++; ret++;
@ -264,7 +264,7 @@ static int cmd_device_scan(int argc, char **argv)
for( i = devstart ; i < argc ; i++ ){ for( i = devstart ; i < argc ; i++ ){
char *path; char *path;
if (!is_block_device(argv[i])) { if (is_block_device(argv[i]) != 1) {
fprintf(stderr, fprintf(stderr,
"ERROR: %s is not a block device\n", argv[i]); "ERROR: %s is not a block device\n", argv[i]);
ret = 1; ret = 1;
@ -323,7 +323,7 @@ static int cmd_device_ready(int argc, char **argv)
goto out; goto out;
} }
if (!is_block_device(path)) { if (is_block_device(path) != 1) {
fprintf(stderr, fprintf(stderr,
"ERROR: %s is not a block device\n", path); "ERROR: %s is not a block device\n", path);
ret = 1; ret = 1;

6
mkfs.c
View File

@ -1494,7 +1494,7 @@ int main(int ac, char **av)
while (dev_cnt-- > 0) { while (dev_cnt-- > 0) {
file = av[optind++]; file = av[optind++];
if (is_block_device(file)) if (is_block_device(file) == 1)
if (test_dev_for_mkfs(file, force_overwrite)) if (test_dev_for_mkfs(file, force_overwrite))
exit(1); exit(1);
} }
@ -1718,7 +1718,7 @@ int main(int ac, char **av)
exit(1); exit(1);
} }
if (is_block_device(file)) if (is_block_device(file) == 1)
btrfs_register_one_device(file); btrfs_register_one_device(file);
if (dev_cnt == 0) if (dev_cnt == 0)
@ -1768,7 +1768,7 @@ int main(int ac, char **av)
(unsigned long long)device->devid); (unsigned long long)device->devid);
} }
if (is_block_device(file)) if (is_block_device(file) == 1)
btrfs_register_one_device(file); btrfs_register_one_device(file);
} }

View File

@ -1086,7 +1086,8 @@ int open_path_or_dev_mnt(const char *path, DIR **dirstream)
char mp[PATH_MAX]; char mp[PATH_MAX];
int fdmnt; int fdmnt;
if (is_block_device(path)) { fdmnt = is_block_device(path);
if (fdmnt == 1) {
int ret; int ret;
ret = get_btrfs_mount(path, mp, sizeof(mp)); ret = get_btrfs_mount(path, mp, sizeof(mp));
@ -1096,7 +1097,7 @@ int open_path_or_dev_mnt(const char *path, DIR **dirstream)
return -1; return -1;
} }
fdmnt = open_file_or_dir(mp, dirstream); fdmnt = open_file_or_dir(mp, dirstream);
} else { } else if (fdmnt == 0) {
fdmnt = open_file_or_dir(path, dirstream); fdmnt = open_file_or_dir(path, dirstream);
} }
@ -2138,7 +2139,7 @@ int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args,
memset(fi_args, 0, sizeof(*fi_args)); memset(fi_args, 0, sizeof(*fi_args));
if (is_block_device(path)) { if (is_block_device(path) == 1) {
struct btrfs_super_block *disk_super; struct btrfs_super_block *disk_super;
char buf[BTRFS_SUPER_INFO_SIZE]; char buf[BTRFS_SUPER_INFO_SIZE];
u64 devid; u64 devid;