Skip to contentSkip to conversation

erofs-utils: introduce dump.erofs

PATCH In review Guo Xuenan 3 participants 9 messages Sep 15, 2021 – Sep 28, 2021

Subsystems (2)
lore
Share & tools
lore

Guo Xuenan

author
#0 lore raw

PATCH v3 1/5 erofs-utils: introduce dump.erofs

From: Wang Qi <[email protected]>

Add dump-tool for erofs to facilitate users directly analyzing the erofs image file.

---
 Makefile.am        |  2 +-
 configure.ac       |  1 +
 dump/Makefile.am   |  8 +++++
 dump/main.c        | 81 ++++++++++++++++++++++++++++++++++++++++++++++
 include/erofs/io.h |  3 ++
 lib/config.c       |  3 ++
 lib/namei.c        |  5 ++-
 7 files changed, 99 insertions(+), 4 deletions(-)
 create mode 100644 dump/Makefile.am
 create mode 100644 dump/main.c
Makefile.am +1 -1
index b804aa9..fedf7b5 100644
@@ -3,7 +3,7 @@
 
 ACLOCAL_AMFLAGS = -I m4
 
-SUBDIRS = man lib mkfs
+SUBDIRS = man lib mkfs dump
 if ENABLE_FUSE
 SUBDIRS += fuse
 endif
configure.ac +1 -0
index f626064..81c493a 100644
@@ -280,6 +280,7 @@ AC_CONFIG_FILES([Makefile
 		 man/Makefile
 		 lib/Makefile
 		 mkfs/Makefile
+		 dump/Makefile
 		 fuse/Makefile])
 AC_OUTPUT
 
dump/Makefile.am new file +8 -0
new file mode 100644
index 0000000..3d8a32c
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Makefile.am
+
+AUTOMAKE_OPTIONS = foreign
+bin_PROGRAMS     = dump.erofs
+dump_erofs_SOURCES = main.c
+dump_erofs_CFLAGS = -Wall -Werror -I$(top_srcdir)/include
+dump_erofs_LDADD = $(top_builddir)/lib/liberofs.la
\ No newline at end of file
dump/main.c new file +81 -0

81 lines not on this page · raw message

include/erofs/io.h +3 -0
index 5574245..00e5de8 100644
@@ -10,6 +10,7 @@
 #define __EROFS_IO_H
 
 #include <unistd.h>
+#include <sys/types.h>
 #include "internal.h"
 
 #ifndef O_BINARY
@@ -25,6 +26,8 @@ int dev_fillzero(u64 offset, size_t len, bool padding);
 int dev_fsync(void);
 int dev_resize(erofs_blk_t nblocks);
 u64 dev_length(void);
+dev_t erofs_new_decode_dev(u32 dev);
+int erofs_read_inode_from_disk(struct erofs_inode *vi);
 
 static inline int blk_write(const void *buf, erofs_blk_t blkaddr,
 			    u32 nblocks)
lib/config.c +3 -0
index 99fcf49..405fae6 100644
@@ -7,6 +7,7 @@
  * Created by Li Guifu <[email protected]>
  */
 #include <string.h>
+#include <stdlib.h>
 #include "erofs/print.h"
 #include "erofs/internal.h"
 
@@ -45,6 +46,8 @@ void erofs_exit_configure(void)
 	if (cfg.sehnd)
 		selabel_close(cfg.sehnd);
 #endif
+	if (cfg.c_img_path)
+		free(cfg.c_img_path);
 }
 
 static unsigned int fullpath_prefix;	/* root directory prefix length */
lib/namei.c +2 -3
index 4e06ba4..b45e9d8 100644
@@ -5,7 +5,6 @@
  * Created by Li Guifu <[email protected]>
  */
 #include <linux/kdev_t.h>
-#include <sys/types.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <errno.h>
@@ -15,7 +14,7 @@
 #include "erofs/print.h"
 #include "erofs/io.h"
 
-static dev_t erofs_new_decode_dev(u32 dev)
+dev_t erofs_new_decode_dev(u32 dev)
 {
 	const unsigned int major = (dev & 0xfff00) >> 8;
 	const unsigned int minor = (dev & 0xff) | ((dev >> 12) & 0xfff00);
@@ -23,7 +22,7 @@ static dev_t erofs_new_decode_dev(u32 dev)
 	return makedev(major, minor);
 }
 
