2 * check_desc.c --- Check the group descriptors of an ext2 filesystem
4 * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
23 #include <sys/types.h>
30 * This routine sanity checks the group descriptors
32 errcode_t ext2fs_check_desc(ext2_filsys fs)
35 blk_t block = fs->super->s_first_data_block;
38 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
40 for (i = 0; i < fs->group_desc_count; i++) {
41 next = block + fs->super->s_blocks_per_group;
43 * Check to make sure block bitmap for group is
44 * located within the group.
46 if (fs->group_desc[i].bg_block_bitmap < block ||
47 fs->group_desc[i].bg_block_bitmap >= next)
48 return EXT2_ET_GDESC_BAD_BLOCK_MAP;
50 * Check to make sure inode bitmap for group is
51 * located within the group
53 if (fs->group_desc[i].bg_inode_bitmap < block ||
54 fs->group_desc[i].bg_inode_bitmap >= next)
55 return EXT2_ET_GDESC_BAD_INODE_MAP;
57 * Check to make sure inode table for group is located
60 if (fs->group_desc[i].bg_inode_table < block ||
61 ((fs->group_desc[i].bg_inode_table +
62 fs->inode_blocks_per_group) >= next))
63 return EXT2_ET_GDESC_BAD_INODE_TABLE;