linux-erofs.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Guo Xuenan <guoxuenan@huawei.com>
To: <xiang@kernel.org>, <linux-erofs@lists.ozlabs.org>
Cc: mpiglet@outlook.com
Subject: [PATCH v1 5/5] dump.erofs: add -I options to dump the layout of a particular inode on disk
Date: Sat, 11 Sep 2021 21:46:35 +0800	[thread overview]
Message-ID: <20210911134635.1253426-5-guoxuenan@huawei.com> (raw)
In-Reply-To: <20210911134635.1253426-1-guoxuenan@huawei.com>

From: mpiglet <mpiglet@outlook.com>

Signed-off-by: Guo Xuenan <guoxuenan@huawei.com>
Signed-off-by: mpiglet <mpiglet@outlook.com>
---
 dump/main.c | 108 +++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 91 insertions(+), 17 deletions(-)

diff --git a/dump/main.c b/dump/main.c
index 2389cef..efce309 100644
--- a/dump/main.c
+++ b/dump/main.c
@@ -21,8 +21,10 @@ struct dumpcfg {
 	bool print_superblock;
 	bool print_inode;
 	bool print_statistic;
+	bool print_inode_phy;
 	bool print_version;
 	u64 ino;
+	u64 ino_phy;
 };
 static struct dumpcfg dumpcfg;
 
@@ -105,6 +107,7 @@ static void usage(void)
 		"-s         print information about superblock\n"
 		"-S         print statistic information of the erofs-image\n"
 		"-i #       print target # inode info\n"
+		"-I #       print target # inode on-disk info\n"
 		"-v/-V      print dump.erofs version info\n"
 		"-h/--help  display this help and exit\n", stderr);
 }
@@ -136,6 +139,11 @@ static int dumpfs_parse_options_cfg(int argc, char **argv)
 			dumpcfg.print_inode = true;
 			dumpcfg.ino = i;
 			break;
+		case 'I':
+			i = atoll(optarg);
+			dumpcfg.print_inode_phy = true;
+			dumpcfg.ino_phy = i;
+			break;
 		case 'h':
 		case 1:
 		    usage();
@@ -402,25 +410,25 @@ static void dumpfs_print_inode(void)
 	fprintf(stderr, "Inode %lu info:\n", dumpcfg.ino);
 	switch (inode.inode_isize) {
 	case 32:
-		fprintf(stderr, "	File inode is compacted layout\n");
+		fprintf(stderr, "File inode is compacted layout\n");
 		break;
 	case 64:
-		fprintf(stderr, "	File inode is extended layout\n");
+		fprintf(stderr, "File inode is extended layout\n");
 		break;
 	default:
 		erofs_err("unsupported inode layout\n");
 	}
