- /* test the comparison between all the
- blocks successfully read */
- for (i = 0; i < got; ++i)
- if (memcmp (test_ptr+i*block_size,
- read_ptr+i*block_size, block_size))
- bb_count += bb_output(currently_testing + i);
- if (got < try) {
- bb_count += bb_output(currently_testing + got);
- got++;
+ flush_bufs();
+ save_currently_testing = currently_testing;
+
+ /*
+ * for each contiguous block that we read into the
+ * buffer (and wrote test data into afterwards), read
+ * it back (looping if necessary, to get past newly
+ * discovered unreadable blocks, of which there should
+ * be none, but with a hard drive which is unreliable,
+ * it has happened), and compare with the test data
+ * that was written; output to the bad block list if
+ * it doesn't match.
+ */
+ used2 = 0;
+ save_ptr = save_base;
+ test_ptr = test_base;
+ read_ptr = read_base;
+ try = 0;
+
+ while (1) {
+ if (try == 0) {
+ if (used2 >= num_saved)
+ break;
+ currently_testing = test_record[used2].block;
+ try = test_record[used2].num;
+ used2++;
+ }
+
+ got = do_read (dev, read_ptr, try,
+ block_size, currently_testing);
+
+ /* test the comparison between all the
+ blocks successfully read */
+ for (i = 0; i < got; ++i)
+ if (memcmp (test_ptr+i*block_size,
+ read_ptr+i*block_size, block_size))
+ bb_count += bb_output(currently_testing + i, CORRUPTION_ERROR);
+ if (got < try) {
+ bb_count += bb_output(currently_testing + got, READ_ERROR);
+ got++;
+ }
+
+ /* write back original data */
+ do_write (dev, save_ptr, got,
+ block_size, currently_testing);
+ save_ptr += got * block_size;
+
+ currently_testing += got;
+ test_ptr += got * block_size;
+ read_ptr += got * block_size;
+ try -= got;