Whamcloud - gitweb
mke2fs: allow metadata checksums to be turned on at mkfs time
authorDarrick J. Wong <djwong@us.ibm.com>
Mon, 30 Jul 2012 22:54:04 +0000 (18:54 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 30 Jul 2012 22:54:04 +0000 (18:54 -0400)
Write out reserved inodes with full checksums when writing out a
zeroed table.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/mke2fs.c

index 94db901..d1d8156 100644 (file)
@@ -304,6 +304,27 @@ _("Warning: the backup superblock/group descriptors at block %u contain\n"
        ext2fs_badblocks_list_iterate_end(bb_iter);
 }
 
+static void write_reserved_inodes(ext2_filsys fs)
+{
+       errcode_t       retval;
+       ext2_ino_t      ino;
+       struct ext2_inode *inode;
+
+       retval = ext2fs_get_mem(EXT2_INODE_SIZE(fs->super), &inode);
+       if (retval) {
+               com_err("inode_init", retval,
+                       "while allocating memory");
+               exit(1);
+       }
+       bzero(inode, EXT2_INODE_SIZE(fs->super));
+
+       for (ino = 1; ino < EXT2_FIRST_INO(fs->super); ino++)
+               ext2fs_write_inode_full(fs, ino, inode,
+                                       EXT2_INODE_SIZE(fs->super));
+
+       ext2fs_free_mem(&inode);
+}
+
 static void write_inode_tables(ext2_filsys fs, int lazy_flag, int itable_zeroed)
 {
        errcode_t       retval;
@@ -349,6 +370,12 @@ static void write_inode_tables(ext2_filsys fs, int lazy_flag, int itable_zeroed)
        ext2fs_zero_blocks2(0, 0, 0, 0, 0);
        ext2fs_numeric_progress_close(fs, &progress,
                                      _("done                            \n"));
+
+       /* Reserved inodes must always have correct checksums */
+       if (fs->super->s_creator_os == EXT2_OS_LINUX &&
+           fs->super->s_feature_ro_compat &
+           EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)
+               write_reserved_inodes(fs);
 }
 
 static void create_root_dir(ext2_filsys fs)
@@ -868,7 +895,7 @@ static __u32 ok_features[3] = {
 #ifdef CONFIG_QUOTA
                EXT4_FEATURE_RO_COMPAT_QUOTA|
 #endif
-               0
+               EXT4_FEATURE_RO_COMPAT_METADATA_CSUM
 };