www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21627] New: macOS: std.stdio.File.sync does not guarantee to

https://issues.dlang.org/show_bug.cgi?id=21627

          Issue ID: 21627
           Summary: macOS:  std.stdio.File.sync does not guarantee to be
                    written to disk
           Product: D
           Version: D2
          Hardware: All
                OS: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: kubo39 gmail.com

The documentation(https://dlang.org/phobos/std_stdio.html#.File.sync) says:

 Forces any data buffered by the OS to be written to disk.
 Call flush before calling this function to flush the C FILE buffers first.
Accoriding to macOS's manapge, however, fsync(2) does not guarantee to be written to disk. https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fsync.2.html
 Note that while fsync() will flush all data from the host to the drive
 (i.e. the "permanent storage device"), the drive itself may not physically
 write the data to the platters for quite some time and it may be
 written in an out-of-order sequence.

 Specifically, if the drive loses power or the OS crashes, the application
 may find that only some or none of their data was written.  The disk
 drive may also re-order the data so that later writes may be present,
 while earlier writes are not.

 This is not a theoretical edge case.  This scenario is easily reproduced
 with real world workloads and drive power failures.
The manpage also says that the F_FULLFSYNC fcntl would be useful in this case.
 For applications that require tighter guarantees about the integrity of
 their data, Mac OS X provides the F_FULLFSYNC fcntl.  The F_FULLFSYNC
 fcntl asks the drive to flush all buffered data to permanent storage.
I think std.stdio.File.sync should use F_FULLSYNC fcntl. --
Feb 10