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