Blame man2/sync.2

Packit 7cfc04
.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
Packit 7cfc04
.\" and Copyright (c) 2011 Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" Modified by Michael Haardt <michael@moria.de>
Packit 7cfc04
.\" Modified Sat Jul 24 12:02:47 1993 by Rik Faith <faith@cs.unc.edu>
Packit 7cfc04
.\" Modified 15 Apr 1995 by Michael Chastain <mec@shell.portal.com>:
Packit 7cfc04
.\"   Added reference to `bdflush(2)'.
Packit 7cfc04
.\" Modified 960414 by Andries Brouwer <aeb@cwi.nl>:
Packit 7cfc04
.\"   Added the fact that since 1.3.20 sync actually waits.
Packit 7cfc04
.\" Modified Tue Oct 22 22:27:07 1996 by Eric S. Raymond <esr@thyrsus.com>
Packit 7cfc04
.\" Modified 2001-10-10 by aeb, following Michael Kerrisk.
Packit 7cfc04
.\" 2011-09-07, mtk, Added syncfs() documentation,
Packit 7cfc04
.\"
Packit 7cfc04
.TH SYNC 2 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
sync, syncfs \- commit filesystem caches to disk
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.B #include <unistd.h>
Packit 7cfc04
.PP
Packit 7cfc04
.B void sync(void);
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int syncfs(int " fd );
Packit 7cfc04
.PP
Packit 7cfc04
.in -4n
Packit 7cfc04
Feature Test Macro Requirements for glibc (see
Packit 7cfc04
.BR feature_test_macros (7)):
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
.BR sync ():
Packit 7cfc04
.ad l
Packit 7cfc04
.RS 4
Packit 7cfc04
_XOPEN_SOURCE\ >=\ 500
Packit 7cfc04
.\"    || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
Packit 7cfc04
    || /* Since glibc 2.19: */ _DEFAULT_SOURCE
Packit 7cfc04
    || /* Glibc versions <= 2.19: */ _BSD_SOURCE
Packit 7cfc04
.RE
Packit 7cfc04
.ad
Packit 7cfc04
.PP
Packit 7cfc04
.BR syncfs ():
Packit 7cfc04
.ad l
Packit 7cfc04
.RS 4
Packit 7cfc04
_GNU_SOURCE
Packit 7cfc04
.RE
Packit 7cfc04
.ad
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
.BR sync ()
Packit 7cfc04
causes all pending modifications to filesystem metadata and cached file
Packit 7cfc04
data to be written to the underlying filesystems.
Packit 7cfc04
.PP
Packit 7cfc04
.BR syncfs ()
Packit 7cfc04
is like
Packit 7cfc04
.BR sync (),
Packit 7cfc04
but synchronizes just the filesystem containing file
Packit 7cfc04
referred to by the open file descriptor
Packit 7cfc04
.IR fd .
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
.BR syncfs ()
Packit 7cfc04
returns 0 on success;
Packit 7cfc04
on error, it returns \-1 and sets
Packit 7cfc04
.I errno
Packit 7cfc04
to indicate the error.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.BR sync ()
Packit 7cfc04
is always successful.
Packit 7cfc04
.PP
Packit 7cfc04
.BR syncfs ()
Packit 7cfc04
can fail for at least the following reason:
Packit 7cfc04
.TP
Packit 7cfc04
.B EBADF
Packit 7cfc04
.I fd
Packit 7cfc04
is not a valid file descriptor.
Packit 7cfc04
.SH VERSIONS
Packit 7cfc04
.BR syncfs ()
Packit 7cfc04
first appeared in Linux 2.6.39;
Packit 7cfc04
library support was added to glibc in version 2.14.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
.BR sync ():
Packit 7cfc04
POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
Packit 7cfc04
.PP
Packit 7cfc04
.BR syncfs ()
Packit 7cfc04
is Linux-specific.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
Since glibc 2.2.2, the Linux prototype for
Packit 7cfc04
.BR sync ()
Packit 7cfc04
is as listed above,
Packit 7cfc04
following the various standards.
Packit 7cfc04
In glibc 2.2.1 and earlier,
Packit 7cfc04
it was "int sync(void)", and
Packit 7cfc04
.BR sync ()
Packit 7cfc04
always returned 0.
Packit 7cfc04
.PP
Packit 7cfc04
According to the standard specification (e.g., POSIX.1-2001),
Packit 7cfc04
.BR sync ()
Packit 7cfc04
schedules the writes, but may return before the actual
Packit 7cfc04
writing is done.  However Linux waits for I/O completions,
Packit 7cfc04
and thus
Packit 7cfc04
.BR sync ()
Packit 7cfc04
or
Packit 7cfc04
.BR syncfs ()
Packit 7cfc04
provide the same guarantees as fsync called on every file in
Packit 7cfc04
the system or filesystem respectively.
Packit 7cfc04
.SH BUGS
Packit 7cfc04
Before version 1.3.20 Linux did not wait for I/O to complete
Packit 7cfc04
before returning.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR sync (1),
Packit 7cfc04
.BR fdatasync (2),
Packit 7cfc04
.BR fsync (2)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.