du -m is off
  Home FAQ Contact Sign in
muc.lists.netbsd.tech.misc only
 
Advanced search
POPULAR GROUPS

more...

muc.lists.netbsd.tech.misc Profile…
 Up
du -m is off         


Author: Jeremy C. Reed
Date: Mar 22, 2008 08:00

I noticed that a file of 10485760 bytes would be listed as 11MB by du -m.
The -h "humanize" is correct and lists as 10MB.

du.c uses:

(void)printf("%%lld\t%%s\n",
(long long)howmany(blocks, (int64_t)blocksize),

This works better for me:

printf("%%ld\n", (long)((int64_t)blocks / blocksize));

But that doesn't help for files less than a megabyte which will then be
displayed as a zero.

As another example, a file of 3372684 bytes is 3.21644MB. du -m would
round up to 4. While my printf above prints "3".

I am not sure what correct behaviour should be.

Either way, the du man page should document about this as it is
misleading.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
2 Comments
Re: du -m is off         


Author: Greg A. Woods; Planix, Inc.
Date: Mar 22, 2008 10:10

On 22-Mar-08, at 11:00 AM, Jeremy C. Reed wrote:
> I noticed that a file of 10485760 bytes would be listed as 11MB by
> du -m.
> The -h "humanize" is correct and lists as 10MB.
>
> du.c uses:
>
> (void)printf("%%lld\t%%s\n",
> (long long)howmany(blocks, (int64_t)blocksize),
>
> This works better for me:
>
> printf("%%ld\n", (long)((int64_t)blocks / blocksize));
>
> But that doesn't help for files less than a megabyte which will
> then be
> displayed as a zero.
>
> As another example, a file of 3372684 bytes is 3.21644MB. du -m would
> round up to 4. While my printf above prints "3". ...
Show full article (3.42Kb)
no comments
Re: du -m is off         


Author: David Laight
Date: Mar 26, 2008 14:38

On Sat, Mar 22, 2008 at 01:10:04PM -0400, Greg A. Woods; Planix, Inc. wrote:
>
> Now as to the problem with your 10485760-byte file, well that's easy
> to understand if you first take a peek at just how much space has
> been allocated for that file (and keep in mind that "du" shows disk
> usage, not file size) [use "stat -s"]. For example when I create an
> exactly 10MB file I get a file that uses 20512 "blocks" (i.e. 512-
> byte-blocks) of disk space. If you multiply that back out then the
> bytes of disk space used are 10502144, i.e. 10.015625MB, and so by
> the logic above that means that in 1MB units the file does indeed use
> what must be counted as 11MB of disk space. This is of course
> because the block size on the filesystem is 16KB, not 512B, and your
> 10MB...
Show full article (1.22Kb)
no comments