From patchwork Tue Jan 10 01:08:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9506127 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 5D81360231 for ; Tue, 10 Jan 2017 01:12:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E96528493 for ; Tue, 10 Jan 2017 01:12:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 527852849C; Tue, 10 Jan 2017 01:12:09 +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=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1CE1E28493 for ; Tue, 10 Jan 2017 01:12:09 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id D4F6D81B12; Mon, 9 Jan 2017 17:12:08 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 37BF781B10 for ; Mon, 9 Jan 2017 17:12:08 -0800 (PST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP; 09 Jan 2017 17:12:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,341,1477983600"; d="scan'208";a="806992304" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.14]) by FMSMGA003.fm.intel.com with ESMTP; 09 Jan 2017 17:12:07 -0800 Subject: [PATCH 7/9] ndctl: return unit size from parse_size64() From: Dan Williams To: linux-nvdimm@lists.01.org Date: Mon, 09 Jan 2017 17:08:01 -0800 Message-ID: <148401048177.16217.14743190895800442308.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <148401044568.16217.6942951063735168785.stgit@dwillia2-desk3.amr.corp.intel.com> References: <148401044568.16217.6942951063735168785.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP In preparation for suggesting namespace sizes that satisfy alignment requirements, add the ability to track the size suffix. The suggestions will be aligned to the size suffix by default. Signed-off-by: Dan Williams --- util/size.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/util/size.c b/util/size.c index 1ca2dcff5e28..6ad622781a27 100644 --- a/util/size.c +++ b/util/size.c @@ -2,7 +2,8 @@ #include #include -unsigned long long parse_size64(const char *str) +static unsigned long long __parse_size64(const char *str, + unsigned long long *units) { unsigned long long val, check; char *end; @@ -14,25 +15,35 @@ unsigned long long parse_size64(const char *str) switch (*end) { case 'k': case 'K': + if (units) + *units = SZ_1K; val *= SZ_1K; end++; break; case 'm': case 'M': + if (units) + *units = SZ_1M; val *= SZ_1M; end++; break; case 'g': case 'G': + if (units) + *units = SZ_1G; val *= SZ_1G; end++; break; case 't': case 'T': + if (units) + *units = SZ_1T; val *= SZ_1T; end++; break; default: + if (units) + *units = 1; break; } @@ -40,3 +51,8 @@ unsigned long long parse_size64(const char *str) val = ULLONG_MAX; return val; } + +unsigned long long parse_size64(const char *str) +{ + return __parse_size64(str, NULL); +}