Signed-off-by: Jaegeuk Kim <[email protected]>
---
 fsck/dump.c     | 38 +++++++++++++++++++++++++++++++++++++-
 fsck/main.c     |  6 +++++-
 man/dump.f2fs.8 |  7 +++++++
 3 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/fsck/dump.c b/fsck/dump.c
index 042a2e52edca..e25c70af84ed 100644
--- a/fsck/dump.c
+++ b/fsck/dump.c
@@ -23,6 +23,9 @@
 
 #define BUF_SZ 80
 
+/* current extent info */
+struct extent_info dump_extent = { 0, 0, 0};
+
 const char *seg_type_name[SEG_TYPE_MAX + 1] = {
        "SEG_TYPE_DATA",
        "SEG_TYPE_CUR_DATA",
@@ -227,6 +230,21 @@ void ssa_dump(struct f2fs_sb_info *sbi, int start_ssa, int 
end_ssa)
        close(fd);
 }
 
+static void print_extent(bool last)
+{
+       if (dump_extent.len == 1) {
+               printf(" %d", dump_extent.blk);
+               dump_extent.len = 0;
+       } else {
+               printf(" %d-%d",
+                       dump_extent.blk,
+                       dump_extent.blk + dump_extent.len - 1);
+               dump_extent.len = 0;
+       }
+       if (last)
+               printf("\n");
+}
+
 static void dump_data_blk(struct f2fs_sb_info *sbi, __u64 offset, u32 blkaddr)
 {
        char buf[F2FS_BLKSIZE];
@@ -237,8 +255,19 @@ static void dump_data_blk(struct f2fs_sb_info *sbi, __u64 
offset, u32 blkaddr)
        /* get data */
        if (blkaddr == NEW_ADDR || !IS_VALID_BLK_ADDR(sbi, blkaddr)) {
                memset(buf, 0, F2FS_BLKSIZE);
+       } else if (c.show_file_map) {
+               if (dump_extent.len == 0) {
+                       dump_extent.blk = blkaddr;
+                       dump_extent.len = 1;
+               } else if (dump_extent.blk + dump_extent.len == blkaddr) {
+                       dump_extent.len++;
+               } else {
+                       print_extent(false);
+               }
+               return;
        } else {
                int ret;
+
                ret = dev_read_block(buf, blkaddr);
                ASSERT(ret >= 0);
        }
@@ -404,6 +433,8 @@ static void dump_inode_blk(struct f2fs_sb_info *sbi, u32 
nid,
                else
                        ASSERT(0);
        }
+       /* last block in extent cache */
+       print_extent(true);
 
        dump_xattr(sbi, node_blk);
 }
@@ -433,6 +464,10 @@ static void dump_file(struct f2fs_sb_info *sbi, struct 
node_info *ni,
        if (force)
                goto dump;
 
+       /* dump file's data */
+       if (c.show_file_map)
+               return dump_inode_blk(sbi, ni->ino, node_blk);
+
        printf("Do you want to dump this file into ./lost_found/? [Y/N] ");
        ret = scanf("%s", ans);
        ASSERT(ret >= 0);
@@ -505,7 +540,8 @@ void dump_node(struct f2fs_sb_info *sbi, nid_t nid, int 
force)
 
        if (le32_to_cpu(node_blk->footer.ino) == ni.ino &&
                        le32_to_cpu(node_blk->footer.nid) == ni.nid) {
-               print_node_info(sbi, node_blk, force);
+               if (!c.show_file_map)
+                       print_node_info(sbi, node_blk, force);
 
                if (ni.ino == ni.nid)
                        dump_file(sbi, &ni, node_blk, force);
diff --git a/fsck/main.c b/fsck/main.c
index c07be1edc94e..2588a01799c2 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -93,6 +93,7 @@ void dump_usage()
        MSG(0, "  -d debug level [default:0]\n");
        MSG(0, "  -i inode no (hex)\n");
        MSG(0, "  -n [NAT dump nid from #1~#2 (decimal), for all 0~-1]\n");
+       MSG(0, "  -M show a block map\n");
        MSG(0, "  -s [SIT dump segno from #1~#2 (decimal), for all 0~-1]\n");
        MSG(0, "  -S sparse_mode\n");
        MSG(0, "  -a [SSA dump segno from #1~#2 (decimal), for all 0~-1]\n");
@@ -376,7 +377,7 @@ void f2fs_parse_options(int argc, char *argv[])
                }
        } else if (!strcmp("dump.f2fs", prog)) {
 #ifdef WITH_DUMP
-               const char *option_string = "d:i:n:s:Sa:b:V";
+               const char *option_string = "d:i:n:Ms:Sa:b:V";
                static struct dump_option dump_opt = {
                        .nid = 0,       /* default root ino */
                        .start_nat = -1,
@@ -423,6 +424,9 @@ void f2fs_parse_options(int argc, char *argv[])
                                                        &dump_opt.start_nat,
                                                        &dump_opt.end_nat);
                                break;
+                       case 'M':
+                               c.show_file_map = 1;
+                               break;
                        case 's':
                                ret = sscanf(optarg, "%d~%d",
                                                        &dump_opt.start_sit,
diff --git a/man/dump.f2fs.8 b/man/dump.f2fs.8
index eedba855721f..1ddb7fc5d0d9 100644
--- a/man/dump.f2fs.8
+++ b/man/dump.f2fs.8
@@ -14,6 +14,10 @@ dump.f2fs \- retrieve directory and file entries from an 
F2FS-formated image
 .I NAT range
 ]
 [
+.B \-M
+.I Block map
+]
+[
 .B \-s
 .I SIT range
 ]
@@ -51,6 +55,9 @@ Specify an inode number to dump out.
 .BI \-n " NAT range"
 Specify a range presented by nids to dump NAT entries.
 .TP
+.BI \-M " Block map"
+Show all the allocated block addresses given inode number.
+.TP
 .BI \-s " SIT range"
 Specify a range presented by segment numbers to dump SIT entries.
 .TP
-- 
2.32.0.272.g935e593368-goog



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to