[cs631apue] blocks (-s) & size (-k -h)

Sen Jiang sjiang11 at stevens.edu
Sat Oct 18 14:25:52 EDT 2014


If BLOCKSIZE is less than 512, X will be 0

On Fri, Oct 17, 2014 at 10:45 PM, Jan Schaumann <jschauma at stevens.edu>
wrote:

> 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
> one.
>
> -Jan
> _______________________________________________
> cs631apue mailing list
> cs631apue at lists.stevens.edu
> https://lists.stevens.edu/mailman/listinfo/cs631apue
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.stevens.edu/pipermail/cs631apue/attachments/20141018/ef46b171/attachment.html>


More information about the cs631apue mailing list