Subject: Re: HSM implementation proposal
To: None <tech-kern@NetBSD.ORG>
From: Christoph Badura <bad@ora.de>
List: tech-kern
Date: 12/09/1997 14:47:22
ghudson@mit.edu (Greg Hudson) writes:
>I quoth from read(2):

>     Upon successful completion, read() and readv() return the number of bytes
>     actually read and placed in the buffer.  The system guarantees to read
>     the number of bytes requested if the descriptor references a normal file
>     that has that many bytes left before the end-of-file, but in no other
>     case.

>It's not at all uncommon to rely on that assumption.  A lot of
>programs fstat() a file and then read in st_size bytes with no
>surrounding while loop.

Of course, programs doing what you describe have, aside from *not*
relying on that assumption, been broken since the introduction of
ftruncate(2).  The system never made a guarantee that the filesize does
not change between a call to stat(2)/fstat(2) and a subsequent call to
read(2) (or write(2) for that matter).

That's why O_APPEND was invented, too.

-- 
Christoph Badura

Now available in print: Lion's Commentary on UNIX 6th Edition, with Source Code
			http://www.peer-to-peer.com/