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

« back to all changes in this revision

Viewing changes to lib/ext2fs/initialize.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:
67
67
{
68
68
        struct ext2_super_block *sb = fs->super;
69
69
        unsigned long bpg = sb->s_blocks_per_group;
70
 
        unsigned int gdpb = fs->blocksize / sizeof(struct ext2_group_desc);
 
70
        unsigned int gdpb = EXT2_DESC_PER_BLOCK(sb);
71
71
        unsigned long max_blocks = 0xffffffff;
72
72
        unsigned long rsv_groups;
73
73
        unsigned int rsv_gdb;
103
103
        dgrp_t          i;
104
104
        blk_t           numblocks;
105
105
        int             rsv_gdt;
 
106
        int             csum_flag;
106
107
        int             io_flags;
107
 
        char            *buf;
 
108
        char            *buf = 0;
108
109
        char            c;
109
110
 
110
111
        if (!param || !param->s_blocks_count)
158
159
        set_field(s_first_meta_bg, 0);
159
160
        set_field(s_raid_stride, 0);            /* default stride size: 0 */
160
161
        set_field(s_raid_stripe_width, 0);      /* default stripe width: 0 */
 
162
        set_field(s_log_groups_per_flex, 0);
161
163
        set_field(s_flags, 0);
162
164
        if (super->s_feature_incompat & ~EXT2_LIB_FEATURE_INCOMPAT_SUPP) {
163
165
                retval = EXT2_ET_UNSUPP_FEATURE;
172
174
        if (super->s_rev_level >= EXT2_DYNAMIC_REV) {
173
175
                set_field(s_first_ino, EXT2_GOOD_OLD_FIRST_INO);
174
176
                set_field(s_inode_size, EXT2_GOOD_OLD_INODE_SIZE);
 
177
                if (super->s_inode_size >= sizeof(struct ext2_inode_large)) {
 
178
                        int extra_isize = sizeof(struct ext2_inode_large) -
 
179
                                EXT2_GOOD_OLD_INODE_SIZE;
 
180
                        set_field(s_min_extra_isize, extra_isize);
 
181
                        set_field(s_want_extra_isize, extra_isize);
 
182
                }
 
183
        } else {
 
184
                super->s_first_ino = EXT2_GOOD_OLD_FIRST_INO;
 
185
                super->s_inode_size = EXT2_GOOD_OLD_INODE_SIZE;
175
186
        }
176
187
 
177
188
        set_field(s_checkinterval, EXT2_DFL_CHECKINTERVAL);
367
378
         * Note that although the block bitmap, inode bitmap, and
368
379
         * inode table have not been allocated (and in fact won't be
369
380
         * by this routine), they are accounted for nevertheless.
 
381
         *
 
382
         * If FLEX_BG meta-data grouping is used, only account for the
 
383
         * superblock and group descriptors (the inode tables and
 
384
         * bitmaps will be accounted for when allocated).
370
385
         */
371
386
        super->s_free_blocks_count = 0;
 
387
        csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
 
388
                                               EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
372
389
        for (i = 0; i < fs->group_desc_count; i++) {
 
390
                /*
 
391
                 * Don't set the BLOCK_UNINIT group for the last group
 
392
                 * because the block bitmap needs to be padded.
 
393
                 */
 
394
                if (csum_flag) {
 
395
                        if (i != fs->group_desc_count - 1)
 
396
                                fs->group_desc[i].bg_flags |=
 
397
                                        EXT2_BG_BLOCK_UNINIT;
 
398
                        fs->group_desc[i].bg_flags |= EXT2_BG_INODE_UNINIT;
 
399
                        numblocks = super->s_inodes_per_group;
 
400
                        if (i == 0)
 
401
                                numblocks -= super->s_first_ino;
 
402
                        fs->group_desc[i].bg_itable_unused = numblocks;
 
403
                }
373
404
                numblocks = ext2fs_reserve_super_and_bgd(fs, i, fs->block_map);
 
405
                if (fs->super->s_log_groups_per_flex)
 
406
                        numblocks += 2 + fs->inode_blocks_per_group;
374
407
 
375
408
                super->s_free_blocks_count += numblocks;
376
409
                fs->group_desc[i].bg_free_blocks_count = numblocks;
377
410
                fs->group_desc[i].bg_free_inodes_count =
378
411
                        fs->super->s_inodes_per_group;
379
412
                fs->group_desc[i].bg_used_dirs_count = 0;
 
413
                ext2fs_group_desc_csum_set(fs, i);
380
414
        }
381
415
        
382
416
        c = (char) 255;
395
429
        *ret_fs = fs;
396
430
        return 0;
397
431
cleanup:
 
432
        if (buf)
 
433
                free(buf);
398
434
        ext2fs_free(fs);
399
435
        return retval;
400
436
}