Re: weird behavior with stat and file sizes



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
.



Relevant Pages

  • Re: Magic Number for New File system
    ... > We are planning to write a new file system for our requirements. ... There's no standard place to put a magic number, ... location of the superblock will vary from filesystem to filesystem, ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • SUMMARY: how do I REALLY delete a file?
    ... leaving the rest of the file system intact. ... Wipedrive doesn't seem to be available for Solaris, but might be of interest to ... run this on each filesystem where the files from ... >Solaris' UFS] do not satisfy this assumption." ...
    (SunManagers)
  • Summary: df -k : discrepancy in the % displayed
    ... The standard file system reserves about 10% of the kbytes for efficiency; ... is unavailable to anyone except root. ... If you created your filesystem with default options, ... This 5% or so reservation is probably not worth bothering with on a 1-2GB ...
    (SunManagers)
  • Re: Saving Objectstore to a WinCE OS device
    ... ANY filesystem can be used. ... It should indicate that this particular registry key is deprecated, ... the registry and mount it as the root and you'll be 80% of the way ... I thought when you mentioned File system that you was refering to ...
    (microsoft.public.windowsce.embedded)
  • Re: Booting - Enterprise Volume Management System
    ... nothing to do with LVM and everything to do with file systems. ... bother with LVM on a single disk if you can just make one big partition? ... Runaway processes can't fill the filesystem, ... windows machine when exchange fills the file system. ...
    (Ubuntu)