fsck.f2fs: count the number of inodes during building nat_area_bitmap
authorSheng Yong <shengyong1@huawei.com>
Mon, 14 Mar 2016 06:16:54 +0000 (14:16 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 22 Mar 2016 21:10:00 +0000 (14:10 -0700)
The nid and ino of an inode are the same. So during building
nat_area_bitmap, we can know which nat entry represents an
inode, thus, we can count the number of inodes.

Then in fsck_chk_meta, the amount of inodes can be compared
with that recorded in CP.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/fsck.c
fsck/fsck.h
fsck/mount.c

index fede8e1..7100397 100644 (file)
@@ -1573,6 +1573,14 @@ int fsck_chk_meta(struct f2fs_sb_info *sbi)
                return -EINVAL;
        }
 
+       if (fsck->nat_valid_inode_cnt != le32_to_cpu(cp->valid_inode_count)) {
+               ASSERT_MSG("valid inode does not match: nat_valid_inode_cnt %u,"
+                               " valid_inode_count %u",
+                               fsck->nat_valid_inode_cnt,
+                               le32_to_cpu(cp->valid_inode_count));
+               return -EINVAL;
+       }
+
        return 0;
 }
 
index f03efb8..da4e6ad 100644 (file)
@@ -76,6 +76,7 @@ struct f2fs_fsck {
        u32 nr_nat_entries;
 
        u32 dentry_depth;
+       u32 nat_valid_inode_cnt;
 };
 
 #define BLOCK_SZ               4096
index af1e0c3..4f907ef 100644 (file)
@@ -1679,6 +1679,11 @@ void build_nat_area_bitmap(struct f2fs_sb_info *sbi)
                        if (lookup_nat_in_journal(sbi, nid + i,
                                                        &raw_nat) >= 0) {
                                node_info_from_raw_nat(&ni, &raw_nat);
+                               if (ni.ino == (nid + i) && ni.blk_addr != 0) {
+                                       fsck->nat_valid_inode_cnt++;
+                                       DBG(3, "ino[0x%8x] maybe is inode\n",
+                                                               ni.ino);
+                               }
                                if (ni.blk_addr != 0x0) {
                                        f2fs_set_bit(nid + i,
                                                        fsck->nat_area_bitmap);
@@ -1689,6 +1694,11 @@ void build_nat_area_bitmap(struct f2fs_sb_info *sbi)
                        } else {
                                node_info_from_raw_nat(&ni,
                                                &nat_block->entries[i]);
+                               if (ni.ino == (nid + i) && ni.blk_addr != 0) {
+                                       fsck->nat_valid_inode_cnt++;
+                                       DBG(3, "ino[0x%8x] maybe is inode\n",
+                                                               ni.ino);
+                               }
                                if (ni.blk_addr == 0)
                                        continue;
                                if (nid + i == 0) {