Testing I/O success

John F. Haugh II jfh at rpp386.Dallas.TX.US
Fri Apr 21 10:33:58 AEST 1989


In article <8038 at boring.cwi.nl> siebren at cwi.nl (Siebren van der Zee) writes:
>In article <8019 at boring.cwi.nl>, I, siebren at cwi.nl (Siebren van der Zee) wrote:
>> You *CANNOT* detect disk-full always on unix, since I/O is lazy.
>
>As several people pointed out to me, I was wrong. Even though the actual
>write may take place by the time that the program has exited, the disk-
>blocks are allocated immediately. Only when the write fails, you won't
>be notified, unless you call fsync(int fd).
>This is true for 4.3 BSD, SunOS 3.5, Ultrix 2.2; every unix I could check.

Part wrong still.  The disk blocks aren't allocated until stdio has flushed
it's buffers and called write(), etc.  A common problem is programs which
never fclose() their buffered files and rely on exit() to do so.  ALWAYS
flush after writes which must check for I/O success.
-- 
John F. Haugh II                        +-Quote of the Week:-------------------
VoiceNet: (214) 250-3311   Data: -6272  | "When everyone else complies
InterNet: jfh at rpp386.Dallas.TX.US       |  I will too ..."
UucpNet : <backbone>!killer!rpp386!jfh  +-------------------  -- Doug Davis  --



More information about the Comp.std.c mailing list