From: Fabio Miranda Hamburger <fabmirha@ns.isi.ulatina.ac.cr>
To: Glynn Clements <glynn@gclements.plus.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: du and ls
Date: Sat, 2 Jun 2007 23:09:36 +0000 (UTC)
Date: Tue, 5 Jun 2007 22:38:56 -0600 (CST) [thread overview]
Message-ID: <Pine.LNX.4.64.0706052236270.20275@ns.isi.ulatina.ac.cr> (raw)
In-Reply-To: <18017.20272.201352.576692@cerise.gclements.plus.com>
> Fabio Miranda Hamburger wrote:
>
>> I am curious about the mismatch between du and ls. Apparently, du reports
>> amount of 512 or 1024-K blocks, and ls lists the absolute value.
>
> du reports the amount of disk space which the file uses, while ls
> reports the amount of data which it contains.
>
>> But, why in some cases, a 1100 bytes file is reported by du as 4 x 512
>> bytes instead of 3 x 512bytes
>
> Because the file occupies 2 x 1024-byte blocks.
>
>> I note both use fstat().
>
> stat(), fstat() etc, and thus du, report disk usage in multiples of
> 512-byte blocks, as that was the block size on the earliest Unix
> systems. The actual block size depends upon the filesystem.
>
> The st_size field indicates the actual size of the file (i.e. the
> number of bytes which it contains); this is the value reported by ls.
>
> The st_blocks field returns the disk usage in multiples of 512 bytes;
> this is the value reported by du.
>
> Note that the actual size of the file can be more than 512 * st_blocks
> bytes if the file contains "holes". These are blocks which are
> implicitly filled with zeros when the file is enlarged by lseek(),
> ftruncate() etc, and aren't actually stored on disk.
Glynn, why lseek() will fill space with zeros if it's placed in a position
beyond file limit itself? To provide to the application a fixed size of
data for one purpose and so on.
Example, an application will use first 1025k of a file for something, then
the next 2048 fo another, is this the intention of lseek() ?
Please, adivse,
Thanks,
fabio
next prev parent reply other threads:[~2007-06-02 23:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-02 1:58 du and ls Fabio Miranda Hamburger
2007-06-02 11:06 ` Glynn Clements
2007-06-02 23:09 ` Fabio Miranda Hamburger [this message]
2007-06-04 7:12 ` Glynn Clements
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=Pine.LNX.4.64.0706052236270.20275@ns.isi.ulatina.ac.cr \
--to=fabmirha@ns.isi.ulatina.ac.cr \
--cc=glynn@gclements.plus.com \
--cc=linux-c-programming@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).