I always assumed the st_blocks
field returned by stat()
/lstat()
... system calls and which du
uses to get the disk usage of files was expressed in 512 bytes units.
Checking the POSIX specification, I now see POSIX makes no guarantee for that. The perl
documentation for its own stat()
function also warns against making that assumption.
In any case, as indicated by POSIX, that block size is not related to the st_blksize
field returned by stat()
, so has to be found elsewhere.
Checking the GNU du
or GNU find
source code, I see evidence HP/UX uses 1024 bytes units instead. GNU find
adjusts its -printf %b
output to always give a number of 512-byte units which is probably the source of my confusion.
Is there any other Unix-like system, still currently in use where st_blocks
is not expressed in 512 byte units? Can that be filesystem dependant (as POSIX suggests)? I guess mounting an HP/UX NFS share could do it.