Whamcloud - gitweb
Fix superblock field s_blocks_count for bigalloc file systems
authorTheodore Ts'o <tytso@mit.edu>
Thu, 16 Jun 2011 05:38:43 +0000 (01:38 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 16 Jun 2011 05:38:43 +0000 (01:38 -0400)
Treat the s_blocks_count field in the superblock as a free block count
(instead of the number of free clusters) for bigalloc file systems.

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

index 14529c0..f9d746c 100644 (file)
@@ -401,6 +401,7 @@ redo_counts:
                                ext2fs_unmark_valid(fs);
                }
        }
+       free_blocks = EXT2FS_C2B(fs, free_blocks);
        if (free_blocks != ext2fs_free_blocks_count(fs->super)) {
                pctx.group = 0;
                pctx.blk = ext2fs_free_blocks_count(fs->super);
index 3f9e333..40cfc4f 100644 (file)
@@ -690,7 +690,7 @@ void check_super_block(e2fsck_t ctx)
                        return;
        }
 
-       ctx->free_blocks = free_blocks;
+       ctx->free_blocks = EXT2FS_C2B(fs, free_blocks);
        ctx->free_inodes = free_inodes;
 
        if ((ext2fs_free_blocks_count(sb) > ext2fs_blocks_count(sb)) ||
index efe03be..ccc2dee 100644 (file)
@@ -91,6 +91,7 @@ errcode_t ext2fs_initialize(const char *name, int flags,
        unsigned int    overhead = 0;
        unsigned int    ipg;
        dgrp_t          i;
+       blk64_t         free_blocks;
        blk_t           numblocks;
        int             rsv_gdt;
        int             csum_flag;
@@ -431,7 +432,7 @@ ipg_retry:
         * superblock and group descriptors (the inode tables and
         * bitmaps will be accounted for when allocated).
         */
-       ext2fs_free_blocks_count_set(super, 0);
+       free_blocks = 0;
        csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
                                               EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
        for (i = 0; i < fs->group_desc_count; i++) {
@@ -453,14 +454,14 @@ ipg_retry:
                if (fs->super->s_log_groups_per_flex)
                        numblocks += 2 + fs->inode_blocks_per_group;
 
-               ext2fs_free_blocks_count_set(super,
-                                            ext2fs_free_blocks_count(super) +
-                                            numblocks);
+               free_blocks += numblocks;
                ext2fs_bg_free_blocks_count_set(fs, i, numblocks);
                ext2fs_bg_free_inodes_count_set(fs, i, fs->super->s_inodes_per_group);
                ext2fs_bg_used_dirs_count_set(fs, i, 0);
                ext2fs_group_desc_csum_set(fs, i);
        }
+       free_blocks &= ~EXT2FS_CLUSTER_MASK(fs);
+       ext2fs_free_blocks_count_set(super, free_blocks);
 
        c = (char) 255;
        if (((int) c) == -1) {
index 7e0cc34..788e0fc 100644 (file)
@@ -2134,7 +2134,7 @@ static void fix_cluster_bg_counts(ext2_filsys fs)
                        group++;
                }
        }
-       ext2fs_free_blocks_count_set(fs->super, tot_free);
+       ext2fs_free_blocks_count_set(fs->super, EXT2FS_C2B(fs, tot_free));
 }
 
 int main (int argc, char *argv[])
index 3f7e7e7..d7cb124 100644 (file)
@@ -265,7 +265,7 @@ static int release_blocks_proc(ext2_filsys fs, blk64_t *blocknr,
        group = ext2fs_group_of_blk2(fs, block);
        ext2fs_bg_free_blocks_count_set(fs, group, ext2fs_bg_free_blocks_count(fs, group) + 1);
        ext2fs_group_desc_csum_set(fs, group);
-       ext2fs_free_blocks_count_add(fs->super, 1);
+       ext2fs_free_blocks_count_add(fs->super, EXT2FS_CLUSTER_RATIO(fs));
        return 0;
 }
 
@@ -1402,6 +1402,7 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
                        group_free = 0;
                }
        }
+       total_free = EXT2FS_C2B(fs, total_free);
        ext2fs_free_blocks_count_set(fs->super, total_free);
 
        /*