I understand the working of write()
call wherein it writes the data only to kernel's buffers which is later written to disk by kernel after sorting the data optimally.
Calling fsync()
on file descriptor makes sure that data is written to disk as soon as it's posted in the kernel's buffer.
My question is, whether fsync()
should be called before write() or after write() call. I've read couple of books on the topic, looked on the internal as well but couldn't find a satisfactory answer.