btrfs-progs: fix improper return value check for is_existing_blk_or_reg_file
The function @is_existing_blk_or_reg_file has a return value of -errno, which indicate the @stat call fails with non-ENOENT errors. In this condition, we should not continue the following work. But -errno evaluates to true and will let the following work go. So we should judge more accurately whether the return value of @is_existing_blk_or_reg_file is > 0 or not to decide our behavior. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
This commit is contained in:
parent
508e9ac827
commit
eb39e765f1
19
utils.c
19
utils.c
|
@ -1563,22 +1563,29 @@ int get_label(const char *btrfs_dev, char *label)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (is_existing_blk_or_reg_file(btrfs_dev))
|
ret = is_existing_blk_or_reg_file(btrfs_dev);
|
||||||
ret = get_label_unmounted(btrfs_dev, label);
|
if (!ret)
|
||||||
else
|
|
||||||
ret = get_label_mounted(btrfs_dev, label);
|
ret = get_label_mounted(btrfs_dev, label);
|
||||||
|
else if (ret > 0)
|
||||||
|
ret = get_label_unmounted(btrfs_dev, label);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int set_label(const char *btrfs_dev, const char *label)
|
int set_label(const char *btrfs_dev, const char *label)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (check_label(label))
|
if (check_label(label))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return is_existing_blk_or_reg_file(btrfs_dev) ?
|
ret = is_existing_blk_or_reg_file(btrfs_dev);
|
||||||
set_label_unmounted(btrfs_dev, label) :
|
if (!ret)
|
||||||
set_label_mounted(btrfs_dev, label);
|
ret = set_label_mounted(btrfs_dev, label);
|
||||||
|
else if (ret > 0)
|
||||||
|
ret = set_label_unmounted(btrfs_dev, label);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int btrfs_scan_block_devices(int run_ioctl)
|
int btrfs_scan_block_devices(int run_ioctl)
|
||||||
|
|
Loading…
Reference in New Issue