after writing a files to an ext4 volume do I need to do more than flush to guarantee the file is fully written?

StackOverflow https://stackoverflow.com/questions/12021423

  •  27-06-2021
  •  | 
  •  

Question

I've written some code where its very important that beyond a certain point that the contents of a file are written to disk

I'm using ext4, such that the volumes integrity is guaranteed with the journal

in order to guarantee my file is actually on disk and not vulnerable to errors replaying the journal in the event of a crash, do I need to do anything more than flush()? I believe that's it, that the contract of flush is that the contents are on disk, and all buffers/caches are flushed

Was it helpful?

Solution

flush() ensures that all processes see the file in the same state, but does not guarantee that all bytes have been written to disk. A further call to fsync() or fdatasync() is required.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top