lkml.org 
[lkml]   [1998]   [Dec]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: st_blocks - was: Re: crazy swapping


On Fri, 4 Dec 1998 Andries.Brouwer@cwi.nl wrote:
>
> if (st.st_blocks * 512 < st.st_size) {
> fprintf(stderr, "File %s appears to have holes in it");
>
> This is interesting.
> So far, the unit used in st_blocks has been undocumented.

It's not undocumented, it's just really really badly documented.

As far as I can tell, st_blocks is _always_ given in 512-byte entities,
for completely historical reasons, and has nothing to do with Linux other
than the fact that Linux tries to look like UNIX.

I assume (ie just rambling here) that it is just because historically UNIX
BLOCK_SIZE used to be designed to 512 at some time, and that st_blocks was
added first - so it just meant how many of these (hardcoded) 512-byte
blocks the file contained.

When st_blocksize was added, st_blocks had to remain in multiples of 512
bytes for backwards compatibility (otherwise "du" etc would be confused).

So st_blocksize means the "optimal minimum size for reading and writing"
(especially the latter - writing chunks less than st_blocksize is likely
to be a read-modify-write cycle when re-writing a file) and st_blocks is
"how many 512-byte blocks it takes on disk".

I suspect that you can get a good idea of how true this is of all unixes
by looking at the sources of GNU "du". I wouldn't be in the least
surprised if you find a few #ifdef's there for different UNIXes that do
this differently. But basically 512 is just a magic number.

Linus


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:46    [W:0.047 / U:0.188 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site