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 Library
8 * General Public License, version 2.
24 #include <sys/types.h>
30 struct read_bb_record
{
31 ext2_badblocks_list bb_list
;
36 * Helper function for ext2fs_read_bb_inode()
41 static int mark_bad_block(ext2_filsys fs
, blk_t
*block_nr
,
42 e2_blkcnt_t blockcnt
EXT2FS_ATTR((unused
)),
43 blk_t ref_block
EXT2FS_ATTR((unused
)),
44 int ref_offset
EXT2FS_ATTR((unused
)),
47 struct read_bb_record
*rb
= (struct read_bb_record
*) priv_data
;
52 if ((*block_nr
< fs
->super
->s_first_data_block
) ||
53 (*block_nr
>= ext2fs_blocks_count(fs
->super
)))
54 return 0; /* Ignore illegal blocks */
56 rb
->err
= ext2fs_badblocks_list_add(rb
->bb_list
, *block_nr
);
63 * Reads the current bad blocks from the bad blocks inode.
65 errcode_t
ext2fs_read_bb_inode(ext2_filsys fs
, ext2_badblocks_list
*bb_list
)
68 struct read_bb_record rb
;
69 struct ext2_inode inode
;
72 EXT2_CHECK_MAGIC(fs
, EXT2_ET_MAGIC_EXT2FS_FILSYS
);
75 retval
= ext2fs_read_inode(fs
, EXT2_BAD_INO
, &inode
);
78 numblocks
= inode
.i_blocks
;
79 if (!((fs
->super
->s_feature_ro_compat
&
80 EXT4_FEATURE_RO_COMPAT_HUGE_FILE
) &&
81 (inode
.i_flags
& EXT4_HUGE_FILE_FL
)))
82 numblocks
= numblocks
/ (fs
->blocksize
/ 512);
86 if (numblocks
> 50000)
88 retval
= ext2fs_badblocks_list_create(bb_list
, numblocks
);
93 rb
.bb_list
= *bb_list
;
95 retval
= ext2fs_block_iterate2(fs
, EXT2_BAD_INO
, BLOCK_FLAG_READ_ONLY
,
96 0, mark_bad_block
, &rb
);