Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.unix.internals Subject: Re: What, exactly, are stat.st_blocks, statfs.f_b Message-ID: <6555@auspex.auspex.com> Date: 11 Mar 91 19:05:35 GMT References: <6487@auspex.auspex.com> <2992@cirrusl.UUCP> <1991Mar11.001544.29006@athena.mit.edu> Organization: Auspex Systems, Santa Clara Lines: 50 > 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@cs.edinburgh.ac.uk (Paul Anderson) Newsgroups: comp.unix.internals Subject: Re: What, exactly, are stat.st_blocks, statfs.f_b Message-ID: <7235@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.