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 v3 2/5] dump.erofs: add "-s" option to dump superblock information
Date: Wed, 15 Sep 2021 17:35:34 +0800	[thread overview]
Message-ID: <20210915093537.2579575-2-guoxuenan@huawei.com> (raw)
In-Reply-To: <20210915093537.2579575-1-guoxuenan@huawei.com>

From: Wang Qi <mpiglet@outlook.com>

Signed-off-by: Guo Xuenan <guoxuenan@huawei.com>
Signed-off-by: Wang Qi <mpiglet@outlook.com>
---
 dump/Makefile.am |  3 +-
 dump/main.c      | 77 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 78 insertions(+), 2 deletions(-)

diff --git a/dump/Makefile.am b/dump/Makefile.am
index 3d8a32c..0bb7b4e 100644
--- a/dump/Makefile.am
+++ b/dump/Makefile.am
@@ -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
diff --git a/dump/main.c b/dump/main.c
index af8db4b..7ece596 100644
--- a/dump/main.c
+++ b/dump/main.c
@@ -13,15 +13,38 @@
 #include "erofs/print.h"
 #include "erofs/io.h"
 
+#ifdef HAVE_LIBUUID
+#include <uuid.h>
+#endif
+
+struct dumpcfg {
+	bool print_superblock;
+	bool print_version;
+};
+static struct dumpcfg dumpcfg;
+
 static struct option long_options[] = {
 	{"help", no_argument, 0, 1},
 	{0, 0, 0, 0},
 };
 
+struct feature {
+	bool compat;
+	__le32 flag;
+	const char *name;
+};
+
+static struct feature feature_lists[] = {
+	{ true, EROFS_FEATURE_COMPAT_SB_CHKSUM, "sb_csum" },
+	{ false, EROFS_FEATURE_INCOMPAT_LZ4_0PADDING, "0padding" },
+	{ false, EROFS_FEATURE_INCOMPAT_BIG_PCLUSTER, "bigpcluster" },
+};
+
 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"
 		"-V      print the version number of dump.erofs and exit.\n"
 		"--help  display this help and exit.\n",
 		stderr);
@@ -35,9 +58,12 @@ static int dumpfs_parse_options_cfg(int argc, char **argv)
 {
 	int opt;
 
-	while ((opt = getopt_long(argc, argv, "V",
+	while ((opt = getopt_long(argc, argv, "sV",
 					long_options, NULL)) != -1) {
 		switch (opt) {
+		case 's':
+			dumpcfg.print_superblock = true;
+			break;
 		case 'V':
 			dumpfs_print_version();
 			exit(0);
@@ -63,6 +89,40 @@ static int dumpfs_parse_options_cfg(int argc, char **argv)
 	return 0;
 }
 
+static void dumpfs_print_superblock(void)
+{
+	time_t time = sbi.build_time;
+	char uuid_str[37] = "not available";
+	int i = 0;
+
+	fprintf(stdout, "Filesystem magic number:                      0x%04X\n",
+			EROFS_SUPER_MAGIC_V1);
+	fprintf(stdout, "Filesystem blocks:                            %lu\n",
+			sbi.blocks);
+	fprintf(stdout, "Filesystem inode metadata start block:        %u\n",
+			sbi.meta_blkaddr);
+	fprintf(stdout, "Filesystem shared xattr metadata start block: %u\n",
+			sbi.xattr_blkaddr);
+	fprintf(stdout, "Filesystem root nid:                          %ld\n",
+			sbi.root_nid);
+	fprintf(stdout, "Filesystem inode count:                       %lu\n",
+			sbi.inos);
+	fprintf(stdout, "Filesystem created:                           %s",
+			ctime(&time));
+	fprintf(stdout, "Filesystem features:                          ");
+	for (; i < ARRAY_SIZE(feature_lists); i++) {
+		__le32 feature = feature_lists[i].compat ?
+			sbi.feature_compat : sbi.feature_incompat;
+		if (feature & feature_lists[i].flag)
+			fprintf(stdout, "%s ", feature_lists[i].name);
+	}
+#ifdef HAVE_LIBUUID
+	uuid_unparse_lower(sbi.uuid, uuid_str);
+#endif
+	fprintf(stdout, "\nFilesystem UUID:                              %s\n",
+			uuid_str);
+}
+
 int main(int argc, char **argv)
 {
 	int err = 0;
@@ -75,6 +135,21 @@ int main(int argc, char **argv)
 		goto exit;
 	}
 
+	err = dev_open_ro(cfg.c_img_path);
+	if (err) {
+		erofs_err("open image file failed");
+		goto exit;
+	}
+
+	err = erofs_read_superblock();
+	if (err) {
+		erofs_err("read superblock failed");
+		goto exit;
+	}
+
+	if (dumpcfg.print_superblock)
+		dumpfs_print_superblock();
+
 exit:
 	erofs_exit_configure();
 	return err;
-- 
2.25.4


  reply	other threads:[~2021-09-15  9:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-15  9:35 [PATCH v3 1/5] erofs-utils: introduce dump.erofs Guo Xuenan
2021-09-15  9:35 ` Guo Xuenan [this message]
2021-09-15  9:35 ` [PATCH v3 3/5] dump.erofs: add -S options for collecting statistics of the whole filesystem Guo Xuenan
2021-09-15  9:35 ` [PATCH v3 4/5] dump.erofs: add -i options to dump file information of specific inode number Guo Xuenan
2021-09-15  9:35 ` [PATCH v3 5/5] dump.erofs: add -I options to dump the layout of a particular inode on disk Guo Xuenan
2021-09-26  3:21 ` [PATCH v3 1/5] erofs-utils: introduce dump.erofs Gao Xiang
2021-09-28  2:33   ` Gao Xiang
2021-09-28  6:23     ` Qi Wang
2021-09-28  7:54       ` 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=20210915093537.2579575-2-guoxuenan@huawei.com \
    --to=guoxuenan@huawei.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=mpiglet@outlook.com \
    --cc=xiang@kernel.org \
    --subject='Re: [PATCH v3 2/5] dump.erofs: add "-s" option to dump superblock information' \
    /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).