ofstream, fsync and data loss bugs

Mateusz Loskot mateusz@loskot.net
Thu Mar 18 09:47:00 GMT 2010


Mateusz Loskot wrote:
> Pavel Sanda wrote:
>>> until standardized, that is no better than ext/stdio_filebuf - we
>>> should investigate whether other implementations are *somehow*
>>> trying to do something about it.
>>
>> I googled before asking here, but was able to find only hopeless
>> questions about (o)fstream and fsync without response.
> 
> AFAICT, the file streams implementation shipped with
> Microsoft Visual C++ does not perform any kind of low-level sync.
> This behaviour can be accomplished with Windows specific file
> flags [1] or flush [2] but neither of these is used in C++ streams,
> also not in C file I/O functions.
> 
> It looks Microsoft assumes this features are used through Windows API
> only. It seems to apply also to transactional NTFS, C++ library does not
> make any use of it.
> 
> [1] http://support.microsoft.com/kb/99794
> [2] FlushFileBuffers Function

One addition I've just come across, seems important one:

C++ file streams can be flushed to disk by
- fetching file descriptor from stream
- issuing _commit on fd

http://support.microsoft.com/kb/148505

Best regards,
-- 
Mateusz Loskot, http://mateusz.loskot.net



More information about the Libstdc++ mailing list