xref: /freebsd-14.2/lib/libc/sys/aio_write.2 (revision d8aaf097)
1.\" Copyright (c) 1999 Softweyr LLC.
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 Softweyr LLC 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 Softweyr LLC 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 January 2, 2021
26.Dt AIO_WRITE 2
27.Os
28.Sh NAME
29.Nm aio_write ,
30.Nm aio_writev
31.Nd asynchronous write to a file (REALTIME)
32.Sh LIBRARY
33.Lb libc
34.Sh SYNOPSIS
35.In aio.h
36.Ft int
37.Fn aio_write "struct aiocb *iocb"
38.In sys/uio.h
39.Ft int
40.Fn aio_writev "struct aiocb *iocb"
41.Sh DESCRIPTION
42The
43.Fn aio_write
44and
45.Fn aio_writev
46system calls allow the calling process to write
47to the descriptor
48.Fa iocb->aio_fildes .
49.Fn aio_write
50will write
51.Fa iocb->aio_nbytes
52from the buffer pointed to by
53.Fa iocb->aio_buf ,
54whereas
55.Fn aio_writev
56gathers the data from the
57.Fa iocb->aio_iovcnt
58buffers specified by the members of the
59.Fa iocb->aio_iov
60array.
61Both syscalls return immediately after the write request has been enqueued
62to the descriptor; the write may or may not have completed at the time
63the call returns.
64If the request could not be enqueued, generally due
65to invalid arguments, the call returns without having enqueued the
66request.
67.Pp
68For
69.Fn aio_writev
70the
71.Fa iovec
72structure is defined in
73.Xr writev 2 .
74.Pp
75If
76.Dv O_APPEND
77is set for
78.Fa iocb->aio_fildes ,
79write operations append to the file in the same order as the calls were
80made.
81If
82.Dv O_APPEND
83is not set for the file descriptor, the write operation will occur at
84the absolute position from the beginning of the file plus
85.Fa iocb->aio_offset .
86.Pp
87If
88.Dv _POSIX_PRIORITIZED_IO
89is defined, and the descriptor supports it, then the enqueued
90operation is submitted at a priority equal to that of the calling
91process minus
92.Fa iocb->aio_reqprio .
93.Pp
94The
95.Fa iocb
96pointer may be subsequently used as an argument to
97.Fn aio_return
98and
99.Fn aio_error
100in order to determine return or error status for the enqueued operation
101while it is in progress.
102.Pp
103If the request is successfully enqueued, the value of
104.Fa iocb->aio_offset
105can be modified during the request as context, so this value must not
106be referenced after the request is enqueued.
107.Pp
108The
109.Fa iocb->aio_sigevent
110structure can be used to request notification of the operation's
111completion as described in
112.Xr aio 4 .
113.Sh RESTRICTIONS
114The Asynchronous I/O Control Block structure pointed to by
115.Fa iocb
116and the buffer that the
117.Fa iocb->aio_buf
118member of that structure references must remain valid until the
119operation has completed.
120.Pp
121The asynchronous I/O control buffer
122.Fa iocb
123should be zeroed before the
124.Fn aio_write
125or
126.Fn aio_writev
127system call to avoid passing bogus context information to the kernel.
128.Pp
129Modifications of the Asynchronous I/O Control Block structure or the
130buffer contents are not allowed while the request is queued.
131.Pp
132If the file offset in
133.Fa iocb->aio_offset
134is past the offset maximum for
135.Fa iocb->aio_fildes ,
136no I/O will occur.
137.Sh RETURN VALUES
138.Rv -std aio_write aio_writev
139.Sh ERRORS
140The
141.Fn aio_write
142and
143.Fn aio_writev
144system calls will fail if:
145.Bl -tag -width Er
146.It Bq Er EAGAIN
147The request was not queued because of system resource limitations.
148.It Bq Er EFAULT
149Part of
150.Fa aio_iov
151points outside the process's allocated address space.
152.It Bq Er EINVAL
153The asynchronous notification method in
154.Fa iocb->aio_sigevent.sigev_notify
155is invalid or not supported.
156.It Bq Er EOPNOTSUPP
157Asynchronous write operations on the file descriptor
158.Fa iocb->aio_fildes
159are unsafe and unsafe asynchronous I/O operations are disabled.
160.El
161.Pp
162The following conditions may be synchronously detected when the
163.Fn aio_write
164or
165.Fn aio_writev
166system call is made, or asynchronously, at any time thereafter.
167If they
168are detected at call time,
169.Fn aio_write
170or
171.Fn aio_writev
172returns -1 and sets
173.Va errno
174appropriately; otherwise the
175.Fn aio_return
176system call must be called, and will return -1, and
177.Fn aio_error
178must be called to determine the actual value that would have been
179returned in
180.Va errno .
181.Bl -tag -width Er
182.It Bq Er EBADF
183The
184.Fa iocb->aio_fildes
185argument
186is invalid, or is not opened for writing.
187.It Bq Er EINVAL
188The offset
189.Fa iocb->aio_offset
190is not valid, the priority specified by
191.Fa iocb->aio_reqprio
192is not a valid priority, or the number of bytes specified by
193.Fa iocb->aio_nbytes
194is not valid.
195.El
196.Pp
197If the request is successfully enqueued, but subsequently canceled
198or an error occurs, the value returned by the
199.Fn aio_return
200system call is per the
201.Xr write 2
202system call, and the value returned by the
203.Fn aio_error
204system call is either one of the error returns from the
205.Xr write 2
206system call, or one of:
207.Bl -tag -width Er
208.It Bq Er EBADF
209The
210.Fa iocb->aio_fildes
211argument
212is invalid for writing.
213.It Bq Er ECANCELED
214The request was explicitly canceled via a call to
215.Fn aio_cancel .
216.It Bq Er EINVAL
217The offset
218.Fa iocb->aio_offset
219would be invalid.
220.El
221.Sh SEE ALSO
222.Xr aio_cancel 2 ,
223.Xr aio_error 2 ,
224.Xr aio_return 2 ,
225.Xr aio_suspend 2 ,
226.Xr aio_waitcomplete 2 ,
227.Xr sigevent 3 ,
228.Xr siginfo 3 ,
229.Xr aio 4
230.Sh STANDARDS
231The
232.Fn aio_write
233system call
234is expected to conform to the
235.St -p1003.1
236standard.
237.Pp
238The
239.Fn aio_writev
240system call is a FreeBSD extension, and should not be used in portable code.
241.Sh HISTORY
242The
243.Fn aio_write
244system call first appeared in
245.Fx 3.0 .
246The
247.Fn aio_writev
248system call first appeared in
249.Fx 13.0 .
250.Sh AUTHORS
251This manual page was written by
252.An Wes Peters Aq Mt [email protected] .
253.Sh BUGS
254Invalid information in
255.Fa iocb->_aiocb_private
256may confuse the kernel.
257