From 35964b5c4a85ab73c1ac02caed98584b6527f7c2 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Thu, 6 Jul 2000 13:19:43 +0000 Subject: [PATCH] ChangeLog, badblocks.8.in, badblocks.c: badblocks.8.in: Update manual page to reflect that the blocks-count parameter is now optional. Also properly document the start-block parameter. badblocks.c (main): Allow the blocks-count parameter to be optional. If it's not specified, use the size of the device as a default. --- misc/ChangeLog | 10 ++++++++++ misc/badblocks.8.in | 11 +++++++++-- misc/badblocks.c | 37 ++++++++++++++++++++++++++----------- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/misc/ChangeLog b/misc/ChangeLog index 4d6490fd..16b09504 100644 --- a/misc/ChangeLog +++ b/misc/ChangeLog @@ -1,3 +1,13 @@ +2000-07-06 Theodore Ts'o + + * badblocks.8.in: Update manual page to reflect that the + blocks-count parameter is now optional. Also properly + document the start-block parameter. + + * badblocks.c (main): Allow the blocks-count parameter to be + optional. If it's not specified, use the size of the + device as a default. + 2000-07-05 Theodore Ts'o * badblocks.c (test_nd): Significantly simplify the logic so that diff --git a/misc/badblocks.8.in b/misc/badblocks.8.in index c08b6be9..bbc4a080 100644 --- a/misc/badblocks.8.in +++ b/misc/badblocks.8.in @@ -28,7 +28,11 @@ badblocks \- search a device for bad blocks .I num_passes ] .I device -.IR blocks-count [ start-block ] +[ +.I blocks-count +] [ +.I start-block +] .SH DESCRIPTION .B badblocks is used to search for bad blocks on a device (usually a disk partition). @@ -36,7 +40,10 @@ is used to search for bad blocks on a device (usually a disk partition). is the special file corresponding to the device (e.g .IR /dev/hdc1 ). .I blocks-count -is the number of blocks on the device. +is the number of blocks on the device; if it is not specified, the size +of the device is used as a default. +.I start-block is an optional parameter specifying the starting block number +for the test, which allows the testing to start in the middle of the disk. .SH OPTIONS .TP .BI \-b " block-size" diff --git a/misc/badblocks.c b/misc/badblocks.c index cc1cae97..c7f1d46b 100644 --- a/misc/badblocks.c +++ b/misc/badblocks.c @@ -70,7 +70,7 @@ static char *blkbuf; /* Allocation array for bad block testing */ static void usage(void) { - fprintf(stderr, _("Usage: %s [-b block_size] [-i input_file] [-o output_file] [-svwn]\n [-c blocks_at_once] [-p num_passes] device blocks_count [start_count]\n"), + fprintf(stderr, _("Usage: %s [-b block_size] [-i input_file] [-o output_file] [-svwn]\n [-c blocks_at_once] [-p num_passes] device [blocks_count] [start_count]\n"), program_name); exit (1); } @@ -624,7 +624,7 @@ int main (int argc, char ** argv) FILE * in = NULL; int block_size = 1024; unsigned long blocks_at_once = 16; - unsigned long blocks_count, from_count; + blk_t blocks_count, from_count; int num_passes = 0; int passes_clean = 0; int dev; @@ -705,16 +705,31 @@ int main (int argc, char ** argv) if (optind > argc - 1) usage(); device_name = argv[optind++]; - if (optind > argc - 1) - usage(); - blocks_count = strtoul (argv[optind], &tmp, 0); - if (*tmp) - { - com_err (program_name, 0, _("bad blocks count - %s"), - argv[optind]); - exit (1); + if (optind > argc - 1) { + errcode = ext2fs_get_device_size(device_name, + block_size, + &blocks_count); + if (errcode == EXT2_ET_UNIMPLEMENTED) { + com_err(program_name, 0, + _("Couldn't determine device size; you " + "must specify\nthe size manually\n")); + exit(1); + } + if (errcode) { + com_err(program_name, errcode, + _("while trying to determine device size")); + exit(1); + } + } else { + blocks_count = strtoul (argv[optind], &tmp, 0); + if (*tmp) { + com_err (program_name, 0, _("bad blocks count - %s"), + argv[optind]); + exit (1); + } + optind++; } - if (++optind <= argc-1) { + if (optind <= argc-1) { from_count = strtoul (argv[optind], &tmp, 0); } else from_count = 0; if (from_count >= blocks_count) { -- 2.11.0