xref: /illumos-gate/usr/src/man/man3c/syncfs.3c (revision a2934841337103007c5d678161cb7f21286f172f)
14763305eSRobert Mustacchi.\"
24763305eSRobert Mustacchi.\" This file and its contents are supplied under the terms of the
34763305eSRobert Mustacchi.\" Common Development and Distribution License ("CDDL"), version 1.0.
44763305eSRobert Mustacchi.\" You may only use this file in accordance with the terms of version
54763305eSRobert Mustacchi.\" 1.0 of the CDDL.
64763305eSRobert Mustacchi.\"
74763305eSRobert Mustacchi.\" A full copy of the text of the CDDL should have accompanied this
84763305eSRobert Mustacchi.\" source.  A copy of the CDDL is also available via the Internet at
94763305eSRobert Mustacchi.\" http://www.illumos.org/license/CDDL.
104763305eSRobert Mustacchi.\"
114763305eSRobert Mustacchi.\"
124763305eSRobert Mustacchi.\" Copyright 2024 Oxide Computer Company
134763305eSRobert Mustacchi.\"
144763305eSRobert Mustacchi.Dd July 13, 2024
154763305eSRobert Mustacchi.Dt SYNCFS 3C
164763305eSRobert Mustacchi.Os
174763305eSRobert Mustacchi.Sh NAME
184763305eSRobert Mustacchi.Nm syncfs
194763305eSRobert Mustacchi.Nd synchronize file system to disk
204763305eSRobert Mustacchi.Sh LIBRARY
214763305eSRobert Mustacchi.Lb libc
224763305eSRobert Mustacchi.Sh SYNOPSIS
234763305eSRobert Mustacchi.In unistd.h
244763305eSRobert Mustacchi.Ft int
254763305eSRobert Mustacchi.Fo syncfs
264763305eSRobert Mustacchi.Fa "int fd"
274763305eSRobert Mustacchi.Fc
284763305eSRobert Mustacchi.Sh DESCRIPTION
294763305eSRobert MustacchiThe
304763305eSRobert Mustacchi.Fn syncfs
314763305eSRobert Mustacchifunction instructs the file system associated with the file descriptor,
324763305eSRobert Mustacchi.Fa fd ,
334763305eSRobert Mustacchito ensure that all pending data and metadata updates that are still
344763305eSRobert Mustacchiin-memory are synchronized back to the file system's underlying storage
354763305eSRobert Mustacchidevices.
364763305eSRobert MustacchiThis function will block until all such writes are completed.
374763305eSRobert Mustacchi.Pp
384763305eSRobert MustacchiNot all file systems support this request.
394763305eSRobert MustacchiThis may happen either because the file system has not been enhanced yet
404763305eSRobert Mustacchito support this request or because the file system does not support the
414763305eSRobert Mustacchiidea of synchronizing data to a backing store such as the underlying
424763305eSRobert Mustacchisocket file system or the read-only
434763305eSRobert Mustacchi.Xr bootfs 4FS
444763305eSRobert Mustacchifile system.
454763305eSRobert Mustacchi.Pp
464763305eSRobert MustacchiIf an application only cares about the state of a single file and its
474763305eSRobert Mustacchimetadata, then it should use the
484763305eSRobert Mustacchi.Xr fsync 3C
494763305eSRobert Mustacchifunction instead.
504763305eSRobert MustacchiThe traditional
514763305eSRobert Mustacchi.Xr sync 2
524763305eSRobert Mustacchifunction has two primary differences from the
53*a2934841SPeter Tribble.Fn syncfs
54*a2934841SPeter Tribblefunction:
554763305eSRobert Mustacchi.Xr sync 2
564763305eSRobert Mustacchiinstructs the system to schedule all I/O across all file
574763305eSRobert Mustacchisystems to be synchronized and it does not guarantee that all that
584763305eSRobert MustacchiI/O is completed prior to returning.
594763305eSRobert MustacchiThere is no non-blocking way to force I/O to be synchronized to a
604763305eSRobert Mustacchispecific file system.
614763305eSRobert Mustacchi.Sh RETURN VALUES
624763305eSRobert MustacchiUpon successful completion, the
634763305eSRobert Mustacchi.Fn syncfs
644763305eSRobert Mustacchifunction returns
654763305eSRobert Mustacchi.Sy 0
664763305eSRobert Mustacchiand ensures that the file system data and metadata synchronization has
674763305eSRobert Mustacchialready completed.
684763305eSRobert MustacchiOtherwise
694763305eSRobert Mustacchi.Sy -1
704763305eSRobert Mustacchiis returned
714763305eSRobert Mustacchiand
724763305eSRobert Mustacchi.Va errno
734763305eSRobert Mustacchiis set to indicate the error and outstanding file system data and
744763305eSRobert Mustacchimetadata is not guaranteed to have been synchronized.
754763305eSRobert Mustacchi.Sh ERRORS
764763305eSRobert MustacchiThe
774763305eSRobert Mustacchi.Fn syncfs
784763305eSRobert Mustacchifunctions will fail if:
794763305eSRobert Mustacchi.Bl -tag -width Er
804763305eSRobert Mustacchi.It Er EBADF
814763305eSRobert MustacchiThe
824763305eSRobert Mustacchi.Fa fd
834763305eSRobert Mustacchiargument is not a valid open file descriptor in the calling process.
844763305eSRobert Mustacchi.It Er EDQUOT, ENOSPC
854763305eSRobert MustacchiThere was no free space remaining on the file system's backing store or
864763305eSRobert Mustacchia quota was hit.
874763305eSRobert Mustacchi.It Er EIO
884763305eSRobert MustacchiAn I/O error occurred while reading or writing.
894763305eSRobert Mustacchi.It Er ENOSYS
904763305eSRobert MustacchiThe file system backing the file descriptor,
914763305eSRobert Mustacchi.Fa fd ,
924763305eSRobert Mustacchidoes not support file system-wide synchronization.
934763305eSRobert Mustacchi.El
944763305eSRobert Mustacchi.Pp
954763305eSRobert MustacchiIt is possible that a remote file system
964763305eSRobert Mustacchi.Pq e.g. NFS
974763305eSRobert Mustacchimay fail with additional errors that are unique to the network based
984763305eSRobert Mustacchinature of the file system.
994763305eSRobert Mustacchi.Sh INTERFACE STABILITY
1004763305eSRobert Mustacchi.Sy Committed
1014763305eSRobert Mustacchi.Sh MT-LEVEL
1024763305eSRobert Mustacchi.Sy Safe
1034763305eSRobert Mustacchi.Sh SEE ALSO
1044763305eSRobert Mustacchi.Xr sync 2 ,
1054763305eSRobert Mustacchi.Xr fsync 3C
106