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 first_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 first_block = ext2fs_group_first_block(fs, i);
42 last_block = ext2fs_group_last_block(fs, i);
45 * Check to make sure block bitmap for group is
46 * located within the group.
48 if (fs->group_desc[i].bg_block_bitmap < first_block ||
49 fs->group_desc[i].bg_block_bitmap > last_block)
50 return EXT2_ET_GDESC_BAD_BLOCK_MAP;
52 * Check to make sure inode bitmap for group is
53 * located within the group
55 if (fs->group_desc[i].bg_inode_bitmap < first_block ||
56 fs->group_desc[i].bg_inode_bitmap > last_block)
57 return EXT2_ET_GDESC_BAD_INODE_MAP;
59 * Check to make sure inode table for group is located
62 if (fs->group_desc[i].bg_inode_table < first_block ||
63 ((fs->group_desc[i].bg_inode_table +
64 fs->inode_blocks_per_group) > last_block))
65 return EXT2_ET_GDESC_BAD_INODE_TABLE;