diff options
| author | ngkaho1234 <ngkaho1234@gmail.com> | 2016-05-07 08:55:20 +0000 |
|---|---|---|
| committer | Kaho Ng <ngkaho1234@gmail.com> | 2016-05-07 16:58:04 +0800 |
| commit | 2e93de2e29c061c7cf7f0fc9562a00d3dc16b561 (patch) | |
| tree | cdd06c2fdd8ffb5d065f5313570a966addf104bb /src | |
| parent | 670b5f15834213fec6fe0ffd41d3419591cb64a5 (diff) | |
ext4: count on free blocks and inodes number after journal recovery.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ext4.c | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -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); |
