From patchwork Wed Jul 18 13:23:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 171675 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B45362C037F for ; Wed, 18 Jul 2012 23:23:56 +1000 (EST) Received: from localhost ([::1]:48985 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrUEM-0001oR-Ql for incoming@patchwork.ozlabs.org; Wed, 18 Jul 2012 09:23:54 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34168) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrUEF-0001nw-2X for qemu-devel@nongnu.org; Wed, 18 Jul 2012 09:23:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SrUEA-0000di-Sh for qemu-devel@nongnu.org; Wed, 18 Jul 2012 09:23:47 -0400 Received: from mail-yx0-f173.google.com ([209.85.213.173]:36515) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrUEA-0000dO-M7 for qemu-devel@nongnu.org; Wed, 18 Jul 2012 09:23:42 -0400 Received: by yenl1 with SMTP id l1so1622091yen.4 for ; Wed, 18 Jul 2012 06:23:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer; bh=VydrvRFS3uWDKgE+EN8MwEyf4Hv/k/+xHPwBxHMIIOg=; b=ZC8p5S6tymLJiIGh+Ts7uR0MPb3uttrXbkjBilXmudRXtbBHDFvs88oen4LF18xQU4 hFZxQp/Hd9B+1Bn2y0HPGu3tfKyk7FwqlL668nvUhqZuhVpxnpASN0OntMyAvE/zOHs2 toFUnvrBLvoHs60aW37Q2D4KI74sVi0J/OPgPq1pMwip2WFCKzDWLLNxFRC+6JFlCJ7J 6IwXOYJQdf2bE0ZPei+K+dAblUDbpsjxxGhTnLg44YZDlj7t4PvtSu7S1tnlVOsWEH54 hVkeyIV+Z6o/7VlTvkOlbTZOFP5VKrpqyANzGAWh6+Q+tQ40Ub+98nm1j3McHBPH4ux8 UVSQ== Received: by 10.50.94.166 with SMTP id dd6mr1981912igb.11.1342617821151; Wed, 18 Jul 2012 06:23:41 -0700 (PDT) Received: from localhost.localdomain ([202.108.130.138]) by mx.google.com with ESMTPS id ua2sm24957420igb.7.2012.07.18.06.23.37 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 18 Jul 2012 06:23:39 -0700 (PDT) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Wed, 18 Jul 2012 21:23:06 +0800 Message-Id: <1342617786-22107-1-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.213.173 Cc: kwolf@redhat.com, Dong Xu Wang , riegamaths@gmail.com Subject: [Qemu-devel] [PATCH v3] qemu-img: correct size parsers and help message X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org qemu-img not only suports k/K/M/G/T/b, but also supports m/g/t/B. So correct it in help message. Also use the same parser in parse_option_size function. Signed-off-by: Dong Xu Wang CC: riegamaths@gmail.com --- v1->v2: also correct error reporting. v2->v3: use the same parser in parse_option_size function. qemu-img.c | 9 +++++---- qemu-option.c | 6 +++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 80cfb9b..7f2fde4 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -69,8 +69,9 @@ static void help(void) " options are: 'none', 'writeback' (default, except for convert), 'writethrough',\n" " 'directsync' and 'unsafe' (default for convert)\n" " 'size' is the disk image size in bytes. Optional suffixes\n" - " 'k' or 'K' (kilobyte, 1024), 'M' (megabyte, 1024k), 'G' (gigabyte, 1024M)\n" - " and T (terabyte, 1024G) are supported. 'b' is ignored.\n" + " 'k' or 'K' (kilobyte, 1024), 'm' or 'M' (megabyte, 1024k),\n" + " 'g' or 'G' (gigabyte, 1024M) and 't' or 'T' (terabyte, 1024G) are supported.\n" + " 'b' or 'B' is ignored.\n" " 'output_filename' is the destination disk image filename\n" " 'output_fmt' is the destination format\n" " 'options' is a comma separated list of format specific options in a\n" @@ -341,8 +342,8 @@ static int img_create(int argc, char **argv) char *end; sval = strtosz_suffix(argv[optind++], &end, STRTOSZ_DEFSUFFIX_B); if (sval < 0 || *end) { - error_report("Invalid image size specified! You may use k, M, G or " - "T suffixes for "); + error_report("Invalid image size specified! You may use k/K, m/M, " + "g/G or t/T suffixes for "); error_report("kilobytes, megabytes, gigabytes and terabytes."); ret = -1; goto out; diff --git a/qemu-option.c b/qemu-option.c index bb3886c..abc3b90 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -213,25 +213,29 @@ static void parse_option_size(const char *name, const char *value, sizef = strtod(value, &postfix); switch (*postfix) { case 'T': + case 't': sizef *= 1024; /* fall through */ case 'G': + case 'g': sizef *= 1024; /* fall through */ case 'M': + case 'm': sizef *= 1024; /* fall through */ case 'K': case 'k': sizef *= 1024; /* fall through */ + case 'B': case 'b': case '\0': *ret = (uint64_t) sizef; break; default: error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a size"); - error_printf_unless_qmp("You may use k, M, G or T suffixes for " + error_printf_unless_qmp("You may use K/k, M/m, G/g or T/t suffixes for " "kilobytes, megabytes, gigabytes and terabytes.\n"); return; }