diff options
author | Theodore Ts'o <tytso@mit.edu> | 1997-04-26 13:34:30 +0000 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 1997-04-26 13:34:30 +0000 |
commit | f3db3566b5e1342e49dffc5ec3f418a838584194 (patch) | |
tree | 1f6c5daaee7f33beb697143a8891da8a55752dd6 /e2fsck/badblocks.c | |
parent | 6f4a109706f51ad11b9fff0983c140ab62549d2f (diff) | |
download | e2fsprogs-f3db3566b5e1342e49dffc5ec3f418a838584194.tar.gz |
Many files:
Checkin of e2fsprogs 0.5b
Diffstat (limited to 'e2fsck/badblocks.c')
-rw-r--r-- | e2fsck/badblocks.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/e2fsck/badblocks.c b/e2fsck/badblocks.c index 6dff23d9..62f99c9c 100644 --- a/e2fsck/badblocks.c +++ b/e2fsck/badblocks.c @@ -10,6 +10,10 @@ #include <et/com_err.h> #include "e2fsck.h" +static int check_bb_inode_blocks(ext2_filsys fs, blk_t *block_nr, int blockcnt, + void *private); + + static void invalid_block(ext2_filsys fs, blk_t blk) { printf("Bad block %lu out of range; ignored.\n", blk); @@ -24,6 +28,19 @@ void read_bad_blocks_file(ext2_filsys fs, const char *bad_blocks_file, FILE *f; read_bitmaps(fs); + + /* + * Make sure the bad block inode is sane. If there are any + * illegal blocks, clear them. + */ + retval = ext2fs_block_iterate(fs, EXT2_BAD_INO, 0, 0, + check_bb_inode_blocks, 0); + if (retval) { + com_err("ext2fs_block_iterate", retval, + "while sanity checking the bad blocks inode"); + fatal_error(0); + } + /* * If we're appending to the bad blocks inode, read in the @@ -69,6 +86,25 @@ void read_bad_blocks_file(ext2_filsys fs, const char *bad_blocks_file, return; } +static int check_bb_inode_blocks(ext2_filsys fs, blk_t *block_nr, int blockcnt, + void *private) +{ + if (!*block_nr) + return 0; + + /* + * If the block number is outrageous, clear it and ignore it. + */ + if (*block_nr >= fs->super->s_blocks_count || + *block_nr < fs->super->s_first_data_block) { + printf("Warning illegal block %lu found in bad block inode. Cleared.\n", *block_nr); + *block_nr = 0; + return BLOCK_CHANGED; + } + + return 0; +} + void test_disk(ext2_filsys fs) { errcode_t retval; |