xref: /freebsd/lib/libsys/aio_fsync.2 (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1.\" Copyright (c) 2013 Sergey Kandaurov
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.Dd November 15, 2023
26.Dt AIO_FSYNC 2
27.Os
28.Sh NAME
29.Nm aio_fsync
30.Nd asynchronous file synchronization (REALTIME)
31.Sh LIBRARY
32.Lb libc
33.Sh SYNOPSIS
34.In aio.h
35.Ft int
36.Fn aio_fsync "int op" "struct aiocb *iocb"
37.Sh DESCRIPTION
38The
39.Fn aio_fsync
40system call allows the calling process to move all modified data
41associated with the descriptor
42.Fa iocb->aio_fildes
43to a permanent storage device.
44The call returns immediately after the synchronization request has been
45enqueued to the descriptor; the synchronization may or may not have
46completed at the time the call returns.
47.Pp
48The
49.Fa op
50argument can be set to
51.Dv O_SYNC
52to cause all currently queued I/O operations to be completed
53as if by a call to
54.Xr fsync 2 ,
55or
56.Dv O_DSYNC
57for the behavior of
58.Xr fdatasync 2 .
59.Pp
60The
61.Fa iocb
62pointer may be subsequently used as an argument to
63.Fn aio_return
64and
65.Fn aio_error
66in order to determine return or error status for the enqueued operation
67while it is in progress.
68.Pp
69If the request could not be enqueued (generally due to invalid arguments),
70the call returns without having enqueued the request.
71.Pp
72The
73.Fa iocb->aio_sigevent
74structure can be used to request notification of the operation's
75completion as described in
76.Xr aio 4 .
77.Sh RESTRICTIONS
78The Asynchronous I/O Control Block structure pointed to by
79.Fa iocb
80must remain valid until the
81operation has completed.
82.Pp
83The asynchronous I/O control buffer
84.Fa iocb
85should be zeroed before the
86.Fn aio_fsync
87call to avoid passing bogus context information to the kernel.
88.Pp
89Modification of the Asynchronous I/O Control Block structure is not allowed
90while the request is queued.
91.Sh RETURN VALUES
92.Rv -std aio_fsync
93.Sh ERRORS
94The
95.Fn aio_fsync
96system call will fail if:
97.Bl -tag -width Er
98.It Bq Er EAGAIN
99The request was not queued because of system resource limitations.
100.It Bq Er EINVAL
101The asynchronous notification method in
102.Fa iocb->aio_sigevent.sigev_notify
103is invalid or not supported.
104.It Bq Er EOPNOTSUPP
105Asynchronous file synchronization operations on the file descriptor
106.Fa iocb->aio_fildes
107are unsafe and unsafe asynchronous I/O operations are disabled.
108.It Bq Er EINVAL
109A value of the
110.Fa op
111argument is not set to
112.Dv O_SYNC
113or
114.Dv O_DSYNC .
115.El
116.Pp
117The following conditions may be synchronously detected when the
118.Fn aio_fsync
119system call is made, or asynchronously, at any time thereafter.
120If they are detected at call time,
121.Fn aio_fsync
122returns -1 and sets
123.Va errno
124appropriately; otherwise the
125.Fn aio_return
126system call must be called, and will return -1, and
127.Fn aio_error
128must be called to determine the actual value that would have been
129returned in
130.Va errno .
131.Bl -tag -width Er
132.It Bq Er EBADF
133The
134.Fa iocb->aio_fildes
135argument
136is not a valid descriptor.
137.It Bq Er EINVAL
138This implementation does not support synchronized I/O for this file.
139.El
140.Pp
141If the request is successfully enqueued, but subsequently cancelled
142or an error occurs, the value returned by the
143.Fn aio_return
144system call is per the
145.Xr read 2
146and
147.Xr write 2
148system calls, and the value returned by the
149.Fn aio_error
150system call is one of the error returns from the
151.Xr read 2
152or
153.Xr write 2
154system calls.
155.Sh SEE ALSO
156.Xr aio_cancel 2 ,
157.Xr aio_error 2 ,
158.Xr aio_read 2 ,
159.Xr aio_return 2 ,
160.Xr aio_suspend 2 ,
161.Xr aio_waitcomplete 2 ,
162.Xr aio_write 2 ,
163.Xr fsync 2 ,
164.Xr sigevent 3 ,
165.Xr siginfo 3 ,
166.Xr aio 4
167.Sh STANDARDS
168The
169.Fn aio_fsync
170system call is expected to conform to the
171.St -p1003.1
172standard.
173.Sh HISTORY
174The
175.Fn aio_fsync
176system call first appeared in
177.Fx 7.0 .
178The
179.Dv O_DSYNC
180option appeared in
181.Fx 13.0 .
182