[cs631apue] blocks (-s) & size (-k -h)
jschauma at stevens.edu
Fri Oct 17 22:45:08 EDT 2014
zding4 <zding4 at stevens.edu> wrote:
> APUE book have the paragraph about st_blocks
> "Be aware that different versions of the UNIX System use units other
> than 512-byte blocks for st_blocks.
> Using this value is nonportable"
That is correct. However, there is no portable method of determining
the value used for st_blocks, so for our purposes here we may make the
assumption that it is in fact 512 bytes.
That means that the approach of calculating the correct value based on
the environment variable as discussed in this thread does work (although
you need to be careful to round up when needed).
The NetBSD implementation of ls(1) takes the approach of setting the
value for '-s' output to
X = BLOCKSIZE/512
Y = ( (st_blocks + (X - 1)) / X )
st_blocks * 512 / BLOCKSIZE will get close, but occasionally be off by
More information about the cs631apue