What, exactly, are stat.st_blocks, statfs.f_b
Guy Harris
guy at auspex.auspex.com
Tue Mar 12 05:05:35 AEST 1991
> I'm sorry to be so insistent, but I still haven't seen one clear,
>unequivocal answer to this question: If a system has st_blocks in its stat
>structure, then how can I tell what the count in st_blocks is in terms of?
Perhaps the *lack* of such an answer *is* the answer - i.e., the way you
tell is system-dependent. Sad, but seemingly true; while most systems
report in 512-byte units, according to another posting, at least at one
point Pyramid systems didn't:
From: paul at cs.edinburgh.ac.uk (Paul Anderson)
Newsgroups: comp.unix.internals
Subject: Re: What, exactly, are stat.st_blocks, statfs.f_b
Message-ID: <7235 at skye.cs.ed.ac.uk>
Date: 5 Mar 91 13:27:30 GMT
Organization: Department of Computer Science, University of Edinburgh
...
Things might have changed, but this certainly didn't used to be true of the
Pyramid system we had - st_blocks was in units of f_bsize. Things like "du"
gave results that were out by a factor of two (or more) depending on the
NFS filesystem that your files lived on! I agree with you that this was
wrong, but I have never seen the correct units actually stated anywhere.
S5R4 and 4.3-reno *finally* nail down the units in their documentation
(512 bytes), so hopefully Pyramid, and any others whose "stat()" calls
and NFS implementations don't use those units will change to report in
those units (both in "stat()" *and* in the NFS server code - the idea is
not just to fix programs running on the Pyramid, but to fix programs
running *elsewhere* accessing files on the Pyramid).
> Do I assume it's 512 everywhere?
Nope - see above.
> Do I do statfs on each file?
Nope - not all systems with an "st_blocks" field *have* "statfs()"
(e.g., vanilla 4.3BSD and 4.3-tahoe; Reno appears to have it).
>Or something else? I'm willing to use #ifdef magic in order to make
>it work on various different types of systems, but I haven't yet seen
>one clear answer to my question of *what* the #ifdef magic should do.
Well, it appears it should do a "statfs()", and multiply "st_blocks" by
"f_bsize/512", on a Pyramid, according to the above posting. It should
do nothing on 4.3-reno, S5R4 and SunOS (you may be screwed if those
systems are mounting file systems from a Pyramid, say, though). I can't
speak for other systems; I don't know if *anybody* can enumerate all the
systems.
More information about the Comp.unix.internals
mailing list