SYNCFS(3C) Standard C Library Functions SYNCFS(3C)

syncfssynchronize file system to disk

Standard C Library (libc, -lc)

#include <unistd.h>

int
syncfs(int fd);

The () function instructs the file system associated with the file descriptor, fd, to ensure that all pending data and metadata updates that are still in-memory are synchronized back to the file system's underlying storage devices. This function will block until all such writes are completed.

Not all file systems support this request. This may happen either because the file system has not been enhanced yet to support this request or because the file system does not support the idea of synchronizing data to a backing store such as the underlying socket file system or the read-only bootfs(4FS) file system.

If an application only cares about the state of a single file and its metadata, then it should use the fsync(3C) function instead. The traditional sync(2) function has two primary differences from the (function:) sync(2) instructs the system to schedule all I/O across all file systems to be synchronized and it does not guarantee that all that I/O is completed prior to returning. There is no non-blocking way to force I/O to be synchronized to a specific file system.

Upon successful completion, the syncfs() function returns and ensures that the file system data and metadata synchronization has already completed. Otherwise is returned and errno is set to indicate the error and outstanding file system data and metadata is not guaranteed to have been synchronized.

The syncfs() functions will fail if:

The fd argument is not a valid open file descriptor in the calling process.
There was no free space remaining on the file system's backing store or a quota was hit.
An I/O error occurred while reading or writing.
The file system backing the file descriptor, fd, does not support file system-wide synchronization.

It is possible that a remote file system (e.g. NFS) may fail with additional errors that are unique to the network based nature of the file system.

sync(2), fsync(3C)

July 13, 2024 OmniOS