diff options
author | Matthew Dempsky <matthew@cvs.openbsd.org> | 2013-04-15 16:38:22 +0000 |
---|---|---|
committer | Matthew Dempsky <matthew@cvs.openbsd.org> | 2013-04-15 16:38:22 +0000 |
commit | 96993d5faa218d06d7239c746145d094c6015363 (patch) | |
tree | aba1640b13ba1e8e84f33592533a374ec8da3c0c /lib | |
parent | 0f2226790666d9d44c37ce200dff5668cddef63c (diff) |
Implement fdatasync() as a wrapper around fsync()
ok guenther, deraadt, jmc
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/Makefile.inc | 5 | ||||
-rw-r--r-- | lib/libc/gen/fdatasync.c | 13 | ||||
-rw-r--r-- | lib/libc/sys/Makefile.inc | 3 | ||||
-rw-r--r-- | lib/libc/sys/fsync.2 | 46 |
4 files changed, 55 insertions, 12 deletions
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 64d8df708c3..e39258c979b 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.58 2012/09/15 20:59:38 miod Exp $ +# $OpenBSD: Makefile.inc,v 1.59 2013/04/15 16:38:21 matthew Exp $ # gen sources .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/gen ${LIBCSRCDIR}/gen @@ -6,7 +6,8 @@ SRCS+= alarm.c assert.c auth_subr.c authenticate.c \ basename.c clock.c closedir.c confstr.c ctermid.c ctype_.c \ daemon.c devname.c dirfd.c dirname.c disklabel.c elf_hash.c err.c \ - errx.c errlist.c errno.c exec.c fnmatch.c fpclassify.c frexp.c \ + errx.c errlist.c errno.c exec.c \ + fdatasync.c fnmatch.c fpclassify.c frexp.c \ fstab.c ftok.c fts.c ftw.c getbsize.c getcap.c getcwd.c \ getdomainname.c getgrent.c getgrouplist.c gethostname.c \ getloadavg.c getlogin.c getmntinfo.c getnetgrent.c getpagesize.c \ diff --git a/lib/libc/gen/fdatasync.c b/lib/libc/gen/fdatasync.c new file mode 100644 index 00000000000..26612123a2c --- /dev/null +++ b/lib/libc/gen/fdatasync.c @@ -0,0 +1,13 @@ +/* $OpenBSD: fdatasync.c,v 1.1 2013/04/15 16:38:21 matthew Exp $ */ +/* + * Written by Matthew Dempsky, 2013. + * Public domain. + */ + +#include <unistd.h> + +int +fdatasync(int fd) +{ + return (fsync(fd)); +} diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index 0bd51eecbc5..a22d4bf77e6 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.109 2013/02/03 10:38:40 miod Exp $ +# $OpenBSD: Makefile.inc,v 1.110 2013/04/15 16:38:21 matthew Exp $ # $NetBSD: Makefile.inc,v 1.35 1995/10/16 23:49:07 jtc Exp $ # @(#)Makefile.inc 8.1 (Berkeley) 6/17/93 @@ -210,6 +210,7 @@ MLINKS+=clock_gettime.2 clock_settime.2 MLINKS+=dup.2 dup2.2 MLINKS+=execve.2 exect.2 MLINKS+=fhopen.2 fhstat.2 fhopen.2 fhstatfs.2 +MLINKS+=fsync.2 fdatasync.2 MLINKS+=getgid.2 getegid.2 MLINKS+=getitimer.2 setitimer.2 MLINKS+=getitimer.2 timeradd.3 diff --git a/lib/libc/sys/fsync.2 b/lib/libc/sys/fsync.2 index 166f852f7d6..1684c49dcfa 100644 --- a/lib/libc/sys/fsync.2 +++ b/lib/libc/sys/fsync.2 @@ -1,4 +1,4 @@ -.\" $OpenBSD: fsync.2,v 1.10 2013/03/31 22:11:26 guenther Exp $ +.\" $OpenBSD: fsync.2,v 1.11 2013/04/15 16:38:21 matthew Exp $ .\" $NetBSD: fsync.2,v 1.4 1995/02/27 12:32:38 cgd Exp $ .\" .\" Copyright (c) 1983, 1993 @@ -30,34 +30,50 @@ .\" .\" @(#)fsync.2 8.1 (Berkeley) 6/4/93 .\" -.Dd $Mdocdate: March 31 2013 $ +.Dd $Mdocdate: April 15 2013 $ .Dt FSYNC 2 .Os .Sh NAME -.Nm fsync +.Nm fsync , +.Nm fdatasync .Nd "synchronize a file's in-core state with that on disk" .Sh SYNOPSIS .Fd #include <unistd.h> .Ft int .Fn fsync "int fd" +.Ft int +.Fn fdatasync "int fd" .Sh DESCRIPTION +The .Fn fsync -causes all modified data and attributes of +function causes all modified data and attributes of .Fa fd to be moved to a permanent storage device. This normally results in all in-core modified copies of buffers for the associated file to be written to a disk. .Pp +The +.Fn fdatasync +function is similar to .Fn fsync +except that it only guarantees modified data +.Pq and metadata necessary to read that data +is committed to storage. +Other file modifications may be left unsynchronized. +.Pp +.Fn fsync +and +.Fn fdatasync should be used by programs that require a file to be in a known state, for example, in building a simple transaction facility. .Sh RETURN VALUES -A 0 value is returned on success. -A \-1 value indicates an error. +.Rv -std fsync fdatasync .Sh ERRORS The .Fn fsync -fails if: +and +.Fn fdatasync +functions fail if: .Bl -tag -width Er .It Bq Er EBADF .Fa fd @@ -74,10 +90,22 @@ An I/O error occurred while reading from or writing to the file system. .Sh STANDARDS The .Fn fsync -function conforms to +and +.Fn fdatasync +functions conform to .St -p1003.1-2008 . .Sh HISTORY The .Fn fsync -function call appeared in +function appeared in .Bx 4.2 . +The +.Fn fdatasync +function appeared in +.Ox 5.4 . +.Sh BUGS +The +.Fn fdatasync +function is currently a wrapper around +.Fn fsync , +so it synchronizes more state than necessary. |