What, exactly, are stat.st_blocks, statfs.f_bsize?

Jonathan I. Kamens jik at athena.mit.edu
Tue Feb 26 12:01:46 AEST 1991


  Well, if there are systems that measure st_blocks in terms of 1k blocks, how
can I detect them in my source code?

  Assuming that it's always 512 bytes would leave me with the following code:

int actual_bytes;
struct stat statbuf;

... assume statbuf is initialized ...

#ifdef ST_BLOCKS_EXISTS
actual_bytes = statbuf.st_blocks * 512;
#else
actual_bytes = statbuf.st_size;
#endif /* ST_BLOCKS_EXISTS */

But this is going to lose on sites that have 1k blocks.  Is there any way to
detect them.

  And, on a historical note, what led to the decision to measure in terms of
512-byte blocks, and why do some sites measure in terms of 1k blocks instead?

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710



More information about the Comp.unix.wizards mailing list