From patchwork Mon Aug 31 11:03:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaolei X-Patchwork-Id: 7099341 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B37BC9F32B for ; Mon, 31 Aug 2015 11:05:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D1A2C20709 for ; Mon, 31 Aug 2015 11:05:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DD7D520705 for ; Mon, 31 Aug 2015 11:05:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752915AbbHaLFf (ORCPT ); Mon, 31 Aug 2015 07:05:35 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:49679 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752565AbbHaLF1 (ORCPT ); Mon, 31 Aug 2015 07:05:27 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="100195157" Received: from bogon (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 31 Aug 2015 19:08:29 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t7VB5EHh009057 for ; Mon, 31 Aug 2015 19:05:14 +0800 Received: from localhost.localdomain (10.167.226.114) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server id 14.3.181.6; Mon, 31 Aug 2015 19:05:22 +0800 From: Zhao Lei To: CC: Zhao Lei Subject: [PATCH v2 3/4] btrfs-progs: Use common unit parser for btrfs device command Date: Mon, 31 Aug 2015 19:03:43 +0800 Message-ID: X-Mailer: git-send-email 1.8.5.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move to use get_unit_mode_from_arg() for cmds-device.c, to make "btrfs device usage"'s unit argument same with other tools. Signed-off-by: Zhao Lei --- cmds-device.c | 74 ++++++----------------------------------------------------- 1 file changed, 7 insertions(+), 67 deletions(-) diff --git a/cmds-device.c b/cmds-device.c index 844289a..e0f390b 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -474,16 +474,7 @@ out: const char * const cmd_device_usage_usage[] = { "btrfs device usage [options] [..]", "Show detailed information about internal allocations in devices.", - "-b|--raw raw numbers in bytes", - "-h|--human-readable", - " human friendly numbers, base 1024 (default)", - "-H human friendly numbers, base 1000", - "--iec use 1024 as a base (KiB, MiB, GiB, TiB)", - "--si use 1000 as a base (kB, MB, GB, TB)", - "-k|--kbytes show sizes in KiB, or kB with --si", - "-m|--mbytes show sizes in MiB, or MB with --si", - "-g|--gbytes show sizes in GiB, or GB with --si", - "-t|--tbytes show sizes in TiB, or TB with --si", + HELPINFO_OUTPUT_UNIT, NULL }; @@ -518,69 +509,18 @@ out: int cmd_device_usage(int argc, char **argv) { - unsigned unit_mode = UNITS_DEFAULT; + unsigned unit_mode; int ret = 0; - int i, more_than_one = 0; + int i, more_than_one = 0; - optind = 1; - while (1) { - int c; - static const struct option long_options[] = { - { "raw", no_argument, NULL, 'b'}, - { "kbytes", no_argument, NULL, 'k'}, - { "mbytes", no_argument, NULL, 'm'}, - { "gbytes", no_argument, NULL, 'g'}, - { "tbytes", no_argument, NULL, 't'}, - { "si", no_argument, NULL, GETOPT_VAL_SI}, - { "iec", no_argument, NULL, GETOPT_VAL_IEC}, - { "human-readable", no_argument, NULL, - GETOPT_VAL_HUMAN_READABLE}, - { NULL, 0, NULL, 0 } - }; - - c = getopt_long(argc, argv, "bhHkmgt", long_options, NULL); - if (c < 0) - break; - switch (c) { - case 'b': - unit_mode = UNITS_RAW; - break; - case 'k': - units_set_base(&unit_mode, UNITS_KBYTES); - break; - case 'm': - units_set_base(&unit_mode, UNITS_MBYTES); - break; - case 'g': - units_set_base(&unit_mode, UNITS_GBYTES); - break; - case 't': - units_set_base(&unit_mode, UNITS_TBYTES); - break; - case GETOPT_VAL_HUMAN_READABLE: - case 'h': - unit_mode = UNITS_HUMAN_BINARY; - break; - case 'H': - unit_mode = UNITS_HUMAN_DECIMAL; - break; - case GETOPT_VAL_SI: - units_set_mode(&unit_mode, UNITS_DECIMAL); - break; - case GETOPT_VAL_IEC: - units_set_mode(&unit_mode, UNITS_BINARY); - break; - default: - usage(cmd_device_usage_usage); - } - } + unit_mode = get_unit_mode_from_arg(&argc, argv, 0); - if (check_argc_min(argc - optind, 1)) + if (check_argc_min(argc, 2) || argv[1][0] == '-') usage(cmd_device_usage_usage); - for (i = optind; i < argc ; i++) { + for (i = 1; i < argc; i++) { int fd; - DIR *dirstream = NULL; + DIR *dirstream = NULL; if (more_than_one) printf("\n");