-static int erofs_read_inode_from_disk(struct erofs_inode *vi)
+int erofs_read_inode_from_disk(struct erofs_inode *vi)
 {
 	int ret, ifmt;
 	char buf[sizeof(struct erofs_inode_extended)];
Signature · 1 line
2.25.4
author
#1 lore raw

PATCH v3 2/5 dump.erofs: add "-s" option to dump superblock information

From: Wang Qi <[email protected]>

---
 dump/Makefile.am |  3 +-
 dump/main.c      | 77 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 78 insertions(+), 2 deletions(-)
dump/Makefile.am +2 -1
index 3d8a32c..0bb7b4e 100644
@@ -3,6 +3,7 @@
 
 AUTOMAKE_OPTIONS = foreign
 bin_PROGRAMS     = dump.erofs
+AM_CPPFLAGS = ${libuuid_CFLAGS}
 dump_erofs_SOURCES = main.c
 dump_erofs_CFLAGS = -Wall -Werror -I$(top_srcdir)/include
-dump_erofs_LDADD = $(top_builddir)/lib/liberofs.la
\ No newline at end of file
+dump_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libuuid_LIBS}
\ No newline at end of file
dump/main.c +76 -1

112 lines not on this page · raw message

Signature · 1 line
2.25.4
author
#2 lore raw

PATCH v3 3/5 dump.erofs: add -S options for collecting statistics of the whole filesystem

In reply to Guo Xuenan

From: Wang Qi <[email protected]>

---
 dump/Makefile.am |   2 +-
 dump/main.c      | 348 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 348 insertions(+), 2 deletions(-)
dump/Makefile.am +1 -1
index 0bb7b4e..d7b2873 100644
@@ -6,4 +6,4 @@ bin_PROGRAMS     = dump.erofs
 AM_CPPFLAGS = ${libuuid_CFLAGS}
 dump_erofs_SOURCES = main.c
 dump_erofs_CFLAGS = -Wall -Werror -I$(top_srcdir)/include
-dump_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libuuid_LIBS}
\ No newline at end of file
+dump_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libuuid_LIBS} ${liblz4_LIBS}
\ No newline at end of file
dump/main.c +347 -1

387 lines not on this page · raw message

Signature · 1 line
2.25.4
author
#3 lore raw

PATCH v3 4/5 dump.erofs: add -i options to dump file information of specific inode number

In reply to Guo Xuenan

From: Wang Qi <[email protected]>

---
 dump/main.c | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 158 insertions(+), 1 deletion(-)
dump/main.c +158 -1
index be18ddd..e2ceee3 100644
@@ -19,8 +19,10 @@
 
 struct dumpcfg {
 	bool print_superblock;
+	bool print_inode;
 	bool print_statistic;
 	bool print_version;
+	u64 ino;
 };
 static struct dumpcfg dumpcfg;
 
