[PATCH v2] erofs-utils: add an option to dump an inode by path

Gao Xiang hsiangkao at linux.alibaba.com
Tue Dec 7 00:35:55 AEDT 2021


From: Kelvin Zhang <zhangkelvin at google.com>

This is useful when playing around with EROFS images locally.
For example, it allows us to inspect block mappings of a filepath.

Signed-off-by: Kelvin Zhang <zhangkelvin at google.com>
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
Hi Kelvin,

I plan to apply the following path, since it's somewhat weird to just
fsck a specific path. Also I completed the manpage and fix some minor
issues.

Thanks,
Gao Xiang

 dump/main.c      | 14 +++++++++++++-
 man/dump.erofs.1 |  3 +++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/dump/main.c b/dump/main.c
index f85903b059d2..b8ee88761ff0 100644
--- a/dump/main.c
+++ b/dump/main.c
@@ -23,6 +23,7 @@ struct erofsdump_cfg {
 	bool show_superblock;
 	bool show_statistics;
 	erofs_nid_t nid;
+	const char *inode_path;
 };
 static struct erofsdump_cfg dumpcfg;
 
@@ -71,6 +72,7 @@ static struct option long_options[] = {
 	{"help", no_argument, NULL, 1},
 	{"nid", required_argument, NULL, 2},
 	{"device", required_argument, NULL, 3},
+	{"path", required_argument, NULL, 4},
 	{0, 0, 0, 0},
 };
 
@@ -103,6 +105,7 @@ static void usage(void)
 	      " -s              show information about superblock\n"
 	      " --device=X      specify an extra device to be used together\n"
 	      " --nid=#         show the target inode info of nid #\n"
+	      " --path=X        show the target inode info of path X\n"
 	      " --help          display this help and exit.\n",
 	      stderr);
 }
@@ -148,6 +151,11 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)
 				return err;
 			++sbi.extra_devices;
 			break;
+		case 4:
+			dumpcfg.inode_path = optarg;
+			dumpcfg.show_inode = true;
+			++dumpcfg.totalshow;
+			break;
 		default:
 			return -EINVAL;
 		}
@@ -450,7 +458,11 @@ static void erofsdump_show_fileinfo(bool show_extent)
 		.m_la = 0,
 	};
 
-	err = erofs_read_inode_from_disk(&inode);
+	if (dumpcfg.inode_path)
+		err = erofs_ilookup(dumpcfg.inode_path, &inode);
+	else
+		err = erofs_read_inode_from_disk(&inode);
+
 	if (err) {
 		erofs_err("read inode failed @ nid %llu", inode.nid | 0ULL);
 		return;
diff --git a/man/dump.erofs.1 b/man/dump.erofs.1
index 8efb161b65f1..fd437cfcc250 100644
--- a/man/dump.erofs.1
+++ b/man/dump.erofs.1
@@ -22,6 +22,9 @@ You may give multiple `--device' options in the correct order.
 .BI "\-\-nid=" NID
 Specify an inode NID in order to print its file information.
 .TP
+.BI "\-\-path=" path
+Specify an inode path in order to print its file information.
+.TP
 .BI \-e
 Show the file extent information. The option depends on option --nid to specify NID.
 .TP
-- 
2.24.4



More information about the Linux-erofs mailing list