Whamcloud - gitweb
Fix gcc -Wall warnings in libuuid
[tools/e2fsprogs.git] / lib / ext2fs / csum.c
index a385d76..1091d73 100644 (file)
@@ -69,7 +69,10 @@ int ext2fs_group_desc_csum_verify(ext2_filsys fs, dgrp_t group)
 
 void ext2fs_group_desc_csum_set(ext2_filsys fs, dgrp_t group)
 {
-       fs->group_desc[group].bg_checksum = ext2fs_group_desc_csum(fs, group);
+       if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
+                                      EXT4_FEATURE_RO_COMPAT_GDT_CSUM))
+               fs->group_desc[group].bg_checksum =
+                       ext2fs_group_desc_csum(fs, group);
 }
 
 static __u32 find_last_inode_ingrp(ext2fs_inode_bitmap bitmap,
@@ -89,60 +92,35 @@ static __u32 find_last_inode_ingrp(ext2fs_inode_bitmap bitmap,
 
 /* update the bitmap flags, set the itable high watermark, and calculate
  * checksums for the group descriptors */
-void ext2fs_set_gdt_csum(ext2_filsys fs)
+errcode_t ext2fs_set_gdt_csum(ext2_filsys fs)
 {
        struct ext2_super_block *sb = fs->super;
        struct ext2_group_desc *bg = fs->group_desc;
-       int blks, csum_flag, dirty = 0;
+       int blks, dirty = 0;
        dgrp_t i;
 
-       csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
-                                              EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
-       if (!EXT2_HAS_COMPAT_FEATURE(fs->super,
-                                    EXT2_FEATURE_COMPAT_LAZY_BG) && !csum_flag)
-               return;
+       if (!fs->inode_map)
+               return EXT2_ET_NO_INODE_BITMAP;
+
+       if (!EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
+                                       EXT4_FEATURE_RO_COMPAT_GDT_CSUM))
+               return 0;
 
        for (i = 0; i < fs->group_desc_count; i++, bg++) {
                int old_csum = bg->bg_checksum;
                int old_unused = bg->bg_itable_unused;
                int old_flags = bg->bg_flags;
 
-               /* Even if it wasn't zeroed, by the time this function is
-                * called by e2fsck we have already scanned and corrected
-                * the whole inode table so we may as well not overwrite it.
-                * This is just a hint to the kernel that it could do lazy
-                * zeroing of the inode table if mke2fs didn't do it, to help
-                * out if we need to do a full itable scan sometime later. */
-               if (!(bg->bg_flags & (EXT2_BG_INODE_UNINIT |
-                                     EXT2_BG_INODE_ZEROED)))
-                       fs->group_desc[i].bg_flags |= EXT2_BG_INODE_ZEROED;
-
-               if (bg->bg_free_inodes_count == sb->s_inodes_per_group &&
-                   i > 0 && (i < fs->group_desc_count - 1 || csum_flag)) {
-                       if (!(bg->bg_flags & EXT2_BG_INODE_UNINIT))
-                               bg->bg_flags |= EXT2_BG_INODE_UNINIT;
-
-                       if (csum_flag)
-                               bg->bg_itable_unused = sb->s_inodes_per_group;
-               } else if (csum_flag) {
+               if (bg->bg_free_inodes_count == sb->s_inodes_per_group) {
+                       bg->bg_flags |= EXT2_BG_INODE_UNINIT;
+                       bg->bg_itable_unused = sb->s_inodes_per_group;
+               } else {
                        bg->bg_flags &= ~EXT2_BG_INODE_UNINIT;
                        bg->bg_itable_unused = sb->s_inodes_per_group -
                                find_last_inode_ingrp(fs->inode_map,
                                                      sb->s_inodes_per_group,i);
                }
 
-               /* skip first and last groups, or groups with GDT backups
-                * because the resize inode has blocks allocated in them. */
-               if (i == 0 || (i == fs->group_desc_count - 1 && !csum_flag) ||
-                   (ext2fs_bg_has_super(fs, i) && sb->s_reserved_gdt_blocks))
-                       goto checksum;
-
-               blks = ext2fs_super_and_bgd_loc(fs, i, 0, 0, 0, 0);
-               if (bg->bg_free_blocks_count == blks &&
-                   bg->bg_flags & EXT2_BG_INODE_UNINIT &&
-                   !(bg->bg_flags & EXT2_BG_BLOCK_UNINIT))
-                       bg->bg_flags |= EXT2_BG_BLOCK_UNINIT;
-checksum:
                ext2fs_group_desc_csum_set(fs, i);
                if (old_flags != bg->bg_flags)
                        dirty = 1;
@@ -153,4 +131,5 @@ checksum:
        }
        if (dirty)
                ext2fs_mark_super_dirty(fs);
+       return 0;
 }