2 * read_bb --- read the bad blocks inode
4 * Copyright (C) 1994 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
23 #include <sys/types.h>
26 #if EXT2_FLAT_INCLUDES
29 #include <linux/ext2_fs.h>
34 struct read_bb_record {
35 ext2_badblocks_list bb_list;
40 * Helper function for ext2fs_read_bb_inode()
45 static int mark_bad_block(ext2_filsys fs, blk_t *block_nr,
46 e2_blkcnt_t blockcnt, blk_t ref_block,
47 int ref_offset, void *priv_data)
49 struct read_bb_record *rb = (struct read_bb_record *) priv_data;
54 if ((*block_nr < fs->super->s_first_data_block) ||
55 (*block_nr >= fs->super->s_blocks_count))
56 return 0; /* Ignore illegal blocks */
58 rb->err = ext2fs_badblocks_list_add(rb->bb_list, *block_nr);
65 * Reads the current bad blocks from the bad blocks inode.
67 errcode_t ext2fs_read_bb_inode(ext2_filsys fs, ext2_badblocks_list *bb_list)
70 struct read_bb_record rb;
71 struct ext2_inode inode;
74 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
77 retval = ext2fs_read_inode(fs, EXT2_BAD_INO, &inode);
80 if (inode.i_blocks < 500)
81 numblocks = (inode.i_blocks /
82 (fs->blocksize / 512)) + 20;
85 retval = ext2fs_badblocks_list_create(bb_list, numblocks);
90 rb.bb_list = *bb_list;
92 retval = ext2fs_block_iterate2(fs, EXT2_BAD_INO, 0, 0,