From 39791dc0bda8c5a995e307e6306b79cd0fded644 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sun, 20 Feb 2011 15:19:47 -0500 Subject: badblocks: Fix up recover_block handling in badblocks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If there was a bad block for block #0, badblocks would never switch back testing blocks more efficiently. In addition, we were double-incrementing the blocks to be tested in the read/write test due to failure to remove code. Thanks to Ragnar Kjørstad for pointing these problems out. Signed-off-by: "Theodore Ts'o" --- misc/badblocks.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) (limited to 'misc') diff --git a/misc/badblocks.c b/misc/badblocks.c index 84e84748..f2965417 100644 --- a/misc/badblocks.c +++ b/misc/badblocks.c @@ -571,7 +571,7 @@ static unsigned int test_rw (int dev, blk_t last_block, const unsigned int *pattern; int i, try, got, nr_pattern, pat_idx; unsigned int bb_count = 0; - blk_t recover_block = 0; + blk_t recover_block = ~0; /* set up abend handler */ capture_terminate(NULL); @@ -681,17 +681,6 @@ static unsigned int test_rw (int dev, blk_t last_block, block_size)) bb_count += bb_output(currently_testing+i); } - currently_testing += got; - if (got != try) { - try = 1; - if (!recover_block) - recover_block = currently_testing - - got + blocks_at_once; - continue; - } else if (currently_testing == recover_block) { - try = blocks_at_once; - recover_block = 0; - } if (v_flag > 1) print_status(); } @@ -732,7 +721,7 @@ static unsigned int test_nd (int dev, blk_t last_block, unsigned long buf_used; static unsigned int bb_count; int granularity = blocks_at_once; - blk_t recover_block = 0; + blk_t recover_block = ~0; bb_count = 0; errcode = ext2fs_badblocks_list_iterate_begin(bb_list,&bb_iter); @@ -831,8 +820,7 @@ static unsigned int test_nd (int dev, blk_t last_block, got = do_read (dev, save_ptr, try, block_size, currently_testing); if (got == 0) { - if ((currently_testing == 0) || - (recover_block == 0)) + if (recover_block == ~0) recover_block = currently_testing + blocks_at_once; if (granularity != 1) { @@ -867,7 +855,7 @@ static unsigned int test_nd (int dev, blk_t last_block, currently_testing += got; if (got != try) { try = 1; - if (!recover_block) + if (recover_block == ~0) recover_block = currently_testing - got + blocks_at_once; continue; @@ -885,7 +873,7 @@ static unsigned int test_nd (int dev, blk_t last_block, if (currently_testing >= recover_block) { granularity = blocks_at_once; - recover_block = 0; + recover_block = ~0; } flush_bufs(); @@ -1298,4 +1286,3 @@ int main (int argc, char ** argv) free(t_patts); return 0; } - -- cgit v1.2.3