-	fprintf(stderr, "	File size:		%lu\n",
+	fprintf(stderr, "File size:		%lu\n",
 			inode.i_size);
-	fprintf(stderr, "	File nid:		%lu\n",
+	fprintf(stderr, "File nid:		%lu\n",
 			inode.nid);
-	fprintf(stderr, "	File extent size:	%u\n",
+	fprintf(stderr, "File extent size:	%u\n",
 			inode.extent_isize);
-	fprintf(stderr, "	File xattr size:	%u\n",
+	fprintf(stderr, "File xattr size:	%u\n",
 			inode.xattr_isize);
-	fprintf(stderr, "	File inode size:	%u\n",
+	fprintf(stderr, "File inode size:	%u\n",
 			inode.inode_isize);
-	fprintf(stderr, "	File type:		");
+	fprintf(stderr, "File type:		");
 	switch (inode.i_mode & S_IFMT) {
 	case S_IFREG:
 		fprintf(stderr, "regular\n");
@@ -453,13 +461,13 @@ static void dumpfs_print_inode(void)
 		return;
 	}
 
-	fprintf(stderr, "	File original size:	%lu\n"
-			"	File on-disk size:	%lu\n",
+	fprintf(stderr, "File original size:	%lu\n"
+			"File on-disk size:	%lu\n",
 			inode.i_size, size);
-	fprintf(stderr, "	File compress rate:	%.2f%%\n",
+	fprintf(stderr, "File compress rate:	%.2f%%\n",
 			(double)(100 * size) / (double)(inode.i_size));
 
-	fprintf(stderr, "	File datalayout:	");
+	fprintf(stderr, "File datalayout:	");
 	switch (inode.datalayout) {
 	case EROFS_INODE_FLAT_PLAIN:
 		fprintf(stderr, "EROFS_INODE_FLAT_PLAIN\n");
@@ -477,18 +485,82 @@ static void dumpfs_print_inode(void)
 		break;
 	}
 
-	fprintf(stderr, "	File create time:	%s", ctime(&t));
-	fprintf(stderr, "	File uid:		%u\n", inode.i_uid);
-	fprintf(stderr, "	File gid:		%u\n", inode.i_gid);
-	fprintf(stderr, "	File hard-link count:	%u\n", inode.i_nlink);
+	fprintf(stderr, "File create time:	%s", ctime(&t));
+	fprintf(stderr, "File uid:		%u\n", inode.i_uid);
+	fprintf(stderr, "File gid:		%u\n", inode.i_gid);
+	fprintf(stderr, "File hard-link count:	%u\n", inode.i_nlink);
 
 	err = get_path_by_nid(sbi.root_nid, sbi.root_nid, nid, path, 0);
 	if (!err)
-		fprintf(stderr, "	File path:		%s\n", path);
+		fprintf(stderr, "File path:		%s\n", path);
 	else
 		fprintf(stderr, "Path not found\n");
 }
 
+static void dumpfs_print_inode_phy(void)
+{
+	int err;
+	erofs_nid_t nid = dumpcfg.ino_phy;
+	struct erofs_inode inode = {.nid = nid};
+	char path[PATH_MAX + 1] = {0};
+
+	err = erofs_read_inode_from_disk(&inode);
+	if (err < 0) {
+		erofs_err("read inode %lu from disk failed", nid);
+		return;
+	}
+
+	const erofs_off_t ibase = iloc(inode.nid);
+	const erofs_off_t pos = Z_EROFS_VLE_LEGACY_INDEX_ALIGN(
+			ibase + inode.inode_isize + inode.xattr_isize);
+	erofs_blk_t blocks = inode.u.i_blocks;
+	erofs_blk_t start = 0;
+	erofs_blk_t end = 0;
+	struct erofs_map_blocks map = {
+		.index = UINT_MAX,
+		.m_la = 0,
+	};
+
+	fprintf(stderr, "Inode %lu on-disk info:\n", nid);
+	switch (inode.datalayout) {
+	case EROFS_INODE_FLAT_INLINE:
+	case EROFS_INODE_FLAT_PLAIN:
+		if (inode.u.i_blkaddr == NULL_ADDR)
+			start = end = erofs_blknr(pos);
+		else {
+			start = inode.u.i_blkaddr;
+			end = start + BLK_ROUND_UP(inode.i_size) - 1;
+		}
+		fprintf(stderr, "File size:			%lu\n",
+				inode.i_size);
+		fprintf(stderr,
+				"	Plain Block Address:		%u - %u\n",
+				start, end);
+		break;
+
+	case EROFS_INODE_FLAT_COMPRESSION_LEGACY:
+	case EROFS_INODE_FLAT_COMPRESSION:
+		err = z_erofs_map_blocks_iter(&inode, &map);
+		if (err)
+			erofs_err("get file blocks range failed");
+
+		start = erofs_blknr(map.m_pa);
+		end = start - 1 + blocks;
+		fprintf(stderr,
+				"	Compressed Block Address:	%u - %u\n",
+				start, end);
+		break;
+	}
+
+	err = get_path_by_nid(sbi.root_nid, sbi.root_nid, nid, path, 0);
+	if (!err)
+		fprintf(stderr, "File Path:			%s\n",
+				path);
+	else
+		erofs_err("path not found");
+}
+
+
 static int get_file_type(const char *filename)
 {
 	char *postfix = strrchr(filename, '.');
@@ -810,5 +882,7 @@ int main(int argc, char **argv)
 	if (dumpcfg.print_inode)
 		dumpfs_print_inode();
 
+	if (dumpcfg.print_inode_phy)
+		dumpfs_print_inode_phy();
 	return 0;
 }
-- 
2.25.4


  parent reply	other threads:[~2021-09-11 13:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-11 13:46 [PATCH v1 1/5] erofs-utils: introduce dump.erofs for utils Guo Xuenan
2021-09-11 13:46 ` [PATCH v1 2/5] dump.erofs: add "-s" option to dump superblock information Guo Xuenan
2021-09-11 15:58   ` Gao Xiang
2021-09-11 13:46 ` [PATCH v1 3/5] dump.erofs: add -S options for collecting statistics of the whole filesystem Guo Xuenan
2021-09-11 16:13   ` Gao Xiang
2021-09-13  4:30     ` Huang Jianan via Linux-erofs
2021-09-13 12:46       ` Gao Xiang
2021-09-14  2:31         ` Guo Xuenan
2021-09-11 13:46 ` [PATCH v1 4/5] dump.erofs: add -i options to dump file information of specific inode number Guo Xuenan
2021-09-11 16:25   ` Gao Xiang
2021-09-11 13:46 ` Guo Xuenan [this message]
2021-09-11 16:29   ` [PATCH v1 5/5] dump.erofs: add -I options to dump the layout of a particular inode on disk Gao Xiang
2021-09-11 15:45 ` [PATCH v1 1/5] erofs-utils: introduce dump.erofs for utils Gao Xiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210911134635.1253426-5-guoxuenan@huawei.com \
    --to=guoxuenan@huawei.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=mpiglet@outlook.com \
    --cc=xiang@kernel.org \
    --subject='Re: [PATCH v1 5/5] dump.erofs: add -I options to dump the layout of a particular inode on disk' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).