mirror of
https://github.com/kdave/btrfs-progs
synced 2025-01-30 09:21:45 +00:00
btrfs-progs: mkfs: convert int to bool in a few helpers
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
b06fe85011
commit
76c0446bec
@ -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)
|
||||
|
@ -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
|
||||
|
12
mkfs/main.c
12
mkfs/main.c
@ -507,7 +507,7 @@ static void list_all_devices(struct btrfs_root *root)
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static int is_temp_block_group(struct extent_buffer *node,
|
||||
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)
|
||||
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user