[PATCH v1] Add an option to only dump/fsck an inode by path

Kelvin Zhang zhangkelvin at google.com
Thu Dec 2 08:48:02 AEDT 2021


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

Change-Id: Iac1aebba5d510dd3d4f38e65d4056ea9ac9871bb
Signed-off-by: Kelvin Zhang <zhangkelvin at google.com>
---
 dump/main.c | 15 ++++++++++++++-
 fsck/main.c | 16 +++++++++++++++-
 mkfs/main.c |  7 +++++++
 3 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/dump/main.c b/dump/main.c
index b7560ec..dcf577e 100644
--- a/dump/main.c
+++ b/dump/main.c
@@ -8,6 +8,7 @@
 #include <stdlib.h>
 #include <getopt.h>
 #include <time.h>
+#include "erofs/internal.h"
 #include "erofs/print.h"
 #include "erofs/inode.h"
 #include "erofs/io.h"
@@ -23,6 +24,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 +73,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 +106,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=str      show the target inode info of path\n"
 	      " --help          display this help and exit.\n",
 	      stderr);
 }
@@ -148,6 +152,10 @@ 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;
+			break;
 		default:
 			return -EINVAL;
 		}
@@ -449,7 +457,12 @@ 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/fsck/main.c b/fsck/main.c
index aefa881..ecdd0bf 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -6,6 +6,7 @@
 #include <stdlib.h>
 #include <getopt.h>
 #include <time.h>
+#include "erofs/internal.h"
 #include "erofs/print.h"
 #include "erofs/io.h"
 #include "erofs/decompress.h"
@@ -18,6 +19,7 @@ struct erofsfsck_cfg {
 	bool check_decomp;
 	u64 physical_blocks;
 	u64 logical_blocks;
+	const char *inode_path;
 };
 static struct erofsfsck_cfg fsckcfg;
 
@@ -25,6 +27,7 @@ static struct option long_options[] = {
 	{"help", no_argument, 0, 1},
 	{"extract", no_argument, 0, 2},
 	{"device", required_argument, 0, 3},
+	{"path", required_argument, 0, 4},
 	{0, 0, 0, 0},
 };
 
@@ -37,6 +40,7 @@ static void usage(void)
 	      " -p              print total compression ratio of all files\n"
 	      " --device=X      specify an extra device to be used together\n"
 	      " --extract       check if all files are well encoded\n"
+	      " --path					check if a specific file well encoded\n"
 	      " --help          display this help and exit.\n",
 	      stderr);
 }
@@ -79,6 +83,10 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)
 				return ret;
 			++sbi.extra_devices;
 			break;
+		case 4:
+			fsckcfg.inode_path = optarg;
+			fsckcfg.check_decomp = true;
+			break;
 		default:
 			return -EINVAL;
 		}
@@ -582,7 +590,13 @@ int main(int argc, char **argv)
 		goto exit_dev_close;
 	}
 
-	erofs_check_inode(sbi.root_nid, sbi.root_nid);
+	if (fsckcfg.inode_path) {
+		struct erofs_inode inode;
+		erofs_ilookup(fsckcfg.inode_path, &inode);
+		erofs_verify_inode_data(&inode);
+	} else {
+		erofs_check_inode(sbi.root_nid, sbi.root_nid);
+	}
 
 	if (fsckcfg.corrupted) {
 		erofs_err("Found some filesystem corruption");
diff --git a/mkfs/main.c b/mkfs/main.c
index 58a6441..d6bc7dd 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -24,6 +24,13 @@
 #include "erofs/compress_hints.h"
 #include "erofs/blobchunk.h"
 
+#ifdef WITH_ANDROID
+#include <selinux/android.h>
+#include <private/android_filesystem_config.h>
+#include <private/canned_fs_config.h>
+#include <private/fs_config.h>
+#endif
+
 #ifdef HAVE_LIBUUID
 #include <uuid.h>
 #endif
-- 
2.34.0.rc2.393.gf8c9666880-goog



More information about the Linux-erofs mailing list