From: ngkaho1234 Date: Sat, 7 May 2016 08:55:20 +0000 (+0000) Subject: ext4: count on free blocks and inodes number after journal recovery. X-Git-Url: https://git.carlh.net/gitweb/?a=commitdiff_plain;h=2e93de2e29c061c7cf7f0fc9562a00d3dc16b561;p=lwext4.git ext4: count on free blocks and inodes number after journal recovery. --- diff --git a/src/ext4.c b/src/ext4.c index b284648..c51dd8c 100644 --- a/src/ext4.c +++ b/src/ext4.c @@ -48,6 +48,7 @@ #include "ext4_dir.h" #include "ext4_inode.h" #include "ext4_super.h" +#include "ext4_block_group.h" #include "ext4_dir_idx.h" #include "ext4_xattr.h" #include "ext4_journal.h" @@ -565,7 +566,31 @@ static int __ext4_recover(const char *mount_point) jbd_put_fs(jbd_fs); free(jbd_fs); } + if (r == EOK && !mp->fs.read_only) { + uint32_t bgid; + uint64_t free_blocks_count = 0; + uint32_t free_inodes_count = 0; + struct ext4_block_group_ref bg_ref; + /* Update superblock's stats */ + for (bgid = 0;bgid < ext4_block_group_cnt(&mp->fs.sb);bgid++) { + r = ext4_fs_get_block_group_ref(&mp->fs, bgid, &bg_ref); + if (r != EOK) + goto Finish; + + free_blocks_count += + ext4_bg_get_free_blocks_count(bg_ref.block_group, + &mp->fs.sb); + free_inodes_count += + ext4_bg_get_free_inodes_count(bg_ref.block_group, + &mp->fs.sb); + + ext4_fs_put_block_group_ref(&bg_ref); + } + ext4_sb_set_free_blocks_cnt(&mp->fs.sb, free_blocks_count); + ext4_set32(&mp->fs.sb, free_inodes_count, free_inodes_count); + /* We don't need to save the superblock stats immediately. */ + } Finish: EXT4_MP_UNLOCK(mp);