From fe75afbf33389f71f8588af388d0c01db0cbf753 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Thu, 16 Jun 2011 01:38:43 -0400 Subject: [PATCH] Fix superblock field s_blocks_count for bigalloc file systems 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" --- e2fsck/pass5.c | 1 + e2fsck/super.c | 2 +- lib/ext2fs/initialize.c | 9 +++++---- misc/mke2fs.c | 2 +- misc/tune2fs.c | 3 ++- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/e2fsck/pass5.c b/e2fsck/pass5.c index 14529c0..f9d746c 100644 --- a/e2fsck/pass5.c +++ b/e2fsck/pass5.c @@ -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); diff --git a/e2fsck/super.c b/e2fsck/super.c index 3f9e333..40cfc4f 100644 --- a/e2fsck/super.c +++ b/e2fsck/super.c @@ -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)) || diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c index efe03be..ccc2dee 100644 --- a/lib/ext2fs/initialize.c +++ b/lib/ext2fs/initialize.c @@ -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) { diff --git a/misc/mke2fs.c b/misc/mke2fs.c index 7e0cc34..788e0fc 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -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[]) diff --git a/misc/tune2fs.c b/misc/tune2fs.c index 3f7e7e7..d7cb124 100644 --- a/misc/tune2fs.c +++ b/misc/tune2fs.c @@ -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); /* -- 1.8.3.1