All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hugo Mills <hugo@carfax.org.uk>
To: David Sterba <dsterba@suse.cz>
Cc: linux-btrfs@vger.kernel.org, zab@redhat.com, wangshilong1991@gmail.com
Subject: Re: [PATCH] btrfs-progs: per-thread, per-call pretty buffer
Date: Wed, 10 Jul 2013 17:16:23 +0100	[thread overview]
Message-ID: <20130710161623.GJ5445@carfax.org.uk> (raw)
In-Reply-To: <1373466615-30013-1-git-send-email-dsterba@suse.cz>

[-- Attachment #1: Type: text/plain, Size: 1367 bytes --]

   Sorry to be a pain in the arse at this late stage of the patch, but
I've only just noticed.

On Wed, Jul 10, 2013 at 04:30:15PM +0200, David Sterba wrote:
>  static char *size_strs[] = { "", "KB", "MB", "GB", "TB",
> -			    "PB", "EB", "ZB", "YB"};
> -char *pretty_sizes(u64 size)
> +			    "PB", "EB"};

   These are SI (power of 10) prefixes...

> +void pretty_size_snprintf(u64 size, char *str, size_t str_bytes)
>  {
>  	int num_divs = 0;
> -        int pretty_len = 16;
>  	float fraction;
> -	char *pretty;
> +
> +	if (str_bytes == 0)
> +		return;
>  
>  	if( size < 1024 ){
>  		fraction = size;
> @@ -1172,13 +1173,13 @@ char *pretty_sizes(u64 size)
>  			num_divs ++;
>  		}
>  
> -		if (num_divs >= ARRAY_SIZE(size_strs))
> -			return NULL;
> +		if (num_divs >= ARRAY_SIZE(size_strs)) {
> +			str[0] = '\0';
> +			return;
> +		}
>  		fraction = (float)last_size / 1024;

   ... and this is working in IEC (power of 2) units.

   Can we fix this discrepancy, please? Also note that SI uses k for
10^3, but IEC uses K for 2^10. Just insert an "i" in the middle of
each element of size_strs should deal with the problem.

   Hugo.

-- 
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
  PGP key: 65E74AC0 from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
   --- Charting the inexorable advance of Western syphilisation... ---   

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

  parent reply	other threads:[~2013-07-10 16:16 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-07  9:58 [PATCH V2 1/2] Btrfs-progs: make pretty_sizes() work less error prone Wang Shilong
2013-07-09 20:24 ` Zach Brown
2013-07-09 23:05   ` Wang Shilong
2013-07-10 12:49   ` David Sterba
2013-07-10 15:59     ` Zach Brown
2013-07-10 14:30   ` [PATCH] btrfs-progs: per-thread, per-call pretty buffer David Sterba
2013-07-10 15:31     ` Wang Shilong
2013-07-10 15:51       ` David Sterba
2013-07-10 16:16     ` Hugo Mills [this message]
2013-07-10 17:39       ` David Sterba
2013-07-10 17:40       ` [PATCH] btrfs-progs: use IEC units for sizes David Sterba
2014-09-04 11:43     ` [PATCH] btrfs-progs: per-thread, per-call pretty buffer Anand Jain
2014-09-04 19:45       ` Zach Brown
2014-09-05  7:11         ` Anand Jain
2014-09-05 15:55           ` Zach Brown
2014-09-05 16:20             ` David Sterba
2014-09-15 12:27               ` David Sterba
2015-02-27 17:53         ` David Sterba

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=20130710161623.GJ5445@carfax.org.uk \
    --to=hugo@carfax.org.uk \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=wangshilong1991@gmail.com \
    --cc=zab@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.