annotate lib/fdatasync.c @ 15622:814138b4cfed

fdatasync: new module At least libvirt would like to use the lighter-weight fdatasync on platforms where it is supported, while still guaranteeing full sync (via the heavy-weight fsync fallback) on all platforms. I've got an open question to the Austin Group, since the POSIX 2008 wording is self-contradictory (unlike fsync, fdatasync requires EBADF on non-writable fds, but still mentions that read() errors must be propagated). I can see how fsync() would affect atime after read() while fdatasync() can skip that, explaining why fdatasync() might have the EBADF requirement, but on the other hand, that prevents an implementation (like ours) where fdatasync is a straight alias of fsync. At any rate, glibc allows fdatasync on read-only fds. * modules/fsync (Description): Document difference to fdatasync. * modules/fdatasync: New module. * m4/fdatasync.m4 (gl_FUNC_FDATASYNC): New file. * lib/fdatasync.c (fdatasync): Likewise. * m4/unistd_h.m4 (gl_UNISTD_H, gl_UNISTD_H_DEFAULTS): Set up defaults. * modules/unistd (Makefile.am): Set witnesses. * lib/unistd.in.h (fdatasync): Declare. * MODULES.html.sh: Document it. * doc/posix-functions/fdatasync.texi (fdatasync): Likewise. * modules/fdatasync-tests: New test. * tests/test-fdatasync.c: Likewise. Signed-off-by: Eric Blake <eblake@redhat.com>
author Eric Blake <eblake@redhat.com>
date Fri, 16 Sep 2011 09:59:23 -0600
parents
children 77a8f27f1e92
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15622
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
1 /* Emulate fdatasync on platforms that lack it.
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
2
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
3 Copyright (C) 2011 Free Software Foundation, Inc.
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
4
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
9
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
13 Lesser General Public License for more details.
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
14
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
17
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
18 #include <config.h>
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
19 #include <unistd.h>
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
20
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
21 int
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
22 fdatasync (int fd)
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
23 {
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
24 return fsync (fd);
814138b4cfed fdatasync: new module
Eric Blake <eblake@redhat.com>
parents:
diff changeset
25 }