Reputation: 2655
I do most of my programming on embedded processors, or on linux. When i need to sync data to my persistant store, i usually use the sync(2) system call. Is there an equivelent for Windows?
Upvotes: 4
Views: 3104
Reputation: 387
See here: https://jeffpar.github.io/kbarchive/kb/066/Q66052/
When you initially open your file using fopen, include the "c" mode option as the LAST OPTION:
fopen( path, "wc") // w - write mode, c - allow immediate commit to disk
Then when you want to force a flush to disk, call
_flushall()
We made this call before calling
fclose()
Note that this approach does NOT required Administrative rights, which FlushFileBuffers
does require.
From that above site:
"Microsoft C/C++ version 7.0 introduces the "c" mode option for the fopen() function. When an application opens a file and specifies the "c" mode, the run-time library writes the contents of the file buffer to disk when the application calls the fflush() or _flushall() function. "
Upvotes: 0
Reputation: 12228
If you are using posix file functions (fopen() etc.), you can use _flushall:
http://msdn.microsoft.com/en-us/library/s9xk9ehd%28v=vs.80%29.aspx
Upvotes: 0
Reputation: 683
http://msdn.microsoft.com/en-us/library/aa364439(VS.85).aspx http://www.codeproject.com/KB/system/EjectMediaByLetter.aspx
FlushFileBuffers with a handle to a volume. You have to do this for every volume :(
Upvotes: 4
Reputation: 29450
Use FlushFileBuffers, but you need a handle to the file you need flushed.
Upvotes: 3