Fixing corrupted data depends on c.fix_on. If it's not set, we should not
force fixing corrupted data.  So if nat entries are found invalid when
building nat_area_bitmap, we should just set c.bug_on, and fix it later.

Signed-off-by: Sheng Yong <shengyo...@huawei.com>
Reviewed-by: Chao Yu <yuch...@huawei.com>
---
 fsck/mount.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/fsck/mount.c b/fsck/mount.c
index 17da814..d8bc50c 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -1877,8 +1877,14 @@ void nullify_nat_entry(struct f2fs_sb_info *sbi, u32 nid)
        ret = dev_read_block(nat_block, block_addr);
        ASSERT(ret >= 0);
 
-       memset(&nat_block->entries[entry_off], 0,
+       if (nid == F2FS_NODE_INO(sbi) || nid == F2FS_META_INO(sbi)) {
+               FIX_MSG("nid [0x%x] block_addr= 0x%x -> 0x1", nid,
+                       le32_to_cpu(nat_block->entries[entry_off].block_addr));
+               nat_block->entries[entry_off].block_addr = cpu_to_le32(0x1);
+       } else {
+               memset(&nat_block->entries[entry_off], 0,
                                        sizeof(struct f2fs_nat_entry));
+       }
 
        ret = dev_write_block(nat_block, block_addr);
        ASSERT(ret >= 0);
@@ -2000,13 +2006,14 @@ void build_nat_area_bitmap(struct f2fs_sb_info *sbi)
 
                        if ((nid + i) == F2FS_NODE_INO(sbi) ||
                                        (nid + i) == F2FS_META_INO(sbi)) {
-                               /* block_addr of node/meta inode should be 0x1 
*/
+                               /*
+                                * block_addr of node/meta inode should be 0x1.
+                                * Set this bit, and fsck_verify will fix it.
+                                */
                                if 
(le32_to_cpu(nat_block->entries[i].block_addr) != 0x1) {
-                                       FIX_MSG("ino: 0x%x node/meta inode, 
block_addr= 0x%x -> 0x1",
+                                       ASSERT_MSG("\tError: ino[0x%x] 
block_addr[0x%x] is invalid\n",
                                                        nid + i, 
le32_to_cpu(nat_block->entries[i].block_addr));
-                                       nat_block->entries[i].block_addr = 
cpu_to_le32(0x1);
-                                       ret = dev_write_block(nat_block, 
block_addr);
-                                       ASSERT(ret >= 0);
+                                       f2fs_set_bit(nid + i, 
fsck->nat_area_bitmap);
                                }
                                continue;
                        }
-- 
2.11.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to