Bug 34834

Summary: "fix" of du(1) and -h
Product: Base System Reporter: Tomas Svensson <tsn>
Component: binAssignee: Pawel Jakub Dawidek <pjd>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 5.0-CURRENT   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description Tomas Svensson 2002-02-11 15:40:03 UTC
	The manpages for df(1), du(1) and ls(1) claim that -h (print human-
	readable numbers) will reduce the number of digits to three or fewer,
	but this isn't true. It will print numbers such as 1000K or 1010K
	(since these are slightly less than a megabyte). Also, the 'K' for
	kilo should really be 'k'.

	Here is a fix for du(1) (I'll fix the others too if this patch is
	accepted). This version will display "1.0M" where the old version
	displayed "1012K", "32k" instead of "32K" etc.

	As a "side effect", df doesn't need the math library anymore (still
	does proper rounding) and the source is more than a kB smaller :)

	An alternative would be to add a more extensive humanize function
	to libc...
Comment 1 Crist J. Clark freebsd_committer freebsd_triage 2002-02-12 11:50:37 UTC
On Mon, Feb 11, 2002 at 10:36:46AM -0500, Tomas Svensson wrote:
[snip]

> >Description:
> 	The manpages for df(1), du(1) and ls(1) claim that -h (print human-
> 	readable numbers) will reduce the number of digits to three or fewer,
> 	but this isn't true. It will print numbers such as 1000K or 1010K
> 	(since these are slightly less than a megabyte). Also, the 'K' for
> 	kilo should really be 'k'.

'k' is generally used for multiples of 1000. 'K' is used for multiples
of 1024. Sticking with 'K' is prefered except possibly for the '-H'
option of df(1). But it seems like a lot of trouble to change that one
case to 'k'.

The current method does seem to be overkill. Why not just divide by
1024 n-times until the result is < 1024 rather than ilogb(3)? We lose
the math library, and we don't need that table of values.

One comment about the patch,

[snip]
> +		printf("%qd.%qd%c", s1, s2, prefixes[i]);
> +	} else
> +		printf("%3qd%c", (bytes + 50) / 100, prefixes[i]);

Quads? Ewwww...
-- 
Crist J. Clark                     |     cjclark@alum.mit.edu
                                   |     cjclark@jhu.edu
http://people.freebsd.org/~cjc/    |     cjc@freebsd.org
Comment 2 Tomas Svensson 2002-02-12 13:52:46 UTC
Tuesday, February 12, 2002, 12:50:37 PM, you wrote:

CJC> On Mon, Feb 11, 2002 at 10:36:46AM -0500, Tomas Svensson wrote:
CJC> [snip]

>> >Description:
>>       The manpages for df(1), du(1) and ls(1) claim that -h (print human-
>>       readable numbers) will reduce the number of digits to three or fewer,
>>       but this isn't true. It will print numbers such as 1000K or 1010K
>>       (since these are slightly less than a megabyte). Also, the 'K' for
>>       kilo should really be 'k'.

CJC> 'k' is generally used for multiples of 1000. 'K' is used for multiples
CJC> of 1024. Sticking with 'K' is prefered except possibly for the '-H'
CJC> option of df(1). But it seems like a lot of trouble to change that one
CJC> case to 'k'.

Yes you're right, change the 'k' to 'K'. Just because 3-4 people told
me that 'k' was right, I assumed that they were correct.

CJC> The current method does seem to be overkill. Why not just divide by
CJC> 1024 n-times until the result is < 1024 rather than ilogb(3)? We lose
CJC> the math library, and we don't need that table of values.

< 1024 will still give the irritating '1000K' result.

CJC> One comment about the patch,

CJC> [snip]
>> +             printf("%qd.%qd%c", s1, s2, prefixes[i]);
>> +     } else
>> +             printf("%3qd%c", (bytes + 50) / 100, prefixes[i]);

CJC> Quads? Ewwww...

The smaller types won't do for the calculation, so no point in
convertning before printing? (Ok, s1 and s2 doesn't need to be quads).

-Tomas
Comment 3 Bob Bishop 2002-02-13 14:57:10 UTC
*ALL* the standard one-letter prefixes strictly denote powers of 10, so 
being precious over k/K doesn't really help much. See
http://physics.nist.gov/cuu/Units/prefixes.html
and
http://physics.nist.gov/cuu/Units/binary.html
for the applicable standards.

--
Bob Bishop		    +44 (0)118 977 4017
rb@gid.co.uk		fax +44 (0)118 989 4254
Comment 4 Pawel Jakub Dawidek freebsd_committer freebsd_triage 2004-10-24 18:23:39 UTC
State Changed
From-To: open->feedback

Could you check if this is fixed in FreeBSD 5.3 or 6-CURRENT? 


Comment 5 Pawel Jakub Dawidek freebsd_committer freebsd_triage 2004-10-24 18:23:39 UTC
Responsible Changed
From-To: freebsd-bugs->pjd

Could you check if this is still a problem in 5.3 or 6-CURRENT?
Comment 6 Pawel Jakub Dawidek freebsd_committer freebsd_triage 2004-10-24 18:45:00 UTC
State Changed
From-To: feedback->closed

Submitter e-mail doesn't exist, so I can't get feedback. 
I think this bug was fixed when humanize_number(3) was introduced.