1.\" Copyright (c) 1983, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" Copyright (c) 2016 The FreeBSD Foundation 4.\" 5.\" Parts of this documentation were written by 6.\" Konstantin Belousov <kib@FreeBSD.org> under sponsorship 7.\" from the FreeBSD Foundation. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 3. Neither the name of the University nor the names of its contributors 18.\" may be used to endorse or promote products derived from this software 19.\" without specific prior written permission. 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" SUCH DAMAGE. 32.\" 33.Dd March 30, 2020 34.Dt FSYNC 2 35.Os 36.Sh NAME 37.Nm fdatasync , 38.Nm fsync 39.Nd "synchronise changes to a file" 40.Sh LIBRARY 41.Lb libc 42.Sh SYNOPSIS 43.In unistd.h 44.Ft int 45.Fn fdatasync "int fd" 46.Ft int 47.Fn fsync "int fd" 48.Sh DESCRIPTION 49The 50.Fn fsync 51system call 52causes all modified data and attributes of the file referenced by 53the file descriptor 54.Fa fd 55to be moved to a permanent storage device. 56This normally results in all in-core modified copies 57of buffers for the associated file to be written to a disk. 58.Pp 59The 60.Fn fdatasync 61system call causes all modified data of 62.Fa fd 63to be moved to a permanent storage device. 64Unlike 65.Fn fsync , 66the system call does not guarantee that file attributes or 67metadata necessary to access the file are committed to the permanent storage. 68.Pp 69The 70.Fn fsync 71system call 72should be used by programs that require a file to be 73in a known state, for example, in building a simple transaction 74facility. 75If the file metadata has already been committed, using 76.Fn fdatasync 77can be more efficient than 78.Fn fsync . 79.Pp 80Both 81.Fn fdatasync 82and 83.Fn fsync 84calls are cancellation points. 85.Sh RETURN VALUES 86.Rv -std fsync 87.Sh ERRORS 88The 89.Fn fsync 90and 91.Fn fdatasync 92calls fail if: 93.Bl -tag -width Er 94.It Bq Er EBADF 95The 96.Fa fd 97argument 98is not a valid descriptor. 99.It Bq Er EINVAL 100The 101.Fa fd 102argument 103refers to a socket, not to a file. 104.It Bq Er EIO 105An I/O error occurred while reading from or writing to the file system. 106.It Bq Er EINTEGRITY 107Corrupted data was detected while reading from the file system. 108.El 109.Sh SEE ALSO 110.Xr fsync 1 , 111.Xr sync 2 , 112.Xr syncer 4 , 113.Xr sync 8 114.Sh HISTORY 115The 116.Fn fsync 117system call appeared in 118.Bx 4.2 . 119The 120.Fn fdatasync 121system call appeared in 122.Fx 11.1 . 123.Sh BUGS 124The 125.Fn fdatasync 126system call currently does not guarantee that enqueued 127.Xr aio 4 128requests for the file referenced by 129.Fa fd 130are completed before the syscall returns. 131