Skip to content

Commit 64fddab

Browse files
Wang Shilongmasoncl
Wang Shilong
authored andcommitted
Btrfs-progs: switch to arg_strtou64() part3
Switch to new helper arg_strtou64(), also check if user assign a valid super copy. Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
1 parent 86da12f commit 64fddab

6 files changed

+29
-26
lines changed

btrfs-select-super.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int main(int ac, char **av)
4343
{
4444
struct btrfs_root *root;
4545
int ret;
46-
int num = 0;
46+
u64 num = 0;
4747
u64 bytenr = 0;
4848

4949
while(1) {
@@ -53,8 +53,14 @@ int main(int ac, char **av)
5353
break;
5454
switch(c) {
5555
case 's':
56-
num = atol(optarg);
57-
bytenr = btrfs_sb_offset(num);
56+
num = arg_strtou64(optarg);
57+
if (num >= BTRFS_SUPER_MIRROR_MAX) {
58+
fprintf(stderr,
59+
"ERROR: super mirror should be less than: %d\n",
60+
BTRFS_SUPER_MIRROR_MAX);
61+
exit(1);
62+
}
63+
bytenr = btrfs_sb_offset(((int)num));
5864
break;
5965
default:
6066
print_usage();

btrfs-show-super.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ int main(int argc, char **argv)
5959
int all = 0;
6060
char *filename;
6161
int fd = -1;
62-
int arg, i;
62+
int i;
63+
u64 arg;
6364
u64 sb_bytenr = btrfs_sb_offset(0);
6465

6566
while ((opt = getopt(argc, argv, "ai:")) != -1) {
6667
switch (opt) {
6768
case 'i':
68-
arg = atoi(optarg);
69-
70-
if (arg < 0 || arg >= BTRFS_SUPER_MIRROR_MAX) {
69+
arg = arg_strtou64(optarg);
70+
if (arg >= BTRFS_SUPER_MIRROR_MAX) {
7171
fprintf(stderr,
72-
"Illegal super_mirror %d\n",
72+
"Illegal super_mirror %llu\n",
7373
arg);
7474
print_usage();
7575
exit(1);

btrfstune.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ int main(int argc, char *argv[])
111111
int success = 0;
112112
int extrefs_flag = 0;
113113
int seeding_flag = 0;
114-
int seeding_value = 0;
114+
u64 seeding_value = 0;
115115
int skinny_flag = 0;
116116
int ret;
117117

@@ -123,7 +123,7 @@ int main(int argc, char *argv[])
123123
switch(c) {
124124
case 'S':
125125
seeding_flag = 1;
126-
seeding_value = atoi(optarg);
126+
seeding_value = arg_strtou64(optarg);
127127
break;
128128
case 'r':
129129
extrefs_flag = 1;

cmds-check.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -6388,7 +6388,7 @@ int cmd_check(int argc, char **argv)
63886388
u64 bytenr = 0;
63896389
char uuidbuf[BTRFS_UUID_UNPARSED_SIZE];
63906390
int ret;
6391-
int num;
6391+
u64 num;
63926392
int option_index = 0;
63936393
int init_csum_tree = 0;
63946394
int init_extent_tree = 0;
@@ -6407,9 +6407,15 @@ int cmd_check(int argc, char **argv)
64076407
ctree_flags |= OPEN_CTREE_BACKUP_ROOT;
64086408
break;
64096409
case 's':
6410-
num = atol(optarg);
6411-
bytenr = btrfs_sb_offset(num);
6412-
printf("using SB copy %d, bytenr %llu\n", num,
6410+
num = arg_strtou64(optarg);
6411+
if (num >= BTRFS_SUPER_MIRROR_MAX) {
6412+
fprintf(stderr,
6413+
"ERROR: super mirror should be less than: %d\n",
6414+
BTRFS_SUPER_MIRROR_MAX);
6415+
exit(1);
6416+
}
6417+
bytenr = btrfs_sb_offset(((int)num));
6418+
printf("using SB copy %llu, bytenr %llu\n", num,
64136419
(unsigned long long)bytenr);
64146420
break;
64156421
case '?':

cmds-replace.c

+1-6
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,7 @@ static int cmd_start_replace(int argc, char **argv)
210210
struct btrfs_ioctl_fs_info_args fi_args;
211211
struct btrfs_ioctl_dev_info_args *di_args = NULL;
212212

213-
if (atoi(srcdev) == 0) {
214-
fprintf(stderr, "Error: Failed to parse the numerical devid value '%s'\n",
215-
srcdev);
216-
goto leave_with_error;
217-
}
218-
start_args.start.srcdevid = (__u64)atoi(srcdev);
213+
start_args.start.srcdevid = arg_strtou64(srcdev);
219214

220215
ret = get_fs_info(path, &fi_args, &di_args);
221216
if (ret) {

cmds-subvolume.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -820,11 +820,7 @@ static int cmd_subvol_set_default(int argc, char **argv)
820820
subvolid = argv[1];
821821
path = argv[2];
822822

823-
objectid = (unsigned long long)strtoll(subvolid, NULL, 0);
824-
if (errno == ERANGE) {
825-
fprintf(stderr, "ERROR: invalid tree id (%s)\n", subvolid);
826-
return 1;
827-
}
823+
objectid = arg_strtou64(subvolid);
828824

829825
fd = open_file_or_dir(path, &dirstream);
830826
if (fd < 0) {
@@ -861,7 +857,7 @@ static int cmd_find_new(int argc, char **argv)
861857
usage(cmd_find_new_usage);
862858

863859
subvol = argv[1];
864-
last_gen = atoll(argv[2]);
860+
last_gen = arg_strtou64(argv[2]);
865861

866862
ret = test_issubvolume(subvol);
867863
if (ret < 0) {

0 commit comments

Comments
 (0)