Differences between version 2 and predecessor to the previous major change of fdatasync(2).
Other diffs: Previous Revision, Previous Author, or view the Annotated Edit History
Newer page: | version 2 | Last edited on Sunday, November 3, 2002 9:53:04 pm | by WikiAdmin | Revert |
Older page: | version 1 | Last edited on Tuesday, June 4, 2002 12:23:40 am | by perry | Revert |
@@ -1,88 +1,107 @@
-FDATASYNC
-!!!FDATASYNC
-NAME
-SYNOPSIS
-DESCRIPTION
-RETURN VALUE
-ERRORS
-BUGS
-CONFORMING TO
-SEE ALSO
-----
-!!NAME
-
-
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__
-__#include __
-
-
-__#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.
-__fdatasync__ flushes all data buffers of a file to disk
-(before the system call returns). It resembles __fsync__
-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__ immediately in order to ensure that the
-written data is physically stored on the harddisk.
-Unfortunately, __fsync__ 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__ 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.
-
-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)
-__EBADF__
+!!CONFORMING TO
+POSIX1b (formerly POSIX.4)
+!!EXAMPLES
+ /*
+ * This program demonstrates fdatasync
+ *
+ */
-''fd'' is not a valid file descriptor open
for
-writing
.
+ #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"
-__EROFS__
, __EINVAL__
+ 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;
+ }
-''
fd'' is bound to a special file which does not support
-synchronization.
+ 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;
+ }
-__EIO__
+ 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;
+ }
-An error occurred during synchronization.
-!!BUGS
+ if (close(fd)==-1) {
+ fprintf(
+ stderr,
+ "close(fd): %s (%i)\n",
+ strerror(errno),
+ errno);
+ return 1;
+ }
+ printf(
+ "%s successfully written\n",
+ FILENAME);
+ return 0;
+ }
-Currently (Linux 2.2) __fdatasync__ is equivalent to
-__fsync__.
-!!CONFORMING TO
-
-POSIX1b (formerly POSIX.4)
!!SEE ALSO
-
-
-
fsync(2), B.O. Gallmeister, POSIX.4, O'Reilly, pp.
-
220-223 and 343.
-----
+fsync(2), B.O. Gallmeister, POSIX.4, O'Reilly, pp. 220-223 and 343.