dump.f2fs: introduce start_bidx_of_node() for cleanup
authorChao Yu <yuchao0@huawei.com>
Fri, 9 Aug 2019 10:52:58 +0000 (18:52 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 27 Aug 2019 21:51:05 +0000 (14:51 -0700)
Just cleanup, no logic change, besides, it can be reused by latter
patch.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/dump.c

index 390361d..a6a1635 100644 (file)
@@ -527,11 +527,31 @@ static void dump_node_from_blkaddr(struct f2fs_sb_info *sbi, u32 blk_addr)
        free(node_blk);
 }
 
+unsigned int start_bidx_of_node(unsigned int node_ofs,
+                                       struct f2fs_node *node_blk)
+{
+       unsigned int indirect_blks = 2 * NIDS_PER_BLOCK + 4;
+       unsigned int bidx;
+
+       if (node_ofs == 0)
+               return 0;
+
+       if (node_ofs <= 2) {
+               bidx = node_ofs - 1;
+       } else if (node_ofs <= indirect_blks) {
+               int dec = (node_ofs - 4) / (NIDS_PER_BLOCK + 1);
+               bidx = node_ofs - 2 - dec;
+       } else {
+               int dec = (node_ofs - indirect_blks - 3) / (NIDS_PER_BLOCK + 1);
+               bidx = node_ofs - 5 - dec;
+       }
+       return bidx * ADDRS_PER_BLOCK + ADDRS_PER_INODE(&node_blk->i);
+}
+
 static void dump_data_offset(u32 blk_addr, int ofs_in_node)
 {
        struct f2fs_node *node_blk;
-       unsigned int indirect_blks = 2 * NIDS_PER_BLOCK + 4;
-       unsigned int bidx = 0;
+       unsigned int bidx;
        unsigned int node_ofs;
        int ret;
 
@@ -543,20 +563,7 @@ static void dump_data_offset(u32 blk_addr, int ofs_in_node)
 
        node_ofs = ofs_of_node(node_blk);
 
-       if (node_ofs == 0)
-               goto got_it;
-
-       if (node_ofs > 0 && node_ofs <= 2) {
-               bidx = node_ofs - 1;
-       } else if (node_ofs <= indirect_blks) {
-               int dec = (node_ofs - 4) / (NIDS_PER_BLOCK + 1);
-               bidx = node_ofs - 2 - dec;
-       } else {
-               int dec = (node_ofs - indirect_blks - 3) / (NIDS_PER_BLOCK + 1);
-               bidx = node_ofs - 5 - dec;
-       }
-       bidx = bidx * ADDRS_PER_BLOCK + ADDRS_PER_INODE(&node_blk->i);
-got_it:
+       bidx = start_bidx_of_node(node_ofs, node_blk);
        bidx +=  ofs_in_node;
 
        setlocale(LC_ALL, "");