From: Corey Hickey Date: Mon, 24 Jan 2022 02:33:22 +0000 (-0800) Subject: badblocks: separate and improve error messages for blocks_at_once X-Git-Tag: v1.46.6~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c48a46ebd63d213ab8fb55564f7a1ba5782efbe;p=thirdparty%2Fe2fsprogs.git badblocks: separate and improve error messages for blocks_at_once Since the conditional checks the product of block_size and blocks_at_once, reporting that the problem is solely with blocks_at_once is misleading. Also change the error to use the name of the parameter listed in the manual rather than the variable name. Since blocks_at_once is unsigned, change the test to == rather than <=. Before: $ misc/badblocks -w -b 16777216 -c 524288 -e 1 -s -v /tmp/testfile.bin misc/badblocks: Invalid blocks_at_once: 524288 After: $ misc/badblocks -w -b 16777216 -c 524288 -e 1 -s -v /tmp/testfile.bin misc/badblocks: For block size 16777216, blocks_at_once too large: 524288 $ misc/badblocks -w -b 16777216 -c 0 -e 1 -s -v /tmp/testfile.bin misc/badblocks: Invalid number of blocks: 0 Signed-off-by: Corey Hickey Signed-off-by: Theodore Ts'o --- diff --git a/misc/badblocks.c b/misc/badblocks.c index e640eadd4..0e74be801 100644 --- a/misc/badblocks.c +++ b/misc/badblocks.c @@ -1211,11 +1211,14 @@ int main (int argc, char ** argv) block_size); exit(1); } - if ((blocks_at_once <= 0) || - (((unsigned long long) block_size * blocks_at_once) > 0xFFFFFFFF)) { - com_err(program_name, 0, _("Invalid blocks_at_once: %d\n"), + if (blocks_at_once == 0) { + com_err(program_name, 0, _("Invalid number of blocks: %d\n"), blocks_at_once); exit(1); + } else if (((unsigned long long) block_size * blocks_at_once) > 0xFFFFFFFF) { + com_err(program_name, 0, _("For block size %d, number of blocks too large: %d\n"), + block_size, blocks_at_once); + exit(1); } if (optind > argc - 1)