Re: weird behavior with stat and file sizes
- From: Michael Kerrisk <michael.kerrisk.at.gmx.net@xxxxxxxxxx>
- Date: Wed, 22 Mar 2006 11:05:31 +1200
On Tue, 21 Mar 2006 20:04:29 +0000, Roger Leigh
<${rleigh}@invalid.whinlatter.ukfsn.org.invalid> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Michael Kerrisk <michael.kerrisk.at.gmx.net@xxxxxxxxxx> writes:
On Tue, 21 Mar 2006 19:17:06 +0000, in comp.os.linux.development.apps
you wrote:
"maria" <marialgullickson@xxxxxxxxx> writes:
From the man page, it looks like I'm working with 512B blocks. Does
that mean all files will take up space in increments of 512B? Even
if the file's "notional size" is only 10B?
Yes, in general. However, don't assume the blocksize is always the
same; it can vary from filesystem to filesystem, so check st_blksize
each time you stat a file.
The ext2 filesystem, for example, allows different blocksizes. You
can make it 1024, 2048 or 4096 bytes, depending on the usage pattern
required of it.
Roger,
This is true, but it does not affect st_blocks, which is always
measured in 512-byte units on Linux. (And I think all other
implementations are similar in always using the same unit across file
systems.)
Yes, I forgot about that detail. The 512 B block is IIRC standardised
by POSIX.
http://www.opengroup.org/onlinepubs/009695399/basedefs/sys/stat.h.html
says:
[[
The unit for the st_blocks member of the stat structure is not defined
within IEEE Std 1003.1-2001. In some implementations it is 512 bytes.
It may differ on a file system basis. There is no correlation between
values of the st_blocks and st_blksize, and the f_bsize (from
<sys/statvfs.h>) structure members.
]]
So, it's not standardized, but also I was not quite right -- it can
vary across file systems. I don't know of systems where this is the
case, but presumably there is/was one that led to this wording in the
standard.
Cheers,
Michael
.
- References:
- weird behavior with stat and file sizes
- From: maria
- Re: weird behavior with stat and file sizes
- From: Michael Kerrisk
- Re: weird behavior with stat and file sizes
- From: maria
- Re: weird behavior with stat and file sizes
- From: Roger Leigh
- Re: weird behavior with stat and file sizes
- From: Michael Kerrisk
- Re: weird behavior with stat and file sizes
- From: Roger Leigh
- weird behavior with stat and file sizes
- Prev by Date: Re: Is stork a troll? (was Re: Trolltech QT license question)
- Next by Date: Advice on video libraries
- Previous by thread: Re: weird behavior with stat and file sizes
- Next by thread: Re: weird behavior with stat and file sizes
- Index(es):
Relevant Pages
|