~csurbhi/ubuntu/maverick/e2fsprogs/e2fsprogs.fix-505719

« back to all changes in this revision

Viewing changes to lib/ext2fs/check_desc.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2008-08-08 20:32:11 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20080808203211-w72lpsd9q7o3bw6x
Tags: 1.41.0-3ubuntu1
* Merge from Debian unstable (LP: #254152, #246461), remaining changes:
  - Do not build-depend on dietlibc-dev, which is in universe.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 */
32
32
errcode_t ext2fs_check_desc(ext2_filsys fs)
33
33
{
 
34
        ext2fs_block_bitmap bmap;
 
35
        errcode_t retval;
34
36
        dgrp_t i;
35
37
        blk_t first_block = fs->super->s_first_data_block;
36
 
        blk_t last_block;
 
38
        blk_t last_block = fs->super->s_blocks_count-1;
 
39
        blk_t blk, b;
 
40
        int j;
37
41
 
38
42
        EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
39
43
 
 
44
        retval = ext2fs_allocate_block_bitmap(fs, "check_desc map", &bmap);
 
45
        if (retval)
 
46
                return retval;
 
47
 
 
48
        for (i = 0; i < fs->group_desc_count; i++)
 
49
                ext2fs_reserve_super_and_bgd(fs, i, bmap);
 
50
 
40
51
        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);
43
 
 
44
 
                /*
45
 
                 * Check to make sure block bitmap for group is
46
 
                 * located within the group.
47
 
                 */
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;
51
 
                /*
52
 
                 * Check to make sure inode bitmap for group is
53
 
                 * located within the group
54
 
                 */
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;
58
 
                /*
59
 
                 * Check to make sure inode table for group is located
60
 
                 * within the group
61
 
                 */
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 - 1) > last_block))
65
 
                        return EXT2_ET_GDESC_BAD_INODE_TABLE;
 
52
                if (!EXT2_HAS_INCOMPAT_FEATURE(fs->super,
 
53
                                               EXT4_FEATURE_INCOMPAT_FLEX_BG)) {
 
54
                        first_block = ext2fs_group_first_block(fs, i);
 
55
                        last_block = ext2fs_group_last_block(fs, i);
 
56
                        if (i == (fs->group_desc_count - 1)) 
 
57
                                last_block = fs->super->s_blocks_count-1;
 
58
                }
 
59
 
 
60
                /*
 
61
                 * Check to make sure the block bitmap for group is sane
 
62
                 */
 
63
                blk = fs->group_desc[i].bg_block_bitmap;
 
64
                if (blk < first_block || blk > last_block ||
 
65
                    ext2fs_test_block_bitmap(bmap, blk)) {
 
66
                        retval = EXT2_ET_GDESC_BAD_BLOCK_MAP;
 
67
                        goto errout;
 
68
                }
 
69
                ext2fs_mark_block_bitmap(bmap, blk);
 
70
 
 
71
                /*
 
72
                 * Check to make sure the inode bitmap for group is sane
 
73
                 */
 
74
                blk = fs->group_desc[i].bg_inode_bitmap;
 
75
                if (blk < first_block || blk > last_block ||
 
76
                    ext2fs_test_block_bitmap(bmap, blk)) {
 
77
                        retval = EXT2_ET_GDESC_BAD_INODE_MAP;
 
78
                        goto errout;
 
79
                }
 
80
                ext2fs_mark_block_bitmap(bmap, blk);
 
81
 
 
82
                /*
 
83
                 * Check to make sure the inode table for group is sane
 
84
                 */
 
85
                blk = fs->group_desc[i].bg_inode_table;
 
86
                if (blk < first_block ||
 
87
                    ((blk + fs->inode_blocks_per_group - 1) > last_block)) {
 
88
                        retval = EXT2_ET_GDESC_BAD_INODE_TABLE;
 
89
                        goto errout;
 
90
                }
 
91
                for (j = 0, b = blk; j < fs->inode_blocks_per_group; 
 
92
                     j++, b++) {
 
93
                        if (ext2fs_test_block_bitmap(bmap, b)) {
 
94
                                retval = EXT2_ET_GDESC_BAD_INODE_TABLE;
 
95
                                goto errout;
 
96
                        }
 
97
                        ext2fs_mark_block_bitmap(bmap, b);
 
98
                }
66
99
        }
67
 
        return 0;
 
100
errout:
 
101
        ext2fs_free_block_bitmap(bmap);
 
102
        return retval;
68
103
}