Subject: Re: du ouput query
To: None <port-i386@NetBSD.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: port-i386
Date: 07/31/2007 02:22:26
[This really doesn't belong on port-i386, as just about nothing here is
i386-specific, as far as I can see.  tech-userlevel maybe?]

> I suppose it's possible for the amount of disk space allocated to a
> sparse file to be the same as its size, and ls -lsh would give the
> same numbers for its first and sixth fields?

(a) they're in different units, so the numbers printed won't be the
same in the case you're thinking of (well, this depends on how -s
interacts with -h in your ls[%]); and (b) they represent different
things, so the numbers wouldn't be the same even if they were in the
same units.

[%] Under 3.1, -h seems to suppress -s for me, though the manpage seems
to imply that -h makes -s print values in bytes.

The size field (the sixth field) is the size of the data content of the
file, in bytes.  This includes any holes as if they were filled in.
The disk-used field (the first field) is the amount of space actually
occupied on disk, in, usually, disk sectors.  This can be smaller than
the nominal size divided by the disk sector size (for a sparse file) or
larger (to account for, eg, indirect blocks).

> In that case, how do you tell if it is a sparse file or not?  Maybe
> it ceases to be a sparse file as soon as this happens?

The latter.  A sparse file is, by definition, one whose data content is
not completely stored on disk, one which (in ffs terms) uses, at least
once, the abbreviation of a zero block number representing a block full
of zero bytes.  Fill in all its holes and it ceases to be sparse.

>       -l      (The lowercase letter ``ell'').  List in long format.  (See
>               below.)  A total sum for all the file sizes is output on a line
>               before the long listing.

> In this example, how does 'total 4' correspond to the file size of
> seven bytes?

> $ ls -l
> total 4
> -rw-r--r--  1 defang  wheel  7 Jul 31 13:49 file1
> $ set | grep BLOCK
> $

My guess is, your filesystem is a 2k/16k FFS filesystem; a seven-byte
file actually occupies one whole frag, which is 4 disk sectors.

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML	       mouse@rodents.montreal.qc.ca
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B