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: src/lib/libc/sys/aio_read.2,v 1.19 2003/01/14 02:37:06 tjr Exp $ 26.\" 27.Dd November 17, 1998 28.Dt AIO_READ 2 29.Os 30.Sh NAME 31.Nm aio_read 32.Nd asynchronous read from a file (REALTIME) 33.Sh LIBRARY 34.Lb libc 35.Sh SYNOPSIS 36.In aio.h 37.Ft int 38.Fo aio_read 39.Fa "struct aiocb *aiocbp" 40.Fc 41.Sh DESCRIPTION 42The 43.Fn aio_read 44system call allows the calling process to read 45.Fa aiocbp->aio_nbytes 46from the descriptor 47.Fa aiocbp->aio_fildes , 48beginning at the offset 49.Fa aiocbp->aio_offset , 50into the buffer pointed to by 51.Fa aiocbp->aio_buf . 52The call returns immediately after the read request has 53been enqueued to the descriptor; 54the read may or may not have completed at the time the call returns. 55.Pp 56If _POSIX_PRIORITIZED_IO is defined, and the descriptor supports it, 57then the enqueued operation is submitted at a priority equal to that 58of the calling process minus 59.Fa aiocbp->aio_reqprio . 60.Pp 61The 62.Fa aiocbp->aio_lio_opcode 63argument 64is ignored by the 65.Fn aio_read 66system call. 67.Pp 68The 69.Fa aiocbp 70pointer may be subsequently used as an argument to 71.Fn aio_return 72and 73.Fn aio_error 74in order to determine return or error status for the enqueued operation 75while it is in progress. 76.Pp 77If the request could not be enqueued (generally due to invalid arguments), 78then the call returns without having enqueued the request. 79.Pp 80If the request is successfully enqueued, the value of 81.Fa aiocbp->aio_offset 82can be modified during the request as context, so this value must 83not be referenced after the request is enqueued. 84.Sh RESTRICTIONS 85The Asynchronous I/O Control Block structure pointed to by 86.Fa aiocbp 87and the buffer that the 88.Fa aiocbp->aio_buf 89member of that structure references must remain valid until the 90operation has completed. For this reason, use of auto (stack) variables 91for these objects is discouraged. 92.Pp 93The asynchronous I/O control buffer 94.Fa aiocbp 95should be zeroed before the 96.Fn aio_read 97call to avoid passing bogus context information to the kernel. 98.Pp 99Modifications of the Asynchronous I/O Control Block structure or the 100buffer contents after the request has been enqueued, but before the 101request has completed, are not allowed. 102.Pp 103If the file offset in 104.Fa aiocbp->aio_offset 105is past the offset maximum for 106.Fa aiocbp->aio_fildes , 107no I/O will occur. 108.Sh RETURN VALUES 109.Rv -std aio_read 110.Sh DIAGNOSTICS 111None. 112.Sh ERRORS 113The 114.Fn aio_read 115system call will fail if: 116.Bl -tag -width Er 117.\" ========== 118.It Bq Er EAGAIN 119Because of system resource limitations, 120the request was not queued. 121.\" ========== 122.It Bq Er ENOSYS 123The 124.Fn aio_read 125system call is not supported. 126.El 127.Pp 128The following conditions may be synchronously detected when the 129.Fn aio_read 130system call is made, or asynchronously, at any time thereafter. 131If they are detected at call time, 132.Fn aio_read 133returns -1 and sets 134.Va errno 135appropriately. 136Otherwise, the 137.Fn aio_return 138system call must be called. 139It will return -1; 140.Fn aio_error 141must then be called to determine the actual value 142that would have been returned in 143.Va errno . 144.Pp 145.Bl -tag -width Er 146.\" ========== 147.It Bq Er EBADF 148The 149.Fa aiocbp->aio_fildes 150argument 151is invalid. 152.\" ========== 153.It Bq Er EINVAL 154The offset 155.Fa aiocbp->aio_offset 156is not valid, the priority specified by 157.Fa aiocbp->aio_reqprio 158is not a valid priority, or the number of bytes specified by 159.Fa aiocbp->aio_nbytes 160is not valid. 161.\" ========== 162.It Bq Er EOVERFLOW 163The file is a regular file, 164.Fa aiocbp->aio_nbytes 165is greater than zero, the starting offset in 166.Fa aiocbp->aio_offset 167is before the end of the file, but is at or beyond the 168.Fa aiocbp->aio_fildes 169offset maximum. 170.El 171.Pp 172If the request is successfully enqueued, but subsequently cancelled 173or an error occurs, the value returned by the 174.Fn aio_return 175system call is per the 176.Xr read 2 177system call, and the value returned by the 178.Fn aio_error 179system call is either one of the error returns from the 180.Xr read 2 181system call, or one of: 182.Bl -tag -width Er 183.\" ========== 184.It Bq Er EBADF 185The 186.Fa aiocbp->aio_fildes 187argument 188is invalid for reading. 189.\" ========== 190.It Bq Er ECANCELED 191The request was explicitly cancelled via a call to 192.Fn aio_cancel . 193.\" ========== 194.It Bq Er EINVAL 195The offset 196.Fa aiocbp->aio_offset 197would be invalid. 198.El 199.Sh SEE ALSO 200.Xr aio_cancel 2 , 201.Xr aio_error 2 , 202.Xr aio_return 2 , 203.Xr aio_suspend 2 , 204.Xr aio_write 2 , 205.Xr aio 4 206.Sh STANDARDS 207The 208.Fn aio_read 209system call is expected to conform to the 210.St -p1003.1 211standard. 212.Sh HISTORY 213The 214.Fn aio_read 215system call first appeared in 216.Fx 3.0 . 217.Sh AUTHORS 218This 219manual page was written by 220.An Terry Lambert Aq [email protected] . 221.Sh BUGS 222Invalid information in 223.Fa aiocbp->_aiocb_private 224may confuse the kernel. 225