Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
fdatasync(2)
Edit
PageHistory
Diff
Info
LikePages
fdatasync - synchronize a file's in-core data with that on disk !!SYNOPSIS __#include <unistd.h>__ __#ifdef _POSIX_SYNCHRONIZED_IO__ __int fdatasync(int__ ''fd''__);__ __#endif__ !!DESCRIPTION fdatasync(2) flushes all data buffers of a file to disk (before the system call returns). It resembles fsync(2) but is not required to update the metadata such as access time. Applications that access databases or log files often write a tiny data fragment (e.g., one line in a log file) and then call fsync(2) immediately in order to ensure that the written data is physically stored on the harddisk. Unfortunately, fsync(2) will always initiate two write operations: one for the newly written data and another one in order to update the modification time stored in the inode. If the modification time is not a part of the transaction concept fdatasync(2) can be used to avoid unnecessary inode disk write operations. !!RETURN VALUE On success, zero is returned. On error, -1 is returned, and ''errno'' is set appropriately. !!ERRORS ;[EBADF]: ''fd'' is not a valid file descriptor open for writing. ;[EROFS], [EINVAL]: ''fd'' is bound to a special file which does not support synchronization. ;[EIO]: An error occurred during synchronization. !!BUGS Currently (Linux 2.2) fdatasync(2) is equivalent to fsync(2) !!CONFORMING TO POSIX1b (formerly POSIX.4) !!EXAMPLES /* * This program demonstrates fdatasync * */ #include <sys/stat.h> /* for S_* constants */ #include <sys/types.h> /* for mode_t for creat() */ #include <string.h> /* for strerror() prototype */ #include <fcntl.h> /* for creat() prototype */ #include <stdio.h> /* for fprintf(),stderr protype */ #include <errno.h> /* for errno prototype */ #include <unistd.h> /* for write(2), fdatasync(2), close(2) prototypes */ #define FILENAME "/tmp/fdatasync.example" #define TEXT "blargh!\n" int main(int argc,char **argv) { int fd; int err; fd = creat(FILENAME,S_IRUSR|S_IWUSR); if (fd==-1) { fprintf( stderr, "creat(\"%s\",S_IRUSR|S_IWUSR): %s (%i)\n", FILENAME, strerror(errno), errno); return 1; } err=write(fd,TEXT,strlen(TEXT)); if (err==-1) { fprintf( stderr, "write(fd,\"%s\",strlen(\"%s\")): %s (%i)\n", TEXT, TEXT, strerror(errno), errno); return 1; } if (err!=strlen(TEXT)) { fprintf(stderr,"Failed to write all the data, and I'm lazy and not " "going to retry\n"); return 1; } /* Flush the data only */ if (fdatasync(fd)==-1) { fprintf( stderr, "fdatasync(fd): %s (%i)\n", strerror(errno), errno); return 1; } if (close(fd)==-1) { fprintf( stderr, "close(fd): %s (%i)\n", strerror(errno), errno); return 1; } printf( "%s successfully written\n", FILENAME); return 0; } !!SEE ALSO fsync(2), B.O. Gallmeister, POSIX.4, O'Reilly, pp. 220-223 and 343.
4 pages link to
fdatasync(2)
:
Man2f
sync(2)
syscalls(2)
fsync(2)
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.