## fsync

#### OS/161 Reference Manual

### Name

fsync - flush filesystem data for a specific file to disk

### Library

Standard C Library (libc, -lc)

### Synopsis

`#include <unistd.h>`
`int`
`fsync(int` fd`);`

### Description

The `fsync` function forces a write of dirty filesystem buffers and other dirty filesystem state associated with the object referred to by fd to be written to disk.

`fsync` should not return until the writes are complete.

### Return Values

On success, `fsync` returns 0. On error, -1 is returned, and errno is set according to the error encountered.

### Errors

The following error codes should be returned under the conditions given. Other error codes may be returned for other cases not mentioned here.

| EBADF | fd is not a valid file handle.
EIO | A hard I/O error occurred.