@@ -89,6 +91,7 @@ static void usage(void)
 	fputs("usage: [options] IMAGE\n\n"
 		"Dump erofs layout from IMAGE, and [options] are:\n"
 		"-s      print information about superblock\n"
+		"-i #    print target # inode info\n"
 		"-S      print statistic information of the erofs-image\n"
 		"-V      print the version number of dump.erofs and exit.\n"
 		"--help  display this help and exit.\n",
@@ -102,10 +105,16 @@ static void dumpfs_print_version(void)
 static int dumpfs_parse_options_cfg(int argc, char **argv)
 {
 	int opt;
+	u64 i;
 
-	while ((opt = getopt_long(argc, argv, "sSV",
+	while ((opt = getopt_long(argc, argv, "i:sSV",
 					long_options, NULL)) != -1) {
 		switch (opt) {
+		case 'i':
+			i = atoll(optarg);
+			dumpcfg.print_inode = true;
+			dumpcfg.ino = i;
+			break;
 		case 's':
 			dumpcfg.print_superblock = true;
 			break;
@@ -158,6 +167,151 @@ static int get_file_compressed_size(struct erofs_inode *inode,
 	}
 	return 0;
 }
+static int get_path_by_nid(erofs_nid_t nid, erofs_nid_t parent_nid,
+		erofs_nid_t target, char *path, unsigned int pos)
+{
+	int err;
+	struct erofs_inode inode = {.nid = nid};
+	erofs_off_t offset;
+	char buf[EROFS_BLKSIZ];
+
+	path[pos++] = '/';
+	if (target == sbi.root_nid)
+		return 0;
+
+	err = erofs_read_inode_from_disk(&inode);
+	if (err) {
+		erofs_err("read inode %lu failed", nid);
+		return err;
+	}
+
+	offset = 0;
+	while (offset < inode.i_size) {
+		erofs_off_t maxsize = min_t(erofs_off_t,
+					inode.i_size - offset, EROFS_BLKSIZ);
+		struct erofs_dirent *de = (void *)buf;
+		struct erofs_dirent *end;
+		unsigned int nameoff;
+
+		err = erofs_pread(&inode, buf, maxsize, offset);
+		if (err)
+			return err;
+
+		nameoff = le16_to_cpu(de->nameoff);
+		if (nameoff < sizeof(struct erofs_dirent) ||
+		    nameoff >= PAGE_SIZE) {
+			erofs_err("invalid de[0].nameoff %u @ nid %llu",
+				  nameoff, nid | 0ULL);
+			return -EFSCORRUPTED;
+		}
+
+		end = (void *)buf + nameoff;
+		while (de < end) {
+			const char *dname;
+			unsigned int dname_len;
+
+			nameoff = le16_to_cpu(de->nameoff);
+			dname = (char *)buf + nameoff;
+			if (de + 1 >= end)
+				dname_len = strnlen(dname, maxsize - nameoff);
+			else
+				dname_len = le16_to_cpu(de[1].nameoff)
+					- nameoff;
+
+			/* a corrupted entry is found */
+			if (nameoff + dname_len > maxsize ||
+			    dname_len > EROFS_NAME_LEN) {
+				erofs_err("bogus dirent @ nid %llu",
+						le64_to_cpu(de->nid) | 0ULL);
+				DBG_BUGON(1);
+				return -EFSCORRUPTED;
+			}
+
+			if (de->nid == target) {
+				memcpy(path + pos, dname, dname_len);
+				return 0;
+			}
+
+			if (de->file_type == EROFS_FT_DIR &&
+					de->nid != parent_nid &&
+					de->nid != nid) {
+				memcpy(path + pos, dname, dname_len);
+				err = get_path_by_nid(de->nid, nid,
+						target, path, pos + dname_len);
+				if (!err)
+					return 0;
+				memset(path + pos, 0, dname_len);
+			}
+			++de;
+		}
+		offset += maxsize;
+	}
+	return -1;
+}
+
+static void dumpfs_print_inode(void)
+{
+	int err;
+	erofs_off_t size;
+	u16 access_mode;
+	time_t t;
+	erofs_nid_t nid = dumpcfg.ino;
+	struct erofs_inode inode = {.nid = nid};
+	char path[PATH_MAX + 1] = {0};
+	char access_mode_str[] = "rwxrwxrwx";
+
+	err = erofs_read_inode_from_disk(&inode);
+	if (err) {
+		erofs_err("read inode %lu from disk failed", nid);
+		return;
+	}
+
+	err = get_file_compressed_size(&inode, &size);
+	if (err) {
+		erofs_err("get file size failed\n");
+		return;
+	}
+
+	fprintf(stdout, "Inode %lu info:\n", dumpcfg.ino);
+	err = get_path_by_nid(sbi.root_nid, sbi.root_nid, nid, path, 0);
+
+	fprintf(stdout, "File path:            %s\n",
+			!err ? path : "path not found");
+	fprintf(stdout, "File nid:             %lu\n", inode.nid);
+	fprintf(stdout, "File inode core size: %d\n", inode.inode_isize);
+	fprintf(stdout, "File original size:   %lu\n", inode.i_size);
+	fprintf(stdout,	"File on-disk size:    %lu\n", size);
+	fprintf(stdout, "File compress rate:   %.2f%%\n",
+			(double)(100 * size) / (double)(inode.i_size));
+	fprintf(stdout, "File extent size:     %u\n", inode.extent_isize);
+	fprintf(stdout,	"File xattr size:      %u\n", inode.xattr_isize);
+	fprintf(stdout, "File type:            ");
+	switch (inode.i_mode & S_IFMT) {
+	case S_IFBLK:  fprintf(stdout, "block device\n");     break;
+	case S_IFCHR:  fprintf(stdout, "character device\n"); break;
+	case S_IFDIR:  fprintf(stdout, "directory\n");        break;
+	case S_IFIFO:  fprintf(stdout, "FIFO/pipe\n");        break;
+	case S_IFLNK:  fprintf(stdout, "symlink\n");          break;
+	case S_IFREG:  fprintf(stdout, "regular file\n");     break;
+	case S_IFSOCK: fprintf(stdout, "socket\n");           break;
+	default:       fprintf(stdout, "unknown?\n");         break;
+	}
+
+	access_mode = inode.i_mode & 0777;
+	t = inode.i_ctime;
+	for (int i = 8; i >= 0; i--)
+		if (((access_mode >> i) & 1) == 0)
+			access_mode_str[8 - i] = '-';
+	fprintf(stdout, "File access:          %04o/%s\n",
+			access_mode, access_mode_str);
+	fprintf(stdout, "File uid:             %u\n", inode.i_uid);
+	fprintf(stdout, "File gid:             %u\n", inode.i_gid);
+	fprintf(stdout, "File datalayout:      %d\n", inode.datalayout);
+	fprintf(stdout,	"File nlink:           %u\n", inode.i_nlink);
+	fprintf(stdout, "File create time:     %s", ctime(&t));
+	fprintf(stdout, "File access time:     %s", ctime(&t));
+	fprintf(stdout, "File modify time:     %s", ctime(&t));
+}
 
 static int get_file_type(const char *filename)
 {
@@ -496,6 +650,9 @@ int main(int argc, char **argv)
 	if (dumpcfg.print_statistic)
 		dumpfs_print_statistic();
 
+	if (dumpcfg.print_inode)
+		dumpfs_print_inode();
+
 exit:
 	erofs_exit_configure();
 	return err;
Signature · 1 line
2.25.4
author
#4 lore raw

PATCH v3 5/5 dump.erofs: add -I options to dump the layout of a particular inode on disk

In reply to Guo Xuenan

From: Wang Qi <[email protected]>

---
 dump/main.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 86 insertions(+), 2 deletions(-)
dump/main.c +86 -2
index e2ceee3..34a17f9 100644
@@ -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;
 
@@ -92,6 +94,7 @@ static void usage(void)
 		"Dump erofs layout from IMAGE, and [options] are:\n"
 		"-s      print information about superblock\n"
 		"-i #    print target # inode info\n"
+		"-I #    print target # inode on-disk info\n"
 		"-S      print statistic information of the erofs-image\n"
 		"-V      print the version number of dump.erofs and exit.\n"
 		"--help  display this help and exit.\n",
@@ -107,7 +110,7 @@ static int dumpfs_parse_options_cfg(int argc, char **argv)
 	int opt;
 	u64 i;
 
-	while ((opt = getopt_long(argc, argv, "i:sSV",
+	while ((opt = getopt_long(argc, argv, "i:I:sSV",
 					long_options, NULL)) != -1) {
 		switch (opt) {
 		case 'i':
@@ -115,6 +118,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 's':
 			dumpcfg.print_superblock = true;
 			break;
@@ -167,6 +175,7 @@ static int get_file_compressed_size(struct erofs_inode *inode,
 	}
 	return 0;
 }
+
 static int get_path_by_nid(erofs_nid_t nid, erofs_nid_t parent_nid,
 		erofs_nid_t target, char *path, unsigned int pos)
 {
@@ -249,6 +258,78 @@ static int get_path_by_nid(erofs_nid_t nid, erofs_nid_t parent_nid,
 	return -1;
 }
 
+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;
+	unsigned int extent_count;
+	struct erofs_map_blocks map = {
+		.index = UINT_MAX,
+		.m_la = 0,
+	};
+
+	fprintf(stdout, "Inode %lu on-disk info:\n", nid);
+	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");
+	fprintf(stdout, "File size: %lu\n", inode.i_size);
+
+	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(stdout, "Plain blknr: %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, 0);
+		if (err)
+			erofs_err("get file blocks range failed");
+
+		start = erofs_blknr(map.m_pa);
+		end = start - 1 + blocks;
+		fprintf(stdout,
+				"Compressed blknr: %u - %u\n", start, end);
+		extent_count = 0;
+		map.m_la = 0;
+		while (map.m_la < inode.i_size) {
+			err = z_erofs_map_blocks_iter(&inode, &map,
+					EROFS_GET_BLOCKS_FIEMAP);
+			fprintf(stdout, "Extent %u:\n", extent_count++);
+			fprintf(stdout, "on-disk blkaddr/length: 0x%08lx/0x%04lx\n",
+					map.m_pa, map.m_plen);
+			fprintf(stdout, "logical offset/length:  0x%08lx/0x%04lx\n",
+					map.m_la, map.m_llen);
+			map.m_la += map.m_llen;
+		}
+
+		break;
+	}
+}
+
 static void dumpfs_print_inode(void)
 {
 	int err;
@@ -272,7 +353,7 @@ static void dumpfs_print_inode(void)
 		return;
 	}
 
-	fprintf(stdout, "Inode %lu info:\n", dumpcfg.ino);
+	fprintf(stdout, "Inode %lu on-disk info:\n", dumpcfg.ino);
 	err = get_path_by_nid(sbi.root_nid, sbi.root_nid, nid, path, 0);
 
 	fprintf(stdout, "File path:            %s\n",
@@ -653,6 +734,9 @@ int main(int argc, char **argv)
 	if (dumpcfg.print_inode)
 		dumpfs_print_inode();
 
+	if (dumpcfg.print_inode_phy)
+		dumpfs_print_inode_phy();
+
 exit:
 	erofs_exit_configure();
 	return err;
Signature · 1 line
2.25.4
#5 lore raw
In reply to Guo Xuenan

Hi Xuenan and Qi,

Quoted 7 lines · Guo Xuenan

From: Wang Qi <[email protected]>

Add dump-tool for erofs to facilitate users directly analyzing the erofs image file.

I'm almost fine with the series, and I will merge some of the patches later.

Due to busy work, my original plan was to fix some nits by myself and apply. Anyway, I will reply some comments this evening...

Thanks,
Gao Xiang

Quoted 213 lines
---
 Makefile.am        |  2 +-
 configure.ac       |  1 +
 dump/Makefile.am   |  8 +++++
 dump/main.c        | 81 ++++++++++++++++++++++++++++++++++++++++++++++
 include/erofs/io.h |  3 ++
 lib/config.c       |  3 ++
 lib/namei.c        |  5 ++-
 7 files changed, 99 insertions(+), 4 deletions(-)
 create mode 100644 dump/Makefile.am
 create mode 100644 dump/main.c
Makefile.am +1 -1
index b804aa9..fedf7b5 100644
@@ -3,7 +3,7 @@
 
 ACLOCAL_AMFLAGS = -I m4
 
-SUBDIRS = man lib mkfs
+SUBDIRS = man lib mkfs dump
 if ENABLE_FUSE
 SUBDIRS += fuse
 endif
configure.ac +1 -0
index f626064..81c493a 100644
@@ -280,6 +280,7 @@ AC_CONFIG_FILES([Makefile
 		 man/Makefile
 		 lib/Makefile
 		 mkfs/Makefile
+		 dump/Makefile
 		 fuse/Makefile])
 AC_OUTPUT
 
dump/Makefile.am new file +8 -0
new file mode 100644
index 0000000..3d8a32c
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Makefile.am
+
+AUTOMAKE_OPTIONS = foreign
+bin_PROGRAMS     = dump.erofs
+dump_erofs_SOURCES = main.c
+dump_erofs_CFLAGS = -Wall -Werror -I$(top_srcdir)/include
+dump_erofs_LDADD = $(top_builddir)/lib/liberofs.la
\ No newline at end of file
dump/main.c new file +81 -0
new file mode 100644
index 0000000..af8db4b
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2021-2022 HUAWEI, Inc.
+ *             http://www.huawei.com/
+ * Created by Wang Qi <[email protected]>
+ *            Guo Xuenan <[email protected]>
+ */
+
+#include <stdlib.h>
+#include <getopt.h>
+#include <sys/sysmacros.h>
+#include <time.h>
+#include "erofs/print.h"
+#include "erofs/io.h"
+
+static struct option long_options[] = {
+	{"help", no_argument, 0, 1},
+	{0, 0, 0, 0},
+};
+
+static void usage(void)
+{
+	fputs("usage: [options] IMAGE\n\n"
+		"Dump erofs layout from IMAGE, and [options] are:\n"
+		"-V      print the version number of dump.erofs and exit.\n"
+		"--help  display this help and exit.\n",
+		stderr);
+}
+static void dumpfs_print_version(void)
+{
+	fprintf(stderr, "dump.erofs %s\n", cfg.c_version);
+}
+
+static int dumpfs_parse_options_cfg(int argc, char **argv)
+{
+	int opt;
+
+	while ((opt = getopt_long(argc, argv, "V",
+					long_options, NULL)) != -1) {
+		switch (opt) {
+		case 'V':
+			dumpfs_print_version();
+			exit(0);
+		case 1:
+			usage();
+			exit(0);
+		default:
+			return -EINVAL;
+		}
+	}
+
+	if (optind >= argc)
+		return -EINVAL;
+
+	cfg.c_img_path = strdup(argv[optind++]);
+	if (!cfg.c_img_path)
+		return -ENOMEM;
+
+	if (optind < argc) {
+		erofs_err("unexpected argument: %s\n", argv[optind]);
+		return -EINVAL;
+	}
+	return 0;
+}
+
+int main(int argc, char **argv)
+{
+	int err = 0;
+
+	erofs_init_configure();
+	err = dumpfs_parse_options_cfg(argc, argv);
+	if (err) {
+		if (err == -EINVAL)
+			usage();
+		goto exit;
+	}
+
+exit:
+	erofs_exit_configure();
+	return err;
+}
include/erofs/io.h +3 -0
index 5574245..00e5de8 100644
@@ -10,6 +10,7 @@
 #define __EROFS_IO_H
 
 #include <unistd.h>
+#include <sys/types.h>
 #include "internal.h"
 
 #ifndef O_BINARY
@@ -25,6 +26,8 @@ int dev_fillzero(u64 offset, size_t len, bool padding);
 int dev_fsync(void);
 int dev_resize(erofs_blk_t nblocks);
 u64 dev_length(void);
+dev_t erofs_new_decode_dev(u32 dev);
+int erofs_read_inode_from_disk(struct erofs_inode *vi);
 
 static inline int blk_write(const void *buf, erofs_blk_t blkaddr,
 			    u32 nblocks)
lib/config.c +3 -0
index 99fcf49..405fae6 100644
@@ -7,6 +7,7 @@
  * Created by Li Guifu <[email protected]>
  */
 #include <string.h>
+#include <stdlib.h>
 #include "erofs/print.h"
 #include "erofs/internal.h"
 
@@ -45,6 +46,8 @@ void erofs_exit_configure(void)
 	if (cfg.sehnd)
 		selabel_close(cfg.sehnd);
 #endif
+	if (cfg.c_img_path)
+		free(cfg.c_img_path);
 }
 
 static unsigned int fullpath_prefix;	/* root directory prefix length */
lib/namei.c +2 -3
index 4e06ba4..b45e9d8 100644
@@ -5,7 +5,6 @@
  * Created by Li Guifu <[email protected]>
  */
 #include <linux/kdev_t.h>
-#include <sys/types.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <errno.h>
@@ -15,7 +14,7 @@
 #include "erofs/print.h"
 #include "erofs/io.h"
 
-static dev_t erofs_new_decode_dev(u32 dev)
+dev_t erofs_new_decode_dev(u32 dev)
 {
 	const unsigned int major = (dev & 0xfff00) >> 8;
 	const unsigned int minor = (dev & 0xff) | ((dev >> 12) & 0xfff00);
@@ -23,7 +22,7 @@ static dev_t erofs_new_decode_dev(u32 dev)
 	return makedev(major, minor);
 }
 
-static int erofs_read_inode_from_disk(struct erofs_inode *vi)
+int erofs_read_inode_from_disk(struct erofs_inode *vi)
 {
 	int ret, ifmt;
 	char buf[sizeof(struct erofs_inode_extended)];
Signature · 1 line
2.25.4
#6 lore raw

Hi,

Quoted 8 lines · Gao Xiang

Hi Xuenan and Qi,

Quoted 5 lines · Guo Xuenan

From: Wang Qi <[email protected]>

Add dump-tool for erofs to facilitate users directly analyzing the erofs image file.

Quoted 8 lines
Quoted 2 lines

I'm almost fine with the series, and I will merge some of the patches later.

Due to busy work, my original plan was to fix some nits by myself and apply. Anyway, I will reply some comments this evening...

I've merged the first 2 patches into dev branch with modification (so no need to resend the first two patches).

The rest patches are still a bit messy, I've set up a new experimental-dump branch, please check out:
https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/?h=experimental-dump

There are some stuffs needing to be resolved in advance:
1) rename all "dumpfs_" prefix into "erofsdump_";
2) I feel still uncomfortable when reading get_path_by_nid() and erofs_read_dir(). Could we refactor them by introducing erofs_for_each_dir() or likewise?
3) file_category_types and the switch in dumpfs_print_inode() are duplicated to me. I think one of them can be removed instead.
4) please help using "filefrag -v -b1" style when printing extent info in erofsdump_show_inode_phy(), like below:

ext: logical_offset: physical_offset: length: expected: flags:
0: 0.. 20479: 21788270592..21788291071: 20480: last,eof

Thanks,
Gao Xiang

#7 lore raw

Hi,

Quoted 35 lines · Gao Xiang

Hi,

Quoted 8 lines · Gao Xiang

Hi Xuenan and Qi,

Quoted 5 lines · Guo Xuenan

From: Wang Qi<[email protected]>

Add dump-tool for erofs to facilitate users directly analyzing the erofs image file.

Quoted 7 lines
Quoted 2 lines

I'm almost fine with the series, and I will merge some of the patches later.

Due to busy work, my original plan was to fix some nits by myself and apply. Anyway, I will reply some comments this evening...

I've merged the first 2 patches into dev branch with modification (so no need to resend the first two patches).

The rest patches are still a bit messy, I've set up a new experimental-dump branch, please check out:
https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/?h=experimental-dump

There are some stuffs needing to be resolved in advance:
1) rename all "dumpfs_" prefix into "erofsdump_";
2) I feel still uncomfortable when reading get_path_by_nid() and erofs_read_dir(). Could we refactor them by introducing erofs_for_each_dir() or likewise?
3) file_category_types and the switch in dumpfs_print_inode() are duplicated to me. I think one of them can be removed instead.
4) please help using "filefrag -v -b1" style when printing extent info in erofsdump_show_inode_phy(), like below:

Quoted 6 lines

ext: logical_offset: physical_offset: length: expected: flags:

    0:        0..   20479: 21788270592..21788291071:  20480:             last,eof

Thanks,
Gao Xiang

Thanks for your reply! I will refactor the code according to your advice.

Thanks,
Wang Qi

#8 lore raw

Hi Qi,

Quoted 38 lines · Qi Wang

Hi,

Quoted 35 lines · Gao Xiang

Hi,

Quoted 8 lines · Gao Xiang

Hi Xuenan and Qi,

Quoted 5 lines · Guo Xuenan

From: Wang Qi<[email protected]>

Add dump-tool for erofs to facilitate users directly analyzing the erofs image file.

Quoted 7 lines
Quoted 2 lines

I'm almost fine with the series, and I will merge some of the patches later.

Due to busy work, my original plan was to fix some nits by myself and apply. Anyway, I will reply some comments this evening...

I've merged the first 2 patches into dev branch with modification (so no need to resend the first two patches).

The rest patches are still a bit messy, I've set up a new experimental-dump branch, please check out:
https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/?h=experimental-dump

There are some stuffs needing to be resolved in advance:
1) rename all "dumpfs_" prefix into "erofsdump_";
2) I feel still uncomfortable when reading get_path_by_nid() and erofs_read_dir(). Could we refactor them by introducing erofs_for_each_dir() or likewise?
3) file_category_types and the switch in dumpfs_print_inode() are duplicated to me. I think one of them can be removed instead.
4) please help using "filefrag -v -b1" style when printing extent info in erofsdump_show_inode_phy(), like below:

Quoted 7 lines
Quoted 6 lines

ext: logical_offset: physical_offset: length: expected: flags:

    0:        0..   20479: 21788270592..21788291071:  20480:             last,eof

Thanks,
Gao Xiang

Thanks for your reply! I will refactor the code according to your advice.

Nice! Many thanks for your time and contribution! :)

Thanks,
Gao Xiang

Quoted 3 lines

Thanks,
Wang Qi