st_blocks on SUN 4.0.3

Sam L. Falkner falkner at cell.mot.COM
Tue Mar 20 02:41:27 AEST 1990


i'm trying to 'do what du does' on SUN OS 4.0.3.  to get the number of
blocks used, i'm using stat(2) and looking at the st_blocks field.  the
trouble is that both du(1) and ls(1) disagree with the number i'm
getting by a factor of two.

oh, then the block size must be 512 bytes or something, since the man
page for du(1) says that it reports kilobytes.  well, unfortunately, i
haven't found anything to indicate 512 byte blocks.  the statfs(2) call
returns 1024 in its f_bsize field.

also of interest is that a file whose size is 16384 bytes returns 32
blocks in st_blocks (and du(1) and ls(1) say '16'), so it really does
look like i'm dealing with 512 byte blocks.  why doesn't statfs say 512,
or why does stat say 32 blocks?!

right now, i'm just dividing the st_blocks field by 2, which is a dirty
hack.  i wouldn't mind doing something like st_blocks * f_bsize / 1024
or something like that, but right now nothing seems to make sense.

normally, what i'd do is look at the source for du(1), but alas, we
don't have it :-(.  thanks in advance for any insight/help...

- sam falkner
  motorola cellular infrastructure division
  ...!uunet!motcid!falkner



More information about the Comp.unix.wizards mailing list