[cs631apue] [cs 631] ls -s flag

Jan Schaumann jschauma at stevens.edu
Tue Oct 2 21:41:54 EDT 2012


tparisi <tparisi at stevens.edu> wrote:
> That makes sense. As a check the number of blocks a file occupies
> within the filesystem should be a multiple of 8 correct?

For this particular file system as it was created, yes.

> And this is only true for the regular operating system and not for out
> NFS partitions right?

Correct - different file systems can have different logical block sizes.
You can even create two file systems of the same type (ext3 in the case
of linux-lab.cs.stevens.edu's /) with a different logical block size.
Which is why st_blksize exists in the struct stat -- it will tell you
what the block size of the particular file system the file resides on
is.

> Because when I check this in say /home/tparisi/Documents I receive the
> number of file system blocks to be numbers like 18, 4, 35, 62, and 44.
> These are not multiples of 8 so how is this possible?

/home is on a network file system, not a traditional file system, so
things are little bit different there.  The NFS is mounted with a
specified read- and write- block size, which may or may not be reflected
in the struct stat's st_blocks or st_blksize.

The manual page on Linux notes this explicitly:

| Use of the st_blocks and st_blksize fields may be less portable.  (They
| were introduced in BSD.  The interpretation differs between systems, and
| possibly on a single system when NFS mounts are involved.)

However, these oddities aside, your tool can still follow the
specification and accept whatever it finds in st_blocks and operate on
that -- this is, after all, all that is asked of it, and anything else
is left to the file system.

-Jan


More information about the cs631apue mailing list