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

Gao Xiang hsiangkao at linux.alibaba.com
Wed Dec 8 01:05:28 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>
---
changes since v2:
 - use different failure message for path.

 dump/main.c      | 25 +++++++++++++++++++++----
 man/dump.erofs.1 |  3 +++
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/dump/main.c b/dump/main.c
index f85903b059d2..072d726da71b 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,10 +458,19 @@ static void erofsdump_show_fileinfo(bool show_extent)
 		.m_la = 0,
 	};
 
-	err = erofs_read_inode_from_disk(&inode);
-	if (err) {
-		erofs_err("read inode failed @ nid %llu", inode.nid | 0ULL);
-		return;
+	if (dumpcfg.inode_path) {
+		err = erofs_ilookup(dumpcfg.inode_path, &inode);
+		if (err) {
+			erofs_err("read inode failed @ %s", dumpcfg.inode_path);
+			return;
+		}
+	} else {
+		err = erofs_read_inode_from_disk(&inode);
+		if (err) {
+			erofs_err("read inode failed @ nid %llu",
+				  inode.nid | 0ULL);
+			return;
+		}
 	}
 
 	err = erofs_get_occupied_size(&inode, &size);
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