+2000-07-06 Theodore Ts'o <tytso@valinux.com>
+
+ * 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 <tytso@valinux.com>
* badblocks.c (test_nd): Significantly simplify the logic so that
.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).
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"
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);
}
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;
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) {