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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180219145840.21657-6-viktor.prutyanov@virtuozzo.com>
Date:   Mon, 19 Feb 2018 17:58:40 +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 v2 5/5] dumpe2fs: add JSON output of bad blocks

This patch adds output of bad blocks list in JSON format

Signed-off-by: Viktor Prutyanov <viktor.prutyanov@...tuozzo.com>
---
 misc/dumpe2fs.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/misc/dumpe2fs.c b/misc/dumpe2fs.c
index 58362ec2..d348d2bd 100644
--- a/misc/dumpe2fs.c
+++ b/misc/dumpe2fs.c
@@ -572,14 +572,19 @@ static void fill_json_desc(struct json_obj *obj, ext2_filsys fs)
 		free(inode_bitmap);
 }
 
-static void list_bad_blocks(ext2_filsys fs, int dump)
+static void list_bad_blocks(ext2_filsys fs, int dump, struct json_obj *obj)
 {
 	badblocks_list		bb_list = 0;
 	badblocks_iterate	bb_iter;
 	blk_t			blk;
 	errcode_t		retval;
 	const char		*header, *fmt;
+	struct json_list	*bb_json_list = NULL;
+	char	buf[32];
 
+	if (obj)
+		bb_json_list = json_list_create_in_obj(obj, "bad-blocks",
+			                                   JSON_VAL_STRING);
 	retval = ext2fs_read_bb_inode(fs, &bb_list);
 	if (retval) {
 		com_err("ext2fs_read_bb_inode", retval, 0);
@@ -598,11 +603,16 @@ static void list_bad_blocks(ext2_filsys fs, int dump)
 		fmt = ", %u";
 	}
 	while (ext2fs_badblocks_list_iterate(bb_iter, &blk)) {
+		if (bb_json_list) {
+			snprintf(buf, sizeof(buf), "%u", blk);
+			json_list_add_str(bb_json_list, buf);
+			continue;
+		}
 		printf(header ? header : fmt, blk);
 		header = 0;
 	}
 	ext2fs_badblocks_list_iterate_end(bb_iter);
-	if (!dump)
+	if (!dump && !bb_json_list)
 		fputc('\n', stdout);
 	ext2fs_badblocks_list_free(bb_list);
 }
@@ -865,7 +875,7 @@ try_open_again:
 	if (ext2fs_has_feature_64bit(fs->super))
 		blocks64 = 1;
 	if (print_badblocks) {
-		list_bad_blocks(fs, 1);
+		list_bad_blocks(fs, 1, dump_obj);
 	} else {
 		if (grp_only)
 			goto just_descriptors;
@@ -886,8 +896,7 @@ try_open_again:
 		if (ext2fs_has_feature_journal(fs->super) &&
 		    (fs->super->s_journal_inum != 0))
 			print_inline_journal_information(fs, dump_obj);
-		if (!json)
-			list_bad_blocks(fs, 0);
+		list_bad_blocks(fs, 0, dump_obj);
 		if (header_only) {
 			if (json) {
 				json_obj_print_json(dump_obj, 0);
-- 
2.14.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