List Info

Thread: du -m is off




du -m is off
user name
2008-03-22 10:00: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("%lldt%sn",
                    (long long)howmany(blocks,
(int64_t)blocksize),

This works better for me:

printf("%ldn", (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.


Re: du -m is off
user name
2008-03-26 16:38:19
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 file actually needs 623 filesystem(16KB) units of
allocation,  
> i.e. it does actually use more than 10MB of filesystem
space.

The output of 'du' includes the indirect blocks, so will be
larger
than the filesize for non-trivial files without holes.

	David

-- 
David Laight: davidl8s.co.uk

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )