From patchwork Mon May 14 11:13:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 10397965 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 11C3960216 for ; Mon, 14 May 2018 11:13:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0290629109 for ; Mon, 14 May 2018 11:13:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB84A2910A; Mon, 14 May 2018 11:13:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 63C5D2910F for ; Mon, 14 May 2018 11:13:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752407AbeENLN4 (ORCPT ); Mon, 14 May 2018 07:13:56 -0400 Received: from mx2.suse.de ([195.135.220.15]:41120 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752037AbeENLNl (ORCPT ); Mon, 14 May 2018 07:13:41 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B4F80AEFE for ; Mon, 14 May 2018 11:13:40 +0000 (UTC) From: Nikolay Borisov To: linux-btrfs@vger.kernel.org Cc: Nikolay Borisov 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 Message-Id: <1526296414-27638-6-git-send-email-nborisov@suse.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526296414-27638-1-git-send-email-nborisov@suse.com> References: <1526296414-27638-1-git-send-email-nborisov@suse.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is now a common function used to parse btrfs keys triplets so use that one. No functional changes. Signed-off-by: Nikolay Borisov --- 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 ,, (must also specify -f for the field)\n"); + printf("\t-K 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 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);