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