.I blocks_at_once
]
[
+.B \-e
+.I max_bad_blocks
+]
+[
.B \-i
.I input_file
]
.BI \-c " number of blocks"
is the number of blocks which are tested at a time. The default is 64.
.TP
+.BI \-e " max bad block count"
+Specify a maximum number of bad blocks before aborting the test. The
+default is 0, meaning the test will continue until the end of the test
+range is reached.
+.TP
.B \-f
Normally, badblocks will refuse to do a read/write or a non-destructive
test on a device which is mounted, since either can cause the system to
an existing file system, use the
.B \-n
option instead. It is slower, but it will preserve your data.
+.PP
+The
+.B \-e
+option will cause badblocks to output a possibly incomplete list of
+bad blocks. Therefore it is recommended to use it only when one wants
+to know if there are any bad blocks at all on the device, and not when
+the list of bad blocks is wanted.
.SH AUTHOR
.B badblocks
was written by Remy Card <Remy.Card@linux.org>. Current maintainer is
static unsigned int *t_patts = NULL; /* test patterns */
static int current_O_DIRECT = 0; /* Current status of O_DIRECT flag */
static int exclusive_ok = 0;
+static unsigned int max_bb = 0; /* Abort test if more than this number of bad blocks has been encountered */
#define T_INC 32
static void usage(void)
{
- fprintf(stderr, _("Usage: %s [-b block_size] [-i input_file] [-o output_file] [-svwnf]\n [-c blocks_at_once] [-p num_passes] [-t test_pattern [-t test_pattern [...]]]\n device [last_block [start_block]]\n"),
+ fprintf(stderr, _("Usage: %s [-b block_size] [-i input_file] [-o output_file] [-svwnf]\n [-c blocks_at_once] [-p num_passes] [-e max_bad_blocks] [-t test_pattern [-t test_pattern [...]]]\n device [last_block [start_block]]\n"),
program_name);
exit (1);
}
}
while (currently_testing < last_block)
{
+ if (max_bb && bb_count >= max_bb) {
+ if (s_flag || v_flag) {
+ fputs(_("Too many bad blocks, aborting test\n"), stderr);
+ }
+ break;
+ }
if (next_bad) {
if (currently_testing == next_bad) {
/* fprintf (out, "%lu\n", nextbad); */
try = blocks_at_once;
while (currently_testing < last_block) {
+ if (max_bb && bb_count >= max_bb) {
+ if (s_flag || v_flag) {
+ fputs(_("Too many bad blocks, aborting test\n"), stderr);
+ }
+ break;
+ }
if (currently_testing + try > last_block)
try = last_block - currently_testing;
got = do_write(dev, buffer, try, block_size,
try = blocks_at_once;
while (currently_testing < last_block) {
+ if (max_bb && bb_count >= max_bb) {
+ if (s_flag || v_flag) {
+ fputs(_("Too many bad blocks, aborting test\n"), stderr);
+ }
+ break;
+ }
if (currently_testing + try > last_block)
try = last_block - currently_testing;
got = do_read (dev, read_buffer, try, block_size,
alarm_intr(SIGALRM);
while (currently_testing < last_block) {
+ if (max_bb && bb_count >= max_bb) {
+ if (s_flag || v_flag) {
+ fputs(_("Too many bad blocks, aborting test\n"), stderr);
+ }
+ break;
+ }
got = try = blocks_at_once - buf_used;
if (next_bad) {
if (currently_testing == next_bad) {
if (argc && *argv)
program_name = *argv;
- while ((c = getopt (argc, argv, "b:fi:o:svwnc:p:h:t:X")) != EOF) {
+ while ((c = getopt (argc, argv, "b:e:fi:o:svwnc:p:h:t:X")) != EOF) {
switch (c) {
case 'b':
block_size = parse_uint(optarg, "block size");
case 'c':
blocks_at_once = parse_uint(optarg, "blocks at once");
break;
+ case 'e':
+ max_bb = parse_uint(optarg, "max bad block count");
+ break;
case 'p':
num_passes = parse_uint(optarg,
"number of clean passes");