1 /* vi: set sw=4 ts=4: */
3 * check_desc.c --- Check the group descriptors of an ext2 filesystem
5 * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
8 * This file may be redistributed under the terms of the GNU Public
24 #include <sys/types.h>
31 * This routine sanity checks the group descriptors
33 errcode_t
ext2fs_check_desc(ext2_filsys fs
)
36 blk_t block
= fs
->super
->s_first_data_block
;
39 EXT2_CHECK_MAGIC(fs
, EXT2_ET_MAGIC_EXT2FS_FILSYS
);
41 for (i
= 0; i
< fs
->group_desc_count
; i
++) {
42 next
= block
+ fs
->super
->s_blocks_per_group
;
44 * Check to make sure block bitmap for group is
45 * located within the group.
47 if (fs
->group_desc
[i
].bg_block_bitmap
< block
||
48 fs
->group_desc
[i
].bg_block_bitmap
>= next
)
49 return EXT2_ET_GDESC_BAD_BLOCK_MAP
;
51 * Check to make sure inode bitmap for group is
52 * located within the group
54 if (fs
->group_desc
[i
].bg_inode_bitmap
< block
||
55 fs
->group_desc
[i
].bg_inode_bitmap
>= next
)
56 return EXT2_ET_GDESC_BAD_INODE_MAP
;
58 * Check to make sure inode table for group is located
61 if (fs
->group_desc
[i
].bg_inode_table
< block
||
62 ((fs
->group_desc
[i
].bg_inode_table
+
63 fs
->inode_blocks_per_group
) >= next
))
64 return EXT2_ET_GDESC_BAD_INODE_TABLE
;