Whamcloud - gitweb
mke2fs/libext2fs: Fix lazy inode table initialization
authorTheodore Ts'o <tytso@mit.edu>
Wed, 23 Apr 2008 03:18:37 +0000 (23:18 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 23 Apr 2008 03:18:37 +0000 (23:18 -0400)
This fixes some bugs which I introduced recently while revamping the
uninit_bg code.  Since mke2fs is no longer calling
ext2fs_set_gdt_csum(), it's important that ext2fs_initialize()
correctly initialize bg_itable_unused for all block group descriptors.
In addition, mke2fs needs to zero out the the reserved inodes based on
the values of bg_itable_unused set by ext2fs_initialize().

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/ext2fs/initialize.c
misc/mke2fs.c

index 09e1008..8fc1b01 100644 (file)
@@ -179,6 +179,9 @@ errcode_t ext2fs_initialize(const char *name, int flags,
                        set_field(s_min_extra_isize, extra_isize);
                        set_field(s_want_extra_isize, extra_isize);
                }
+       } else {
+               super->s_first_ino = EXT2_GOOD_OLD_FIRST_INO;
+               super->s_inode_size = EXT2_GOOD_OLD_INODE_SIZE;
        }
 
        set_field(s_checkinterval, EXT2_DFL_CHECKINTERVAL);
@@ -388,6 +391,10 @@ ipg_retry:
                                fs->group_desc[i].bg_flags |=
                                        EXT2_BG_BLOCK_UNINIT;
                        fs->group_desc[i].bg_flags |= EXT2_BG_INODE_UNINIT;
+                       numblocks = super->s_inodes_per_group;
+                       if (i == 0)
+                               numblocks -= super->s_first_ino;
+                       fs->group_desc[i].bg_itable_unused = numblocks;
                }
                numblocks = ext2fs_reserve_super_and_bgd(fs, i, fs->block_map);
 
index 61f45aa..11dffb7 100644 (file)
@@ -406,7 +406,7 @@ static void write_inode_tables(ext2_filsys fs, int lazy_flag)
        errcode_t       retval;
        blk_t           blk;
        dgrp_t          i;
-       int             num;
+       int             num, ipb;
        struct progress_struct progress;
 
        if (quiet)
@@ -421,19 +421,28 @@ static void write_inode_tables(ext2_filsys fs, int lazy_flag)
                blk = fs->group_desc[i].bg_inode_table;
                num = fs->inode_blocks_per_group;
 
-               if (!(lazy_flag &&
-                     (fs->group_desc[i].bg_flags & EXT2_BG_INODE_UNINIT))) {
-                       retval = zero_blocks(fs, blk, num, 0, &blk, &num);
-                       if (retval) {
-                               fprintf(stderr, _("\nCould not write %d "
-                               "blocks in inode table starting at %u: %s\n"),
-                                       num, blk, error_message(retval));
-                               exit(1);
-                       }
+               if (lazy_flag) {
+                       ipb = fs->blocksize / EXT2_INODE_SIZE(fs->super);
+                       printf("bg %i, num %d, ipb %d, unused %d ",
+                              i, num, ipb, fs->group_desc[i].bg_itable_unused);
+                       num = ((((fs->super->s_inodes_per_group -
+                                 fs->group_desc[i].bg_itable_unused) *
+                                EXT2_INODE_SIZE(fs->super)) +
+                               EXT2_BLOCK_SIZE(fs->super) - 1) /
+                              EXT2_BLOCK_SIZE(fs->super));
+                       printf("new num %d\n", num);
+               } else {
                        /* The kernel doesn't need to zero the itable blocks */
                        fs->group_desc[i].bg_flags |= EXT2_BG_INODE_ZEROED;
                        ext2fs_group_desc_csum_set(fs, i);
                }
+               retval = zero_blocks(fs, blk, num, 0, &blk, &num);
+               if (retval) {
+                       fprintf(stderr, _("\nCould not write %d "
+                                 "blocks in inode table starting at %u: %s\n"),
+                               num, blk, error_message(retval));
+                       exit(1);
+               }
                if (sync_kludge) {
                        if (sync_kludge == 1)
                                sync();