lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180219095447.11757-5-viktor.prutyanov@virtuozzo.com>
Date:   Mon, 19 Feb 2018 12:54:46 +0300
From:   Viktor Prutyanov <viktor.prutyanov@...tuozzo.com>
To:     linux-ext4@...r.kernel.org
Cc:     Theodore Ts'o <tytso@....edu>,
        Dmitry Monakhov <dmonakhov@...nvz.org>,
        Viktor Prutyanov <viktor.prutyanov@...tuozzo.com>
Subject: [PATCH 4/5] dumpe2fs: add JSON output of journal

This patch adds JSON output of journal information

Signed-off-by: Viktor Prutyanov <viktor.prutyanov@...tuozzo.com>
---
 lib/e2p/e2p.h   |  2 ++
 lib/e2p/ljs.c   | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 misc/dumpe2fs.c | 28 +++++++++++++++++++---------
 3 files changed, 78 insertions(+), 9 deletions(-)

diff --git a/lib/e2p/e2p.h b/lib/e2p/e2p.h
index 88c08d73..cd3793e5 100644
--- a/lib/e2p/e2p.h
+++ b/lib/e2p/e2p.h
@@ -83,3 +83,5 @@ int e2p_string2os(char *str);
 unsigned int e2p_percent(int percent, unsigned int base);
 
 void fill_json_super(struct json_obj *obj, struct ext2_super_block * s);
+void e2p_fill_json_journal_super(struct json_obj *obj, char *journal_sb_buf,
+			    int exp_block_size, int flags);
diff --git a/lib/e2p/ljs.c b/lib/e2p/ljs.c
index 2db700b0..c75610b8 100644
--- a/lib/e2p/ljs.c
+++ b/lib/e2p/ljs.c
@@ -111,3 +111,60 @@ void e2p_list_journal_super(FILE *f, char *journal_sb_buf,
 		fprintf(f, "Journal errno:            %d\n",
 			(int) ntohl(jsb->s_errno));
 }
+
+void e2p_fill_json_journal_super(struct json_obj *obj, char *journal_sb_buf,
+			    int exp_block_size, int flags)
+{
+	journal_superblock_t *jsb = (journal_superblock_t *) journal_sb_buf;
+	__u32 *mask_ptr, mask, m;
+	unsigned int size;
+	int i, j, printed = 0;
+	unsigned int nr_users;
+	struct json_obj *journal_obj = json_obj_create_in_obj(obj, "journal");
+	struct json_list *features_list, *users_list;
+	char buf[64];
+
+	features_list = json_list_create_in_obj(journal_obj, "journal-features", JSON_VAL_STRING);
+	for (i=0, mask_ptr=&jsb->s_feature_compat; i <3; i++,mask_ptr++) {
+		mask = e2p_be32(*mask_ptr);
+		for (j=0,m=1; j < 32; j++, m<<=1) {
+			if (mask & m)
+				json_list_add_str(features_list, e2p_jrnl_feature2string(i, m));
+		}
+	}
+	size = (ntohl(jsb->s_blocksize) / 1024) * ntohl(jsb->s_maxlen);
+	if (size < 8192)
+		json_obj_add_fmt_buf_str(journal_obj, "journal-size", buf, sizeof(buf), "%uk", size);
+	else
+		json_obj_add_fmt_buf_str(journal_obj, "journal-size", buf, sizeof(buf), "%uM", size >> 10);
+	nr_users = (unsigned int) ntohl(jsb->s_nr_users);
+	if (exp_block_size != ntohl(jsb->s_blocksize))
+		json_obj_add_fmt_buf_str(journal_obj, "journal-block-size", buf, sizeof(buf), "%u",
+			(unsigned int)ntohl(jsb->s_blocksize));
+	json_obj_add_fmt_buf_str(journal_obj, "journal-length", buf, sizeof(buf), "%u",
+		(unsigned int)ntohl(jsb->s_maxlen));
+	if (ntohl(jsb->s_first) != 1)
+		json_obj_add_fmt_buf_str(journal_obj, "journal-first-block", buf, sizeof(buf), "%u",
+			(unsigned int)ntohl(jsb->s_first));
+	json_obj_add_fmt_buf_str(journal_obj, "journal-sequence", buf, sizeof(buf), "0x%08x", (unsigned int)ntohl(jsb->s_sequence));
+	json_obj_add_fmt_buf_str(journal_obj, "journal-start", buf, sizeof(buf), "%u", (unsigned int)ntohl(jsb->s_start));
+	if (nr_users != 1)
+		json_obj_add_fmt_buf_str(journal_obj, "journal-number-of-users", buf, sizeof(buf), "%u", nr_users);
+	if (jsb->s_feature_compat & e2p_be32(JFS_FEATURE_COMPAT_CHECKSUM))
+		json_obj_add_str(journal_obj, "journal-checksum-type", "crc32");
+	if ((jsb->s_feature_incompat &
+	     e2p_be32(JFS_FEATURE_INCOMPAT_CSUM_V3)) ||
+	    (jsb->s_feature_incompat &
+	     e2p_be32(JFS_FEATURE_INCOMPAT_CSUM_V2))) {
+		json_obj_add_str(journal_obj, "journal-checksum-type", journal_checksum_type_str(jsb->s_checksum_type));
+		json_obj_add_fmt_buf_str(journal_obj, "journal-checksum", buf, sizeof(buf), "0x%08x", e2p_be32(jsb->s_checksum));
+	}
+	if ((nr_users > 1) ||
+	    !e2p_is_null_uuid(&jsb->s_users[0])) {
+		users_list = json_list_create_in_obj(journal_obj, "journal-users", JSON_VAL_STRING);
+		for (i=0; i < nr_users; i++)
+			json_list_add_str(users_list, e2p_uuid2str(&jsb->s_users[i*16]));
+	}
+	if (jsb->s_errno != 0)
+		json_obj_add_fmt_buf_str(journal_obj, "journal-errno", buf, sizeof(buf), "%d", (int) ntohl(jsb->s_errno));
+}
diff --git a/misc/dumpe2fs.c b/misc/dumpe2fs.c
index bddd7377..b8bf0ec6 100644
--- a/misc/dumpe2fs.c
+++ b/misc/dumpe2fs.c
@@ -595,7 +595,7 @@ static void list_bad_blocks(ext2_filsys fs, int dump)
 	ext2fs_badblocks_list_free(bb_list);
 }
 
