From: NeilBrown <neilb@suse.de>
To: Maciej Naruszewicz <maciej.naruszewicz@intel.com>
Cc: linux-raid@vger.kernel.org, maciej.patelczyk@intel.com
Subject: Re: [PATCH 5/6] Display size with human_size_brief with a chosen prefix
Date: Tue, 2 Oct 2012 16:41:32 +1000 [thread overview]
Message-ID: <20121002164132.3cdeade6@notabene.brown> (raw)
In-Reply-To: <20120926114415.328.68023.stgit@gklab-128-174.igk.intel.com>
[-- Attachment #1: Type: text/plain, Size: 3736 bytes --]
On Wed, 26 Sep 2012 13:44:15 +0200 Maciej Naruszewicz
<maciej.naruszewicz@intel.com> wrote:
> When using human_size_brief, only IEC prefixes were supported. Now
> it's possible to specify which format we want to see - either IEC
> (kibi, mibi, gibi) or JEDEC (kilo, mega, giga).
>
> Signed-off-by: Maciej Naruszewicz <maciej.naruszewicz@intel.com>
> ---
> Query.c | 2 +-
> mdadm.h | 7 ++++++-
> util.c | 36 +++++++++++++++++++++++++++---------
> 3 files changed, 34 insertions(+), 11 deletions(-)
>
> diff --git a/Query.c b/Query.c
> index b9c209f..329e583 100644
> --- a/Query.c
> +++ b/Query.c
> @@ -76,7 +76,7 @@ int Query(char *dev)
> else {
> printf("%s: %s %s %d devices, %d spare%s. Use mdadm --detail for more detail.\n",
> dev,
> - human_size_brief(larray_size),
> + human_size_brief(larray_size,IEC),
> map_num(pers, array.level),
> array.raid_disks,
> array.spare_disks, array.spare_disks==1?"":"s");
> diff --git a/mdadm.h b/mdadm.h
> index e27275b..a24b803 100644
> --- a/mdadm.h
> +++ b/mdadm.h
> @@ -329,6 +329,11 @@ enum special_options {
> ControllerPath,
> };
>
> +enum prefix_standard {
> + JEDEC,
> + IEC
> +};
> +
> /* structures read from config file */
> /* List of mddevice names and identifiers
> * Identifiers can be:
> @@ -1242,7 +1247,7 @@ extern int set_array_info(int mdfd, struct supertype *st, struct mdinfo *info);
> unsigned long long min_recovery_start(struct mdinfo *array);
>
> extern char *human_size(long long bytes);
> -extern char *human_size_brief(long long bytes);
> +extern char *human_size_brief(long long bytes, int prefix);
> extern void print_r10_layout(int layout);
>
> #define NoMdDev (1<<23)
> diff --git a/util.c b/util.c
> index 09971a2..cb97816 100644
> --- a/util.c
> +++ b/util.c
> @@ -682,7 +682,7 @@ char *human_size(long long bytes)
> return buf;
> }
>
> -char *human_size_brief(long long bytes)
> +char *human_size_brief(long long bytes, int prefix)
> {
> static char buf[30];
>
> @@ -693,19 +693,37 @@ char *human_size_brief(long long bytes)
> * gigabytes, as that shows more precision and isn't
> * too large a number.
> * Terabytes are not yet handled.
> + *
> + * If prefix == IEC, we mean prefixes like kibi,mebi,gibi etc.
> + * If prefix == JEDEC, we mean prefixes like kilo,mega,giga etc.
> */
>
> if (bytes < 5000*1024)
> buf[0] = 0;
> - else if (bytes < 2*1024LL*1024LL*1024LL) {
> - long cMiB = (bytes / ( (1LL<<20) / 200LL ) +1) /2;
> - snprintf(buf, sizeof(buf), " (%ld.%02ldMiB)",
> - cMiB/100 , cMiB % 100);
> - } else {
> - long cGiB = (bytes / ( (1LL<<30) / 200LL ) +1) /2;
> - snprintf(buf, sizeof(buf), " (%ld.%02ldGiB)",
> - cGiB/100 , cGiB % 100);
> + else if (prefix == IEC) {
> + if (bytes < 2*1024LL*1024LL*1024LL) {
> + long cMiB = (bytes / ( (1LL<<20) / 200LL ) +1) /2;
> + snprintf(buf, sizeof(buf), "%ld.%02ldMiB",
> + cMiB/100 , cMiB % 100);
> + } else {
> + long cGiB = (bytes / ( (1LL<<30) / 200LL ) +1) /2;
> + snprintf(buf, sizeof(buf), "%ld.%02ldGiB",
> + cGiB/100 , cGiB % 100);
> + }
> + }
> + else if (prefix == JEDEC) {
> + if (bytes < 2*1024LL*1024LL*1024LL) {
> + long cMB = (bytes / ( 1000000LL / 200LL ) +1) /2;
> + snprintf(buf, sizeof(buf), "%ld.%02ldMB",
> + cMB/100, cMB % 100);
> + } else {
> + long cGB = (bytes / (1000000000LL/200LL ) +1) /2;
> + snprintf(buf, sizeof(buf), "%ld.%02ldGB",
> + cGB/100 , cGB % 100);
> + }
> }
> + else
> + buf[0] = 0;
>
> return buf;
> }
Yes, I guess that make sense.
Applied,
thanks.
NeilBrown
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]
next prev parent reply other threads:[~2012-10-02 6:41 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-26 11:42 [mdadm,v1 PATCH 0/6] Extend mdadm [...] --export Maciej Naruszewicz
2012-09-26 11:42 ` [PATCH 1/6] imsm: Add --export option for --detail-platform Maciej Naruszewicz
2012-10-02 6:28 ` NeilBrown
2012-09-26 11:42 ` [PATCH 2/6] imsm: Add --controller-path " Maciej Naruszewicz
2012-10-02 6:36 ` NeilBrown
2012-10-02 10:54 ` Maciej Naruszewicz
2012-09-26 11:42 ` [PATCH 3/6] Fix return code " Maciej Naruszewicz
2012-10-02 6:38 ` NeilBrown
2012-09-26 11:44 ` [PATCH 4/6] Synchronize size calculation in human_size and human_size_brief Maciej Naruszewicz
2012-10-02 6:40 ` NeilBrown
2012-09-26 11:44 ` [PATCH 5/6] Display size with human_size_brief with a chosen prefix Maciej Naruszewicz
2012-10-02 6:41 ` NeilBrown [this message]
2012-09-26 11:44 ` [PATCH 6/6] Add MD_ARRAY_SIZE for --examine --export Maciej Naruszewicz
2012-10-02 6:42 ` NeilBrown
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=20121002164132.3cdeade6@notabene.brown \
--to=neilb@suse.de \
--cc=linux-raid@vger.kernel.org \
--cc=maciej.naruszewicz@intel.com \
--cc=maciej.patelczyk@intel.com \
/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).