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