Skip to content

Commit

Permalink
btrfs-progs: mkfs: convert int to bool in a few helpers
Browse files Browse the repository at this point in the history
Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
kdave committed Jul 27, 2023
1 parent b06fe85 commit 76c0446
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
26 changes: 13 additions & 13 deletions mkfs/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ static int check_overwrite(const char *device)
* 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;
Expand All @@ -1076,64 +1076,64 @@ 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.
*/
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;

if (!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)
Expand Down
4 changes: 2 additions & 2 deletions mkfs/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 9 additions & 9 deletions mkfs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 */
Expand Down

0 comments on commit 76c0446

Please sign in to comment.