resize2fs: correctly account for clusters when calculating summary stats

Fixes resize2fs so it correctly calculates the number of free clusters
in each block group for file systems with the bigalloc feature
enabled.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
This commit is contained in:
Theodore Ts'o 2013-01-19 23:41:36 -05:00
parent 3e1816b8cc
commit 1773c87c7e

View File

@ -62,6 +62,15 @@ static errcode_t fix_sb_journal_backup(ext2_filsys fs);
((blk) < (ext2fs_inode_table_loc((fs), (i)) + \
(fs)->inode_blocks_per_group)))
/* Some bigalloc helper macros which are more succint... */
#define B2C(x) EXT2FS_B2C(fs, (x))
#define C2B(x) EXT2FS_C2B(fs, (x))
#define EQ_CLSTR(x, y) (B2C(x) == B2C(y))
#define LE_CLSTR(x, y) (B2C(x) <= B2C(y))
#define LT_CLSTR(x, y) (B2C(x) < B2C(y))
#define GE_CLSTR(x, y) (B2C(x) >= B2C(y))
#define GT_CLSTR(x, y) (B2C(x) > B2C(y))
int lazy_itable_init;
/*
@ -1822,26 +1831,27 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
else
old_desc_blocks = fs->desc_blocks +
fs->super->s_reserved_gdt_blocks;
for (blk = fs->super->s_first_data_block;
blk < ext2fs_blocks_count(fs->super); blk++) {
for (blk = B2C(fs->super->s_first_data_block);
blk < ext2fs_blocks_count(fs->super);
blk += EXT2FS_CLUSTER_RATIO(fs)) {
if ((uninit &&
!((blk == super_blk) ||
!(EQ_CLSTR(blk, super_blk) ||
((old_desc_blk && old_desc_blocks &&
(blk >= old_desc_blk) &&
(blk < old_desc_blk + old_desc_blocks))) ||
((new_desc_blk && (blk == new_desc_blk))) ||
(blk == ext2fs_block_bitmap_loc(fs, group)) ||
(blk == ext2fs_inode_bitmap_loc(fs, group)) ||
((blk >= ext2fs_inode_table_loc(fs, group) &&
(blk < ext2fs_inode_table_loc(fs, group)
GE_CLSTR(blk, old_desc_blk) &&
LT_CLSTR(blk, old_desc_blk + old_desc_blocks))) ||
((new_desc_blk && EQ_CLSTR(blk, new_desc_blk))) ||
EQ_CLSTR(blk, ext2fs_block_bitmap_loc(fs, group)) ||
EQ_CLSTR(blk, ext2fs_inode_bitmap_loc(fs, group)) ||
((GE_CLSTR(blk, ext2fs_inode_table_loc(fs, group)) &&
LT_CLSTR(blk, ext2fs_inode_table_loc(fs, group)
+ fs->inode_blocks_per_group))))) ||
(!ext2fs_fast_test_block_bitmap2(fs->block_map, blk))) {
group_free++;
total_blocks_free++;
}
count++;
if ((count == fs->super->s_blocks_per_group) ||
(blk == ext2fs_blocks_count(fs->super)-1)) {
if ((count == fs->super->s_clusters_per_group) ||
EQ_CLSTR(blk, ext2fs_blocks_count(fs->super)-1)) {
ext2fs_bg_free_blocks_count_set(fs, group, group_free);
ext2fs_group_desc_csum_set(fs, group);
group++;
@ -1861,6 +1871,7 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
fs->super->s_reserved_gdt_blocks;
}
}
total_blocks_free = C2B(total_blocks_free);
ext2fs_free_blocks_count_set(fs->super, total_blocks_free);
/*