diff options
Diffstat (limited to 'e2fsprogs')
-rw-r--r-- | e2fsprogs/mke2fs.c | 54 | ||||
-rw-r--r-- | e2fsprogs/tune2fs.c | 32 |
2 files changed, 27 insertions, 59 deletions
diff --git a/e2fsprogs/mke2fs.c b/e2fsprogs/mke2fs.c index 1c4f154..f25ecfb 100644 --- a/e2fsprogs/mke2fs.c +++ b/e2fsprogs/mke2fs.c @@ -673,7 +673,7 @@ static void show_stats(ext2_filsys fs) static int set_os(struct ext2_super_block *sb, char *os) { if (isdigit (*os)) { - sb->s_creator_os = atoi (os); + sb->s_creator_os = atoi(os); return 1; } @@ -790,7 +790,7 @@ static __u32 ok_features[3] = { static int PRS(int argc, char *argv[]) { - int b, c; + int c; int size; char * tmp; int blocksize = 0; @@ -848,54 +848,32 @@ static int PRS(int argc, char *argv[]) "b:cE:f:g:i:jl:m:no:qr:R:s:tvI:J:ST:FL:M:N:O:V")) != EOF) { switch (c) { case 'b': - if (safe_strtoi(optarg, &blocksize)) - goto BLOCKSIZE_ERROR; - b = (blocksize > 0) ? blocksize : -blocksize; - if (b < EXT2_MIN_BLOCK_SIZE || - b > EXT2_MAX_BLOCK_SIZE) { -BLOCKSIZE_ERROR: - bb_error_msg_and_die("invalid block size - %s", optarg); - } + blocksize = xatou_range(optarg, EXT2_MIN_BLOCK_SIZE, EXT2_MAX_BLOCK_SIZE); mke2fs_warning_msg((blocksize > 4096), "blocksize %d not usable on most systems", blocksize); - if (blocksize > 0) - param.s_log_block_size = - int_log2(blocksize >> - EXT2_MIN_BLOCK_LOG_SIZE); + param.s_log_block_size = + int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE); break; case 'c': /* Check for bad blocks */ case 't': /* deprecated */ cflag++; break; case 'f': - if (safe_strtoi(optarg, &size) || size < EXT2_MIN_BLOCK_SIZE || size > EXT2_MAX_BLOCK_SIZE ){ - bb_error_msg_and_die("invalid fragment size - %s", optarg); - } + size = xatou_range(optarg, EXT2_MIN_BLOCK_SIZE, EXT2_MAX_BLOCK_SIZE); param.s_log_frag_size = int_log2(size >> EXT2_MIN_BLOCK_LOG_SIZE); mke2fs_warning_msg(1, "fragments not supported. Ignoring -f option"); break; case 'g': - { - int foo; - if (safe_strtoi(optarg, &foo)) { - bb_error_msg_and_die("Illegal number for blocks per group"); - } - param.s_blocks_per_group = foo; - } + param.s_blocks_per_group = xatou32(optarg); if ((param.s_blocks_per_group % 8) != 0) { bb_error_msg_and_die("blocks per group must be multiple of 8"); } break; case 'i': - if (safe_strtoi(optarg, &inode_ratio) - || inode_ratio < EXT2_MIN_BLOCK_SIZE - || inode_ratio > EXT2_MAX_BLOCK_SIZE * 1024) { - bb_error_msg_and_die("invalid inode ratio %s (min %d/max %d)", - optarg, EXT2_MIN_BLOCK_SIZE, - EXT2_MAX_BLOCK_SIZE); - } + /* Huh? is "* 1024" correct? */ + inode_ratio = xatou_range(optarg, EXT2_MIN_BLOCK_SIZE, EXT2_MAX_BLOCK_SIZE * 1024); break; case 'J': parse_journal_opts(&journal_device, &journal_flags, &journal_size, optarg); @@ -910,9 +888,7 @@ BLOCKSIZE_ERROR: bad_blocks_filename = optarg; break; case 'm': - if (safe_strtoi(optarg, &reserved_ratio) || reserved_ratio > 50 ) { - bb_error_msg_and_die("invalid reserved blocks percent - %s", optarg); - } + reserved_ratio = xatou_range(optarg, 0, 50); break; case 'n': noaction++; @@ -921,7 +897,7 @@ BLOCKSIZE_ERROR: creator_os = optarg; break; case 'r': - param.s_rev_level = atoi(optarg); + param.s_rev_level = xatoi_u(optarg); if (param.s_rev_level == EXT2_GOOD_OLD_REV) { param.s_feature_incompat = 0; param.s_feature_compat = 0; @@ -929,7 +905,7 @@ BLOCKSIZE_ERROR: } break; case 's': /* deprecated */ - if (atoi(optarg)) + if (xatou(optarg)) param.s_feature_ro_compat |= EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; else @@ -938,13 +914,11 @@ BLOCKSIZE_ERROR: break; #ifdef EXT2_DYNAMIC_REV case 'I': - if (safe_strtoi(optarg, &inode_size)) { - bb_error_msg_and_die("invalid inode size - %s", optarg); - } + inode_size = xatoi_u(optarg); break; #endif case 'N': - num_inodes = atoi(optarg); + num_inodes = xatoi_u(optarg); break; case 'v': quiet = 0; diff --git a/e2fsprogs/tune2fs.c b/e2fsprogs/tune2fs.c index d22deed..c8dfc69 100644 --- a/e2fsprogs/tune2fs.c +++ b/e2fsprogs/tune2fs.c @@ -54,7 +54,8 @@ static int m_flag, M_flag, r_flag, s_flag = -1, u_flag, U_flag, T_flag; static time_t last_check_time; static int print_label; static int max_mount_count, mount_count, mount_flags; -static unsigned long interval, reserved_ratio, reserved_blocks; +static unsigned long interval, reserved_blocks; +static unsigned reserved_ratio; static unsigned long resgid, resuid; static unsigned short errors; static int open_flag; @@ -410,19 +411,14 @@ static void parse_tune2fs_options(int argc, char **argv) switch (c) { case 'c': - if (safe_strtoi(optarg, &max_mount_count) || max_mount_count > 16000) { - goto MOUNTS_COUNT_ERROR; - } + max_mount_count = xatou_range(optarg, 0, 16000); if (max_mount_count == 0) max_mount_count = -1; c_flag = 1; open_flag = EXT2_FLAG_RW; break; case 'C': - if (safe_strtoi(optarg, &mount_count) || mount_count > 16000) { -MOUNTS_COUNT_ERROR: - bb_error_msg_and_die("bad mounts count - %s", optarg); - } + mount_count = xatou_range(optarg, 0, 16000); C_flag = 1; open_flag = EXT2_FLAG_RW; break; @@ -443,13 +439,14 @@ MOUNTS_COUNT_ERROR: f_flag = 1; break; case 'g': - if (safe_strtoul(optarg, &resgid)) + resgid = bb_strtoul(optarg, NULL, 10); + if (errno) resgid = bb_xgetgrnam(optarg); g_flag = 1; open_flag = EXT2_FLAG_RW; break; case 'i': - interval = strtoul (optarg, &tmp, 0); + interval = strtoul(optarg, &tmp, 0); switch (*tmp) { case 's': tmp++; @@ -497,9 +494,7 @@ MOUNTS_COUNT_ERROR: EXT2_FLAG_JOURNAL_DEV_OK; break; case 'm': - if(safe_strtoul(optarg, &reserved_ratio) || reserved_ratio > 50) { - bb_error_msg_and_die("bad reserved block ratio - %s", optarg); - } + reserved_ratio = xatou_range(optarg, 0, 50); m_flag = 1; open_flag = EXT2_FLAG_RW; break; @@ -524,9 +519,7 @@ MOUNTS_COUNT_ERROR: open_flag = EXT2_FLAG_RW; break; case 'r': - if(safe_strtoul(optarg, &reserved_blocks)) { - bb_error_msg_and_die("bad reserved blocks count - %s", optarg); - } + reserved_blocks = xatoul(optarg); r_flag = 1; open_flag = EXT2_FLAG_RW; break; @@ -540,7 +533,8 @@ MOUNTS_COUNT_ERROR: open_flag = EXT2_FLAG_RW; break; case 'u': - if (safe_strtoul(optarg, &resuid)) + resuid = bb_strtoul(optarg, NULL, 10); + if (errno) resuid = bb_xgetpwnam(optarg); u_flag = 1; open_flag = EXT2_FLAG_RW; @@ -646,9 +640,9 @@ int tune2fs_main(int argc, char **argv) } if (m_flag) { sb->s_r_blocks_count = (sb->s_blocks_count / 100) - * reserved_ratio; + * reserved_ratio; ext2fs_mark_super_dirty(fs); - printf("Setting reserved blocks percentage to %lu (%u blocks)\n", + printf("Setting reserved blocks percentage to %u (%u blocks)\n", reserved_ratio, sb->s_r_blocks_count); } if (r_flag) { |