Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!mit-eddie!bbn!rochester!pt.cs.cmu.edu!b.gp.cs.cmu.edu!Ralf.Brown@B.GP.CS.CMU.EDU
From: Ralf.Brown@B.GP.CS.CMU.EDU
Newsgroups: comp.sys.ibm.pc
Subject: Re: disk updates and power failures
Message-ID: <22d356a0@ralf>
Date: 7 Jul 88 10:46:56 GMT
Sender: netnews@pt.cs.cmu.edu
Lines: 35
In-Reply-To: <472@apctrc.UUCP>

In article <472@apctrc.UUCP>, zgel05@apctrc.UUCP (George E. Lehmann) writes:
} Doesn't DOS buffer writes interminably beyond the normal C
}programmer's control, preventing my knowing what has actually made it out
}to disk?

Yes, it can and does, but only if both of the following conditions are met:
        a. the file remains open
        b. no call to INT 21h/AH=0Dh (DISK RESET) is made

DOS writes out any buffered data if the file is closed, and also when it is
told to reset the disk subsystem.  You can thus force the data to be written
by closing and reopening the file (which also updates the file's directory
entry, something that DISK RESET doesn't do).  Since opening a file is
expensive, you can make a duplicate of the file handle and close the duplicate,
like so:

void commit_file(int handle)
{
   int new_handle = dup(handle) ;

   close(new_handle) ;
}

Note that DOS 3.3 finally has a function to write out a file's buffered data:

INT 21 - DOS 3.3 - COMMIT FILE, WRITE ALL BUFFERED DATA TO DISK
        AH = 68h
        BX = file handle
Return: carry flag set on error (and error code in AX)

--
UUCP: {ucbvax,harvard}!cs.cmu.edu!ralf -=-=-=- Voice: (412) 268-3053 (school)
ARPA: ralf@cs.cmu.edu  BIT: ralf%cs.cmu.edu@CMUCCVMA  FIDO: Ralf Brown 1:129/31
Disclaimer? I     |Ducharm's Axiom:  If you view your problem closely enough
claimed something?|   you will recognize yourself as part of the problem.