Changes to update Tomato RAF.
[tomato.git] / release / src / router / busybox / e2fsprogs / old_e2fsprogs / ext2fs / check_desc.c
blobdd4b0e9cf5df18e47f0752588bf6eb250416d245
1 /* vi: set sw=4 ts=4: */
2 /*
3 * check_desc.c --- Check the group descriptors of an ext2 filesystem
5 * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
7 * %Begin-Header%
8 * This file may be redistributed under the terms of the GNU Public
9 * License.
10 * %End-Header%
13 #include <stdio.h>
14 #include <string.h>
15 #if HAVE_UNISTD_H
16 #include <unistd.h>
17 #endif
18 #include <fcntl.h>
19 #include <time.h>
20 #if HAVE_SYS_STAT_H
21 #include <sys/stat.h>
22 #endif
23 #if HAVE_SYS_TYPES_H
24 #include <sys/types.h>
25 #endif
27 #include "ext2_fs.h"
28 #include "ext2fs.h"
31 * This routine sanity checks the group descriptors
33 errcode_t ext2fs_check_desc(ext2_filsys fs)
35 dgrp_t i;
36 blk_t block = fs->super->s_first_data_block;
37 blk_t next;
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
59 * within the group
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;
66 block = next;
68 return 0;