FAT | RFS | XFS

fsync()

PROTOTYPE

#include <posix.h>

int fsync(int fid);

DESCRIPTION

fsync() writes buffered data, both user data and metadata, to the underlying storage media for the volume holding the open file indicated by fid. fsync() also operates on devices under the “/device” branch, including stdout and stderr.

fsync() doesn’t return until all buffered changes for the volume are saved. The standard only requires the specified file to be flushed but because partial metadata updates are problematic and cached data is not referenced by which file it belongs to, every file on the volume is flushed.

If successful, fsync() returns 0. Otherwise, it sets errno and returns EOF.

ERROR CODES

EBADF fid is not the descriptor of a file open in write or append mode.
EROFS The volume is read-only.

EXAMPLE

  /*-----------------------------------------------------------------*/
  /* Flush file data to the flash media.                             */
  /*-----------------------------------------------------------------*/
  if (fsync(fid))
    return -1;