[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 1

fsync or fsync_range Subroutine

Purpose

Writes changes in a file to permanent storage.

Library

Standard C Library (libc.a)

Syntax

#include <unistd.h>

int fsync ( FileDescriptor)
int FileDescriptor;

int fsync_range (FileDescriptor, how, start, length)
int FileDescriptor;
int how;
off_t start;
off_t length;

Description

The fsync subroutine causes all modified data in the open file specified by the FileDescriptor parameter to be saved to permanent storage. On return from the fsync subroutine, all updates have been saved on permanent storage.

The fsync_range subroutine causes all modified data in the specified range of the open file specified by the FileDescriptor parameter to be saved to permanent storage. On return from the fsync_range subroutine, all updates in the specified range have been saved on permanent storage.

Data written to a file that a process has opened for deferred update (with the O_DEFER flag) is not written to permanent storage until another process issues an fsync_range or fsync call against this file or runs a synchronous write subroutine (with the O_SYNC flag) on this file. See the fcntl.h file and the open subroutine for descriptions of the O_DEFER and O_SYNC flags respectively.

Note
The file identified by the FileDescriptor parameter must be open for writing when the fsync_range or fsync subroutine is issued or the call is unsuccessful. This restriction was not enforced in BSD systems.

Parameters

FileDescriptor A valid, open file descriptor.
how How to flush, FDATASYNC, or FFILESYNC.
FDATASYNC
Write file data and enough of the meta-data to retrieve the data for the specified range.
FFILESYNC
All modified file data and meta-data for the specified range.
start Starting file offset.
length Length, or zero for everything.

Return Values

Upon successful completion, the fsync subroutine returns a value of 0. Otherwise, a value of -1 is returned and the errno global variable is set to indicate the error.

Upon successful completion, the fsync_range subroutine returns a value of 0. Otherwise a value of -1 is returned and the errno global variable is set to indicate the error.

Error Codes

The fsync subroutine is unsuccessful if one or more of the following are true:

EIO An I/O error occurred while reading from or writing to the file system.
EBADF The FileDescriptor parameter is not a valid file descriptor open for writing.
EINVAL The file is not a regular file.
EINTR The fsync subroutine was interrupted by a signal.

Related Information

The open, openx, or creat (open, openx, open64, creat, or creat64 Subroutine) subroutine, sync subroutine, write, writex, writev, or writevx subroutine.

The fcntl.h file.

Files, Directories, and File Systems Overview for Programmers in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs contains information about i-nodes, file descriptors, file-space allocation, and more.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]