Article View: comp.os.os2.programmer
Article #2958Re: How do I flush disk buffer?
From: Mike Lempriere
Date: Sat, 19 Dec 1992 03:10
Date: Sat, 19 Dec 1992 03:10
35 lines
2208 bytes
2208 bytes
David Charlap (dic5340@hertz.njit.edu) wrote: : In article <92349.025025DLVGC@CUNYVM.BITNET> DLVGC@CUNYVM.BITNET (Dimitri Vulis) writes: : >I've had a similar problem (keeping the log file in the event the power : >goes off) and simply calling fflush(fptr) after every fprintf seems to : >commit the data to disk right away. (Including writing over a LAN Server : >to a networked disk). I even wrote a little function wrlog using stdargs : >that first passes its args to fprintf(logfptr, then fflush(logfpr)'s. : > : >Of course, fflush _may_ work differently under gcc (I tried this with : >both icc and ms c 6.0) : : If you use OS/2 calls (like DosOpen, DosWrite, DosClose) instead of C : library calls (like fopen, fwrite, fclose), you'll notice an option on : DosOpen which tells the system not to cache the file handle. This may : do what you want it to. [.sig deleted] ------------------------------------------------------------------------------ You must've missed my original posting. I originally wrote the program using fopen(), fwrite(), fflush(). This did not work. I changed it to DosOpen(OPEN_FLAGS_NO_CACHE), DosWrite(). This did not work either. I tried DosOpen(OPEN_FLAGS_WRITE_THROUGH). This worked, but is pretty harsh, I don't want to pound every write directly out to disk, and I can't allow my program to pend until the write happens. I got it doing what I wanted by checking the time since the last write every time I go t do a write, and doing a DosSetFHandState(OPEN_FLAGS_WRITE_THROUGH) if it's been longer than 10 minutes, then setting it back with a DosSetFHandState(0). This is exactly the effact that I want, It's just a bit of a nuisance. I'd rather if NO_CACHE did what it sounds like it's supposed to do.
Technical Details
Message-ID:
<1992Dec19.031015.8974@networx.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!psinntp!openwx!mikelReferences:
<1992Dec15.015458.15556@njitgw.njit.edu>Show Full Headers
Complete Article Headers
Newsgroups: comp.os.os2.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!psinntp!openwx!mikel From: mikel@networx.com (Mike Lempriere) Subject: Re: How do I flush disk buffer? Message-ID: <1992Dec19.031015.8974@networx.com> Sender: usenet@networx.com (Usenet News Account) Organization: NetWorx X-Newsreader: TIN [version 1.1 PL6] References: <1992Dec15.015458.15556@njitgw.njit.edu> Date: Sat, 19 Dec 1992 03:10:15 GMT Lines: 35