static void do_test_seq(badblocks_list bb, blk_t *vec) { int i, match; for (i = 0; vec[i]; i += 2) { switch (vec[i+1]) { case ADD_BLK: ext2fs_badblocks_list_add(bb, vec[i]); match = ext2fs_badblocks_list_test(bb, vec[i]); printf("Adding block %d --- now %s\n", vec[i], match ? "present" : "absent"); if (!match) { printf("FAILURE!\n"); test_fail++; } break; case DEL_BLK: ext2fs_badblocks_list_del(bb, vec[i]); match = ext2fs_badblocks_list_test(bb, vec[i]); printf("Removing block %d --- now %s\n", vec[i], ext2fs_badblocks_list_test(bb, vec[i]) ? "present" : "absent"); if (match) { printf("FAILURE!\n"); test_fail++; } break; } } }
/* * This routine reports a new bad block. If the bad block has already * been seen before, then it returns 0; otherwise it returns 1. */ static int bb_output (blk_t bad, enum error_types error_type) { errcode_t errcode; if (ext2fs_badblocks_list_test(bb_list, bad)) return 0; fprintf(out, "%lu\n", (unsigned long) bad); fflush(out); errcode = ext2fs_badblocks_list_add (bb_list, bad); if (errcode) { com_err (program_name, errcode, "adding to in-memory bad block list"); exit (1); } /* kludge: increment the iteration through the bb_list if an element was just added before the current iteration position. This should not cause next_bad to change. */ if (bb_iter && bad < next_bad) ext2fs_badblocks_list_iterate (bb_iter, &next_bad); if (error_type == READ_ERROR) { num_read_errors++; } else if (error_type == WRITE_ERROR) { num_write_errors++; } else if (error_type == CORRUPTION_ERROR) { num_corruption_errors++; } return 1; }
static void validate_test_seq(badblocks_list bb, blk_t *vec) { int i, match, ok; for (i = 0; vec[i]; i += 2) { match = ext2fs_badblocks_list_test(bb, vec[i]); if (match == vec[i+1]) ok = 1; else { ok = 0; test_fail++; } printf("\tblock %d is %s --- %s\n", vec[i], match ? "present" : "absent", ok ? "OK" : "NOT OK"); } }
/* * This routine reports a new bad block. If the bad block has already * been seen before, then it returns 0; otherwise it returns 1. */ static int bb_output (unsigned long bad) { errcode_t errcode; if (ext2fs_badblocks_list_test(bb_list, bad)) return 0; fprintf (out, "%lu\n", bad); errcode = ext2fs_badblocks_list_add (bb_list, bad); if (errcode) { com_err (program_name, errcode, "adding to in-memory bad block list"); exit (1); } /* kludge: increment the iteration through the bb_list if an element was just added before the current iteration position. This should not cause next_bad to change. */ if (bb_iter && bad < next_bad) ext2fs_badblocks_list_iterate (bb_iter, &next_bad); return 1; }
static void handle_bad_blocks(ext2_filsys fs, badblocks_list bb_list) { dgrp_t i; blk_t j; unsigned must_be_good; blk_t blk; badblocks_iterate bb_iter; errcode_t retval; blk_t group_block; int group; int group_bad; if (!bb_list) return; /* * The primary superblock and group descriptors *must* be * good; if not, abort. */ must_be_good = fs->super->s_first_data_block + 1 + fs->desc_blocks; for (i = fs->super->s_first_data_block; i <= must_be_good; i++) { if (ext2fs_badblocks_list_test(bb_list, i)) { fprintf(stderr, _("Block %d in primary " "superblock/group descriptor area bad.\n"), i); fprintf(stderr, _("Blocks %u through %d must be good " "in order to build a filesystem.\n"), fs->super->s_first_data_block, must_be_good); fputs(_("Aborting....\n"), stderr); exit(1); } } /* * See if any of the bad blocks are showing up in the backup * superblocks and/or group descriptors. If so, issue a * warning and adjust the block counts appropriately. */ group_block = fs->super->s_first_data_block + fs->super->s_blocks_per_group; for (i = 1; i < fs->group_desc_count; i++) { group_bad = 0; for (j=0; j < fs->desc_blocks+1; j++) { if (ext2fs_badblocks_list_test(bb_list, group_block + j)) { if (!group_bad) fprintf(stderr, _("Warning: the backup superblock/group descriptors at block %u contain\n" " bad blocks.\n\n"), group_block); group_bad++; group = ext2fs_group_of_blk(fs, group_block+j); fs->group_desc[group].bg_free_blocks_count++; fs->super->s_free_blocks_count++; } } group_block += fs->super->s_blocks_per_group; } /* * Mark all the bad blocks as used... */ retval = ext2fs_badblocks_list_iterate_begin(bb_list, &bb_iter); if (retval) { com_err("ext2fs_badblocks_list_iterate_begin", retval, _("while marking bad blocks as used")); exit(1); } while (ext2fs_badblocks_list_iterate(bb_iter, &blk)) ext2fs_mark_block_bitmap(fs->block_map, blk); ext2fs_badblocks_list_iterate_end(bb_iter); }
int badblocks_list_test(badblocks_list bb, blk_t blk) { return ext2fs_badblocks_list_test(bb, blk); }