Skip to content

Commit 76c0446

Browse files
committed
btrfs-progs: mkfs: convert int to bool in a few helpers
Signed-off-by: David Sterba <[email protected]>
1 parent b06fe85 commit 76c0446

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

mkfs/common.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ static int check_overwrite(const char *device)
10671067
* 1: something is wrong, an error is printed
10681068
* 0: all is fine
10691069
*/
1070-
int test_dev_for_mkfs(const char *file, int force_overwrite)
1070+
bool test_dev_for_mkfs(const char *file, int force_overwrite)
10711071
{
10721072
int ret, fd;
10731073
struct stat st;
@@ -1076,64 +1076,64 @@ int test_dev_for_mkfs(const char *file, int force_overwrite)
10761076
if (ret < 0) {
10771077
errno = -ret;
10781078
error("checking status of %s: %m", file);
1079-
return 1;
1079+
return true;
10801080
}
10811081
if (ret == 1) {
10821082
error("%s is a swap device", file);
1083-
return 1;
1083+
return true;
10841084
}
10851085
ret = test_status_for_mkfs(file, force_overwrite);
10861086
if (ret)
1087-
return 1;
1087+
return true;
10881088
/*
10891089
* Check if the device is busy. Open it in read-only mode to avoid triggering
10901090
* udev events.
10911091
*/
10921092
fd = open(file, O_RDONLY | O_EXCL);
10931093
if (fd < 0) {
10941094
error("unable to open %s: %m", file);
1095-
return 1;
1095+
return true;
10961096
}
10971097
if (fstat(fd, &st)) {
10981098
error("unable to stat %s: %m", file);
10991099
close(fd);
1100-
return 1;
1100+
return true;
11011101
}
11021102
if (!S_ISBLK(st.st_mode)) {
11031103
error("%s is not a block device", file);
11041104
close(fd);
1105-
return 1;
1105+
return true;
11061106
}
11071107
close(fd);
1108-
return 0;
1108+
return false;
11091109
}
11101110

11111111
/*
11121112
* check if the file (device) is formatted or mounted
11131113
*/
1114-
int test_status_for_mkfs(const char *file, bool force_overwrite)
1114+
bool test_status_for_mkfs(const char *file, bool force_overwrite)
11151115
{
11161116
int ret;
11171117

11181118
if (!force_overwrite) {
11191119
if (check_overwrite(file)) {
11201120
error("use the -f option to force overwrite of %s",
11211121
file);
1122-
return 1;
1122+
return true;
11231123
}
11241124
}
11251125
ret = check_mounted(file);
11261126
if (ret < 0) {
11271127
errno = -ret;
11281128
error("cannot check mount status of %s: %m", file);
1129-
return 1;
1129+
return true;
11301130
}
11311131
if (ret == 1) {
11321132
error("%s is mounted", file);
1133-
return 1;
1133+
return true;
11341134
}
11351135

1136-
return 0;
1136+
return false;
11371137
}
11381138

11391139
int is_vol_small(const char *file)

mkfs/common.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ int test_minimum_size(const char *file, u64 min_dev_size);
106106
int is_vol_small(const char *file);
107107
int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
108108
u64 dev_cnt, int mixed, int ssd);
109-
int test_status_for_mkfs(const char *file, bool force_overwrite);
110-
int test_dev_for_mkfs(const char *file, int force_overwrite);
109+
bool test_status_for_mkfs(const char *file, bool force_overwrite);
110+
bool test_dev_for_mkfs(const char *file, int force_overwrite);
111111

112112
#endif

mkfs/main.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -507,10 +507,10 @@ static void list_all_devices(struct btrfs_root *root)
507507
printf("\n");
508508
}
509509

510-
static int is_temp_block_group(struct extent_buffer *node,
511-
struct btrfs_block_group_item *bgi,
512-
u64 data_profile, u64 meta_profile,
513-
u64 sys_profile)
510+
static bool is_temp_block_group(struct extent_buffer *node,
511+
struct btrfs_block_group_item *bgi,
512+
u64 data_profile, u64 meta_profile,
513+
u64 sys_profile)
514514
{
515515
u64 flag = btrfs_block_group_flags(node, bgi);
516516
u64 flag_type = flag & BTRFS_BLOCK_GROUP_TYPE_MASK;
@@ -537,26 +537,26 @@ static int is_temp_block_group(struct extent_buffer *node,
537537
* So only use condition 1) and 2) to judge them.
538538
*/
539539
if (used != 0)
540-
return 0;
540+
return false;
541541
switch (flag_type) {
542542
case BTRFS_BLOCK_GROUP_DATA:
543543
case BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_METADATA:
544544
data_profile &= BTRFS_BLOCK_GROUP_PROFILE_MASK;
545545
if (flag_profile != data_profile)
546-
return 1;
546+
return true;
547547
break;
548548
case BTRFS_BLOCK_GROUP_METADATA:
549549
meta_profile &= BTRFS_BLOCK_GROUP_PROFILE_MASK;
550550
if (flag_profile != meta_profile)
551-
return 1;
551+
return true;
552552
break;
553553
case BTRFS_BLOCK_GROUP_SYSTEM:
554554
sys_profile &= BTRFS_BLOCK_GROUP_PROFILE_MASK;
555555
if (flag_profile != sys_profile)
556-
return 1;
556+
return true;
557557
break;
558558
}
559-
return 0;
559+
return false;
560560
}
561561

562562
/* Note: if current is a block group, it will skip it anyway */

0 commit comments

Comments
 (0)