linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH 5/9] btrfs-progs: btrfs-corrupt-block: Convert -K flag argument handling to common function
Date: Mon, 14 May 2018 14:13:30 +0300	[thread overview]
Message-ID: <1526296414-27638-6-git-send-email-nborisov@suse.com> (raw)
In-Reply-To: <1526296414-27638-1-git-send-email-nborisov@suse.com>

There is now a common function used to parse btrfs keys triplets so
use that one. No functional changes.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 btrfs-corrupt-block.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index 4cc3528df105..7a5513c455e6 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -114,7 +114,7 @@ static void print_usage(int ret)
 	printf("\t-i   The inode item to corrupt (must also specify the field to corrupt)\n");
 	printf("\t-x   The file extent item to corrupt (must also specify -i for the inode and -f for the field to corrupt)\n");
 	printf("\t-m   The metadata block to corrupt (must also specify -f for the field to corrupt)\n");
-	printf("\t-K   The key to corrupt in the format <num>,<num>,<num> (must also specify -f for the field)\n");
+	printf("\t-K <u64,u8,u64> Corrupt the given key (must also specify -f for the field)\n");
 	printf("\t-f   The field in the item to corrupt\n");
 	printf("\t-I <u64,u8,u64> Corrupt an item corresponding to the passed key triplet (must also specify the field to corrupt and root for the item)\n");
 	printf("\t-D   Corrupt a dir item, must specify key and field\n");
@@ -1129,6 +1129,7 @@ int main(int argc, char **argv)
 	int corrupt_item = 0;
 	int corrupt_di = 0;
 	int delete = 0;
+	int should_corrupt_key = 0;
 	u64 metadata_block = 0;
 	u64 inode = 0;
 	u64 file_extent = (u64)-1;
@@ -1207,15 +1208,8 @@ int main(int argc, char **argv)
 				metadata_block = arg_strtou64(optarg);
 				break;
 			case 'K':
-				ret = sscanf(optarg, "%llu,%u,%llu",
-					     &key.objectid,
-					     (unsigned int *)&key.type,
-					     &key.offset);
-				if (ret != 3) {
-					fprintf(stderr, "error reading key "
-						"%d\n", errno);
-					print_usage(1);
-				}
+				should_corrupt_key = 1;
+				parse_key(&key.objectid, &key.type, &key.offset);
 				break;
 			case 'D':
 				corrupt_di = 1;
@@ -1370,7 +1364,7 @@ int main(int argc, char **argv)
 		ret = delete_item(target, &key);
 		goto out_close;
 	}
-	if (key.objectid || key.offset || key.type) {
+	if (should_corrupt_key) {
 		if (*field == 0)
 			print_usage(1);
 		ret = corrupt_key(root, &key, field);
-- 
2.7.4


  parent reply	other threads:[~2018-05-14 11:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-14 11:13 [PATCH 0/9] Overhaul btrfs-corrupt-block Nikolay Borisov
2018-05-14 11:13 ` [PATCH 1/9] btrfs-progs: btrfs-corrupt-block: Factor out specific-root code Nikolay Borisov
2018-05-14 11:13 ` [PATCH 2/9] btrfs-progs: btrfs-corrupt-block: Correctly handle -r when passing -I Nikolay Borisov
2018-05-14 11:13 ` [PATCH 3/9] btrfs-progs: btrfs-corrupt-block: Factor out key parsing function Nikolay Borisov
2018-05-14 11:13 ` [PATCH 4/9] btrfs-progs: btrfs-corrupt-block: Change -I flag parameter format Nikolay Borisov
2018-05-14 11:13 ` Nikolay Borisov [this message]
2018-05-14 11:13 ` [PATCH 6/9] btrfs-progs: btrfs-corrupt-block: Factor out common "-r" handling code Nikolay Borisov
2018-05-14 11:13 ` [PATCH 7/9] btrfs-progs: btrfs-corrupt-block: Add support for handling specific root when using -K option Nikolay Borisov
2018-05-14 11:13 ` [PATCH 8/9] btrfs-progs: btrfs-corrupt-block: Change format of -d option Nikolay Borisov
2018-05-14 11:13 ` [PATCH 9/9] btrfs-progs: btrfs-corrupt-block: Fix -D option Nikolay Borisov
2018-05-31 12:18 ` [PATCH 0/9] Overhaul btrfs-corrupt-block David Sterba

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=1526296414-27638-6-git-send-email-nborisov@suse.com \
    --to=nborisov@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).