System Interface Guide

Synchronizing a File

The fsync(3C) and fdatasync(3R) functions explicitly synchronize a file to secondary storage.

fsync(3C) guarantees the function is synchronized at the I/O file integrity completion level, while fdatasync(3R) guarantees the function is synchronized at the I/O data integrity completion level.

Applications can synchronize each I/O operation before the operation completes. Setting the O_DSYNC flag on the file description via open(2) or fcntl(2) ensures that all I/O writes (write(2) and aiowrite(3)) have reached I/O data completion before the operation is indicated as completed. Setting the O_SYNC flag on the file description ensures that all I/O writes have reached completion before the operation is indicated as completed. Setting the O_RSYNC flag on the file description ensures that all I/O reads read(2) and aio_read(3R)) have reached the same level of completion as request for writes by the setting, O_DSYNC or O_SYNC, on the descriptor.