Comment by jorangreef
10 years ago
"That's not guaranteed to work in the face of crashes. The problem is that the directory update could get flushed to disk before the file data."
No, it can work, provided that the temporary file is fsynced before being renamed, the parent directory is fsynced after renaming the file, and that the application only considers the rename to have taken place after the parent directory is fsynced (not after the rename call itself).
FSYNC is not enough. You also have to make sure that NCQ is disabled:
https://en.wikipedia.org/wiki/Native_Command_Queuing
OS can use Force Unit Access flag with NCQ to control disk buffering: https://en.wikipedia.org/wiki/Disk_buffer#Force_Unit_Access_...