9.45 fsync

int fsync(int fd, int flags);

The syscall does the same as sync, just only applied to fd. If the passed file is a device, the device will flush its internal caches.

If the file was just created, one might considering synchronizing the parent directory as well, as, depending on the FS and FS driver, parent directory entries are stored separately to the file, EXT-series filesystems come to mind.

If flags is not zero, only the data of the passed descriptor will be guaranteed to be flushed, and not modified metadata, this can be used in order to minimize disk activity even further.

The syscall returns 0 or -1 on failure, with the errno: