btrfs-progs: mkfs: convert int to bool in a few helpers

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2023-06-08 00:08:35 +02:00
parent b06fe85011
commit 76c0446bec
3 changed files with 24 additions and 24 deletions

View file

@ -1067,7 +1067,7 @@ out:
* 1: something is wrong, an error is printed
* 0: all is fine
*/
int test_dev_for_mkfs(const char *file, int force_overwrite)
bool test_dev_for_mkfs(const char *file, int force_overwrite)
{
int ret, fd;
struct stat st;
@ -1076,15 +1076,15 @@ int test_dev_for_mkfs(const char *file, int force_overwrite)
if (ret < 0) {
errno = -ret;
error("checking status of %s: %m", file);
return 1;
return true;
}
if (ret == 1) {
error("%s is a swap device", file);
return 1;
return true;
}
ret = test_status_for_mkfs(file, force_overwrite);
if (ret)
return 1;
return true;
/*
* Check if the device is busy. Open it in read-only mode to avoid triggering
* udev events.
@ -1092,26 +1092,26 @@ int test_dev_for_mkfs(const char *file, int force_overwrite)
fd = open(file, O_RDONLY | O_EXCL);
if (fd < 0) {
error("unable to open %s: %m", file);
return 1;
return true;
}
if (fstat(fd, &st)) {
error("unable to stat %s: %m", file);
close(fd);
return 1;
return true;
}
if (!S_ISBLK(st.st_mode)) {
error("%s is not a block device", file);
close(fd);
return 1;
return true;
}
close(fd);
return 0;
return false;
}
/*
* check if the file (device) is formatted or mounted
*/
int test_status_for_mkfs(const char *file, bool force_overwrite)
bool test_status_for_mkfs(const char *file, bool force_overwrite)
{
int ret;
@ -1119,21 +1119,21 @@ int test_status_for_mkfs(const char *file, bool force_overwrite)
if (check_overwrite(file)) {
error("use the -f option to force overwrite of %s",
file);
return 1;
return true;
}
}
ret = check_mounted(file);
if (ret < 0) {
errno = -ret;
error("cannot check mount status of %s: %m", file);
return 1;
return true;
}
if (ret == 1) {
error("%s is mounted", file);
return 1;
return true;
}
return 0;
return false;
}
int is_vol_small(const char *file)

View file

@ -106,7 +106,7 @@ int test_minimum_size(const char *file, u64 min_dev_size);
int is_vol_small(const char *file);
int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
u64 dev_cnt, int mixed, int ssd);
int test_status_for_mkfs(const char *file, bool force_overwrite);
int test_dev_for_mkfs(const char *file, int force_overwrite);
bool test_status_for_mkfs(const char *file, bool force_overwrite);
bool test_dev_for_mkfs(const char *file, int force_overwrite);
#endif

View file

@ -507,10 +507,10 @@ static void list_all_devices(struct btrfs_root *root)
printf("\n");
}
static int is_temp_block_group(struct extent_buffer *node,
struct btrfs_block_group_item *bgi,
u64 data_profile, u64 meta_profile,
u64 sys_profile)
static bool is_temp_block_group(struct extent_buffer *node,
struct btrfs_block_group_item *bgi,
u64 data_profile, u64 meta_profile,
u64 sys_profile)
{
u64 flag = btrfs_block_group_flags(node, bgi);
u64 flag_type = flag & BTRFS_BLOCK_GROUP_TYPE_MASK;
@ -537,26 +537,26 @@ static int is_temp_block_group(struct extent_buffer *node,
* So only use condition 1) and 2) to judge them.
*/
if (used != 0)
return 0;
return false;
switch (flag_type) {
case BTRFS_BLOCK_GROUP_DATA:
case BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_METADATA:
data_profile &= BTRFS_BLOCK_GROUP_PROFILE_MASK;
if (flag_profile != data_profile)
return 1;
return true;
break;
case BTRFS_BLOCK_GROUP_METADATA:
meta_profile &= BTRFS_BLOCK_GROUP_PROFILE_MASK;
if (flag_profile != meta_profile)
return 1;
return true;
break;
case BTRFS_BLOCK_GROUP_SYSTEM:
sys_profile &= BTRFS_BLOCK_GROUP_PROFILE_MASK;
if (flag_profile != sys_profile)
return 1;
return true;
break;
}
return 0;
return false;
}
/* Note: if current is a block group, it will skip it anyway */