Just cleanup, no logic change, besides, it can be reused by latter patch. Signed-off-by: Chao Yu <yuch...@huawei.com> --- fsck/dump.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-)
diff --git a/fsck/dump.c b/fsck/dump.c index 390361d..a6a1635 100644 --- a/fsck/dump.c +++ b/fsck/dump.c @@ -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, ""); -- 2.18.0.rc1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel