Search code examples
winapifilesystemsntfskernel32windows-kernel

Equivalent of Linux sync_file_range system call on windows?


I need to fsync a range of byte I appended to a file without forcing a flush on the metadata (filesize,...).


Solution

  • As you've said it's ring3 and it's C++, here is the answer:

    You need to call FlushViewOfFile after mapping the file. According to MSDN:

    The FlushViewOfFile function does not flush the file metadata, and it does not wait to return until the changes are flushed from the underlying hardware disk cache and physically written to disk.

    source: https://msdn.microsoft.com/en-us/library/windows/desktop/aa366563%28v=vs.85%29.aspx

    An example code that writes data and uses FlushViewOfFile is here: http://forums.codeguru.com/showthread.php?367742-FlushViewOfFile-does-not-Flush