-static void print_inline_journal_information(ext2_filsys fs)
+static void print_inline_journal_information(ext2_filsys fs, struct json_obj *obj)
 {
 	journal_superblock_t	*jsb;
 	struct ext2_inode	inode;
@@ -631,10 +631,13 @@ static void print_inline_journal_information(ext2_filsys fs)
 			_("Journal superblock magic number invalid!\n"));
 		exit(1);
 	}
-	e2p_list_journal_super(stdout, buf, fs->blocksize, 0);
+	if (obj)
+		e2p_fill_json_journal_super(obj, buf, fs->blocksize, 0);
+	else
+		e2p_list_journal_super(stdout, buf, fs->blocksize, 0);
 }
 
-static void print_journal_information(ext2_filsys fs)
+static void print_journal_information(ext2_filsys fs, struct json_obj *obj)
 {
 	errcode_t	retval;
 	char		buf[1024];
@@ -656,7 +659,10 @@ static void print_journal_information(ext2_filsys fs)
 			_("Couldn't find journal superblock magic numbers"));
 		exit(1);
 	}
-	e2p_list_journal_super(stdout, buf, fs->blocksize, 0);
+	if (obj)
+		e2p_fill_json_journal_super(obj, buf, fs->blocksize, 0);
+	else
+		e2p_list_journal_super(stdout, buf, fs->blocksize, 0);
 }
 
 static void parse_extended_opts(const char *opts, blk64_t *superblock,
@@ -750,7 +756,7 @@ int main (int argc, char ** argv)
 	int		c;
 	int		grp_only = 0;
 	int		json = 0;
-	struct json_obj *dump_obj;
+	struct json_obj *dump_obj = NULL;
 
 #ifdef ENABLE_NLS
 	setlocale(LC_MESSAGES, "");
@@ -855,14 +861,18 @@ try_open_again:
 			fill_json_super(dump_obj, fs->super);
 		else
 			list_super (fs->super);
-		if (!json && ext2fs_has_feature_journal_dev(fs->super)) {
-			print_journal_information(fs);
+		if (ext2fs_has_feature_journal_dev(fs->super)) {
+			print_journal_information(fs, dump_obj);
+			if (json) {
+				json_obj_print_json(dump_obj);
+				json_obj_delete(dump_obj);
+			}
 			ext2fs_close_free(&fs);
 			exit(0);
 		}
-		if (!json && ext2fs_has_feature_journal(fs->super) &&
+		if (ext2fs_has_feature_journal(fs->super) &&
 		    (fs->super->s_journal_inum != 0))
-			print_inline_journal_information(fs);
+			print_inline_journal_information(fs, dump_obj);
 		if (!json)
 			list_bad_blocks(fs, 0);
 		if (header_only) {
-- 
2.14.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