fsync(3C)
NAME
fsync − synchronize a file’s in-memory state with that on the physical medium
SYNOPSIS
#include <unistd.h>
int fsync(int fildes);
DESCRIPTION
The fsync() function moves all modified data and attributes of the file descriptor fildes to a storage device. When fsync() returns, all in-memory modified copies of buffers associated with fildes have been written to the physical medium. The fsync() function is different from sync(), which schedules disk I/O for all files but returns before the I/O completes. The fsync() function forces all outstanding data operations to synchronized file integrity completion (see fcntl(5) definition of O_SYNC.)
The fsync() function should be used by programs that require that a file be in a known state. For example, a program that contains a simple transaction facility might use fsync() to ensure that all changes to a file or files caused by a given transaction were recorded on a storage medium.
RETURN VALUES
Upon successful completion, a value of 0 is returned. Otherwise, a value of −1 is returned and errno is set to indicate the error.
ERRORS
The fsync() function fails if one or more of the following are true:
EBADF The fildes argument is not a valid file descriptor.
EINTR A signal was caught during execution of the fsync() function.
EIO An I/O error occurred while reading from or writing to the file system.
ENOSPC There was no free space remaining on the device containing the file.
ETIMEDOUT Remote connection timed out. This occurs when the file is on an NFS file system mounted with the soft option. See mount_nfs(1M).
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
| MT-Level | Async-Signal-Safe |
SEE ALSO
mount_nfs(1M), sync(2), fdatasync(3R), attributes(5), fcntl(5)
NOTES
The way the data reach the physical medium depends on both implementation and hardware. The fsync() function returns when the device driver tells it that the write has taken place.
SunOS 5.6 — Last change: 27 Jan 1997