dump.f2fs: check block address first before reading the block
authorJaegeuk Kim <jaegeuk@kernel.org>
Tue, 14 Jul 2020 05:59:41 +0000 (22:59 -0700)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 15 Jul 2020 17:30:03 +0000 (10:30 -0700)
This should avoid to read out wrong block address.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/dump.c

index e472eb7..055ce09 100644 (file)
@@ -482,8 +482,6 @@ void dump_node(struct f2fs_sb_info *sbi, nid_t nid, int force)
        node_blk = calloc(BLOCK_SZ, 1);
        ASSERT(node_blk);
 
-       dev_read_block(node_blk, ni.blk_addr);
-
        DBG(1, "Node ID               [0x%x]\n", nid);
        DBG(1, "nat_entry.block_addr  [0x%x]\n", ni.blk_addr);
        DBG(1, "nat_entry.version     [0x%x]\n", ni.version);
@@ -494,6 +492,8 @@ void dump_node(struct f2fs_sb_info *sbi, nid_t nid, int force)
                goto out;
        }
 
+       dev_read_block(node_blk, ni.blk_addr);
+
        if (ni.blk_addr == 0x0)
                MSG(force, "Invalid nat entry\n\n");
        else if (!is_sit_bitmap_set(sbi, ni.blk_addr))