xref: /freebsd/lib/libsys/aio_read.2 (revision 1b37af092211f9947d9f089f452232b791b9eafc)
18269e767SBrooks Davis.\" Copyright (c) 1998 Terry Lambert
28269e767SBrooks Davis.\" All rights reserved.
38269e767SBrooks Davis.\"
48269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
58269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
68269e767SBrooks Davis.\" are met:
78269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
88269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer.
98269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
108269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer in the
118269e767SBrooks Davis.\"    documentation and/or other materials provided with the distribution.
128269e767SBrooks Davis.\"
138269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
148269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
158269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
168269e767SBrooks Davis.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
178269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
188269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
198269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
208269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
218269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
228269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
238269e767SBrooks Davis.\" SUCH DAMAGE.
248269e767SBrooks Davis.\"
25*1b37af09SEnji Cooper.Dd March 27, 2025
268269e767SBrooks Davis.Dt AIO_READ 2
278269e767SBrooks Davis.Os
288269e767SBrooks Davis.Sh NAME
298269e767SBrooks Davis.Nm aio_read ,
30a52cb4c4SKonstantin Belousov.Nm aio_read2 ,
318269e767SBrooks Davis.Nm aio_readv
328269e767SBrooks Davis.Nd asynchronous read from a file (REALTIME)
338269e767SBrooks Davis.Sh LIBRARY
348269e767SBrooks Davis.Lb libc
358269e767SBrooks Davis.Sh SYNOPSIS
368269e767SBrooks Davis.In aio.h
378269e767SBrooks Davis.Ft int
388269e767SBrooks Davis.Fn aio_read "struct aiocb *iocb"
39a52cb4c4SKonstantin Belousov.Ft int
40a52cb4c4SKonstantin Belousov.Fn aio_read2 "struct aiocb *iocb" "int flags"
418269e767SBrooks Davis.In sys/uio.h
428269e767SBrooks Davis.Ft int
438269e767SBrooks Davis.Fn aio_readv "struct aiocb *iocb"
448269e767SBrooks Davis.Sh DESCRIPTION
458269e767SBrooks DavisThe
46a52cb4c4SKonstantin Belousov.Fn aio_read ,
47a52cb4c4SKonstantin Belousov.Fn aio_read2
488269e767SBrooks Davisand
498269e767SBrooks Davis.Fn aio_readv
508269e767SBrooks Davissystem calls allow the calling process to read
518269e767SBrooks Davisfrom the descriptor
52a52cb4c4SKonstantin Belousov.Fa iocb->aio_fildes .
53a52cb4c4SKonstantin BelousovThe syscalls return immediately after the read request has
54a52cb4c4SKonstantin Belousovbeen enqueued to the descriptor; the read may or may not have
55a52cb4c4SKonstantin Belousovcompleted at the time the call returns.
56a52cb4c4SKonstantin Belousov.Pp
57a52cb4c4SKonstantin BelousovFor the
588269e767SBrooks Davis.Fn aio_read
59a52cb4c4SKonstantin Belousovand
60a52cb4c4SKonstantin Belousov.Fn aio_readv
61a52cb4c4SKonstantin Belousovcalls, the read begins at the offset
62a52cb4c4SKonstantin Belousov.Fa iocb->aio_offset .
63a52cb4c4SKonstantin Belousov.Pp
64a52cb4c4SKonstantin BelousovThe
65a52cb4c4SKonstantin Belousov.Fn aio_read
66a52cb4c4SKonstantin Belousovcall will read
678269e767SBrooks Davis.Fa iocb->aio_nbytes
688269e767SBrooks Davisinto the buffer pointed to by
698269e767SBrooks Davis.Fa iocb->aio_buf ,
708269e767SBrooks Daviswhereas
718269e767SBrooks Davis.Fn aio_readv
728269e767SBrooks Davisreads the data into the
738269e767SBrooks Davis.Fa iocb->aio_iovcnt
748269e767SBrooks Davisbuffers specified by the members of the
758269e767SBrooks Davis.Fa iocb->aio_iov
768269e767SBrooks Davisarray.
778269e767SBrooks DavisFor
788269e767SBrooks Davis.Fn aio_readv
798269e767SBrooks Davisthe
808269e767SBrooks Davis.Fa iovec
818269e767SBrooks Davisstructure is defined in
828269e767SBrooks Davis.Xr readv 2 .
838269e767SBrooks Davis.Pp
848269e767SBrooks DavisThe
85a52cb4c4SKonstantin Belousov.Fn aio_read2
86a52cb4c4SKonstantin Belousovcall takes the
87a52cb4c4SKonstantin Belousov.Fa flags
88a52cb4c4SKonstantin Belousovargument.
89a52cb4c4SKonstantin BelousovIf
90a52cb4c4SKonstantin Belousov.Fa flags
91a52cb4c4SKonstantin Belousovis passed as zero, the call behaves identically to
92a52cb4c4SKonstantin Belousov.Fn aio_read .
93a52cb4c4SKonstantin BelousovThe following flags can be specified by logical or:
94a52cb4c4SKonstantin Belousov.Bl -tag -width AIO_OP2_VECTORED
95a52cb4c4SKonstantin Belousov.It AIO_OP2_FOFFSET
96a52cb4c4SKonstantin BelousovThe read occurs at the file descriptor offset,
97a52cb4c4SKonstantin Belousovwhich is advanced by the operation as done by the
98a52cb4c4SKonstantin Belousov.Xr read 2
99a52cb4c4SKonstantin Belousovsyscall.
100a52cb4c4SKonstantin BelousovThe
101a52cb4c4SKonstantin Belousov.Fa iocb->aio_offset
102a52cb4c4SKonstantin Belousovfield is ignored.
103a52cb4c4SKonstantin Belousov.It AIO_OP2_VECTORED
104a52cb4c4SKonstantin BelousovSimilar to
105a52cb4c4SKonstantin Belousov.Fn aio_readv ,
106a52cb4c4SKonstantin Belousovthe read buffers are specified by the
107a52cb4c4SKonstantin Belousov.Fa aiocb->aio_iov
108a52cb4c4SKonstantin Belousovarray.
109a52cb4c4SKonstantin Belousov.El
110a52cb4c4SKonstantin Belousov.Pp
111a52cb4c4SKonstantin BelousovThe
1128269e767SBrooks Davis.Fa iocb
1138269e767SBrooks Davispointer may be subsequently used as an argument to
1148269e767SBrooks Davis.Fn aio_return
1158269e767SBrooks Davisand
1168269e767SBrooks Davis.Fn aio_error
1178269e767SBrooks Davisin order to determine return or error status for the enqueued operation
1188269e767SBrooks Daviswhile it is in progress.
1198269e767SBrooks Davis.Pp
1208269e767SBrooks DavisIf the request could not be enqueued (generally due to invalid arguments),
1218269e767SBrooks Davisthen the call returns without having enqueued the request.
1228269e767SBrooks Davis.Pp
1238269e767SBrooks DavisIf the request is successfully enqueued, the value of
1248269e767SBrooks Davis.Fa iocb->aio_offset
1258269e767SBrooks Daviscan be modified during the request as context, so this value must
1268269e767SBrooks Davisnot be referenced after the request is enqueued.
1278269e767SBrooks Davis.Pp
1288269e767SBrooks DavisThe
1298269e767SBrooks Davis.Fa iocb->aio_sigevent
1308269e767SBrooks Davisstructure can be used to request notification of the operation's
1318269e767SBrooks Daviscompletion as described in
1328269e767SBrooks Davis.Xr aio 4 .
1338269e767SBrooks Davis.Sh RESTRICTIONS
1348269e767SBrooks DavisThe Asynchronous I/O Control Block structure pointed to by
1358269e767SBrooks Davis.Fa iocb
1368269e767SBrooks Davisand the buffer that the
1378269e767SBrooks Davis.Fa iocb->aio_buf
1388269e767SBrooks Davismember of that structure references must remain valid until the
1398269e767SBrooks Davisoperation has completed.
1408269e767SBrooks Davis.Pp
1418269e767SBrooks DavisThe asynchronous I/O control buffer
1428269e767SBrooks Davis.Fa iocb
143a52cb4c4SKonstantin Belousovshould be zeroed before the system
144a52cb4c4SKonstantin Belousovcalls to avoid passing bogus context information to the kernel.
1458269e767SBrooks Davis.Pp
1468269e767SBrooks DavisModifications of the Asynchronous I/O Control Block structure or the
1478269e767SBrooks Davisbuffer contents are not allowed while the request is queued.
1488269e767SBrooks Davis.Pp
1498269e767SBrooks DavisIf the file offset in
1508269e767SBrooks Davis.Fa iocb->aio_offset
1518269e767SBrooks Davisis past the offset maximum for
1528269e767SBrooks Davis.Fa iocb->aio_fildes ,
1538269e767SBrooks Davisno I/O will occur.
1548269e767SBrooks Davis.Sh RETURN VALUES
155a52cb4c4SKonstantin Belousov.Rv -std aio_read aio_read2 aio_readv
1568269e767SBrooks Davis.Sh DIAGNOSTICS
1578269e767SBrooks DavisNone.
1588269e767SBrooks Davis.Sh ERRORS
1598269e767SBrooks DavisThe
160a52cb4c4SKonstantin Belousov.Fn aio_read ,
161a52cb4c4SKonstantin Belousov.Fn aio_read2 ,
1628269e767SBrooks Davisand
1638269e767SBrooks Davis.Fn aio_readv
1648269e767SBrooks Davissystem calls will fail if:
1658269e767SBrooks Davis.Bl -tag -width Er
1668269e767SBrooks Davis.It Bq Er EAGAIN
1678269e767SBrooks DavisThe request was not queued because of system resource limitations.
1688269e767SBrooks Davis.It Bq Er EFAULT
1698269e767SBrooks DavisPart of
1708269e767SBrooks Davis.Fa aio_iov
1718269e767SBrooks Davispoints outside the process's allocated address space.
1728269e767SBrooks Davis.It Bq Er EINVAL
1738269e767SBrooks DavisThe asynchronous notification method in
1748269e767SBrooks Davis.Fa iocb->aio_sigevent.sigev_notify
1758269e767SBrooks Davisis invalid or not supported.
1768269e767SBrooks Davis.It Bq Er EOPNOTSUPP
1778269e767SBrooks DavisAsynchronous read operations on the file descriptor
1788269e767SBrooks Davis.Fa iocb->aio_fildes
1798269e767SBrooks Davisare unsafe and unsafe asynchronous I/O operations are disabled.
1808269e767SBrooks Davis.El
1818269e767SBrooks Davis.Pp
1828269e767SBrooks DavisThe following conditions may be synchronously detected when the
1838269e767SBrooks Davis.Fn aio_read
1848269e767SBrooks Davisor
1858269e767SBrooks Davis.Fn aio_readv
1868269e767SBrooks Davissystem call is made, or asynchronously, at any time thereafter.
1878269e767SBrooks DavisIf they
1888269e767SBrooks Davisare detected at call time,
189a52cb4c4SKonstantin BelousovThe calls return -1 and set
1908269e767SBrooks Davis.Va errno
1918269e767SBrooks Davisappropriately; otherwise the
1928269e767SBrooks Davis.Fn aio_return
1938269e767SBrooks Davissystem call must be called, and will return -1, and
1948269e767SBrooks Davis.Fn aio_error
1958269e767SBrooks Davismust be called to determine the actual value that would have been
1968269e767SBrooks Davisreturned in
1978269e767SBrooks Davis.Va errno .
1988269e767SBrooks Davis.Bl -tag -width Er
1998269e767SBrooks Davis.It Bq Er EBADF
2008269e767SBrooks DavisThe
2018269e767SBrooks Davis.Fa iocb->aio_fildes
2028269e767SBrooks Davisargument
2038269e767SBrooks Davisis invalid.
2048269e767SBrooks Davis.It Bq Er EINVAL
2058269e767SBrooks DavisThe offset
2068269e767SBrooks Davis.Fa iocb->aio_offset
2078269e767SBrooks Davisis not valid, the priority specified by
2088269e767SBrooks Davis.Fa iocb->aio_reqprio
2098269e767SBrooks Davisis not a valid priority, or the number of bytes specified by
2108269e767SBrooks Davis.Fa iocb->aio_nbytes
2118269e767SBrooks Davisis not valid.
2128269e767SBrooks Davis.It Bq Er EOVERFLOW
2138269e767SBrooks DavisThe file is a regular file,
2148269e767SBrooks Davis.Fa iocb->aio_nbytes
2158269e767SBrooks Davisis greater than zero, the starting offset in
2168269e767SBrooks Davis.Fa iocb->aio_offset
2178269e767SBrooks Davisis before the end of the file, but is at or beyond the
2188269e767SBrooks Davis.Fa iocb->aio_fildes
2198269e767SBrooks Davisoffset maximum.
2208269e767SBrooks Davis.El
2218269e767SBrooks Davis.Pp
2228269e767SBrooks DavisIf the request is successfully enqueued, but subsequently cancelled
2238269e767SBrooks Davisor an error occurs, the value returned by the
2248269e767SBrooks Davis.Fn aio_return
2258269e767SBrooks Davissystem call is per the
2268269e767SBrooks Davis.Xr read 2
2278269e767SBrooks Davissystem call, and the value returned by the
2288269e767SBrooks Davis.Fn aio_error
2298269e767SBrooks Davissystem call is either one of the error returns from the
2308269e767SBrooks Davis.Xr read 2
2318269e767SBrooks Davissystem call, or one of:
2328269e767SBrooks Davis.Bl -tag -width Er
2338269e767SBrooks Davis.It Bq Er EBADF
2348269e767SBrooks DavisThe
2358269e767SBrooks Davis.Fa iocb->aio_fildes
2368269e767SBrooks Davisargument
2378269e767SBrooks Davisis invalid for reading.
2388269e767SBrooks Davis.It Bq Er ECANCELED
2398269e767SBrooks DavisThe request was explicitly cancelled via a call to
2408269e767SBrooks Davis.Fn aio_cancel .
2418269e767SBrooks Davis.It Bq Er EINVAL
2428269e767SBrooks DavisThe offset
2438269e767SBrooks Davis.Fa iocb->aio_offset
2448269e767SBrooks Daviswould be invalid.
2458269e767SBrooks Davis.El
2468269e767SBrooks Davis.Sh SEE ALSO
2478269e767SBrooks Davis.Xr aio_cancel 2 ,
2488269e767SBrooks Davis.Xr aio_error 2 ,
2498269e767SBrooks Davis.Xr aio_return 2 ,
2508269e767SBrooks Davis.Xr aio_suspend 2 ,
2518269e767SBrooks Davis.Xr aio_waitcomplete 2 ,
2528269e767SBrooks Davis.Xr aio_write 2 ,
2538269e767SBrooks Davis.Xr sigevent 3 ,
2548269e767SBrooks Davis.Xr siginfo 3 ,
2558269e767SBrooks Davis.Xr aio 4
2568269e767SBrooks Davis.Sh STANDARDS
2578269e767SBrooks DavisThe
2588269e767SBrooks Davis.Fn aio_read
2598269e767SBrooks Davissystem call is expected to conform to the
2608269e767SBrooks Davis.St -p1003.1
2618269e767SBrooks Davisstandard.
2628269e767SBrooks DavisThe
263a52cb4c4SKonstantin Belousov.Fn aio_read2
264a52cb4c4SKonstantin Belousovand
2658269e767SBrooks Davis.Fn aio_readv
266d97e4478SEnji Coopersystem calls are
267d97e4478SEnji Cooper.Fx
268d97e4478SEnji Cooperextensions,
269a52cb4c4SKonstantin Belousovand should not be used in portable code.
2708269e767SBrooks Davis.Sh HISTORY
2718269e767SBrooks DavisThe
2728269e767SBrooks Davis.Fn aio_read
2738269e767SBrooks Davissystem call first appeared in
2748269e767SBrooks Davis.Fx 3.0 .
2758269e767SBrooks DavisThe
2768269e767SBrooks Davis.Fn aio_readv
2778269e767SBrooks Davissystem call first appeared in
2788269e767SBrooks Davis.Fx 13.0 .
279a52cb4c4SKonstantin BelousovThe
280a52cb4c4SKonstantin Belousov.Fn aio_read2
281a52cb4c4SKonstantin Belousovsystem call first appeared in
282a52cb4c4SKonstantin Belousov.Fx 14.1 .
2838269e767SBrooks Davis.Sh AUTHORS
2848269e767SBrooks DavisThis
2858269e767SBrooks Davismanual page was written by
2868269e767SBrooks Davis.An Terry Lambert Aq Mt terry@whistle.com .
2878269e767SBrooks Davis.Sh BUGS
2888269e767SBrooks DavisInvalid information in
2898269e767SBrooks Davis.Fa iocb->_aiocb_private
2908269e767SBrooks Davismay confuse the kernel.
291