This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ofstream, fsync and data loss bugs


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]