xref: /netbsd-src/lib/librt/aio_read.3 (revision c2f76ff004a2cb67efe5b12d97bd3ef7fe89e18d)
1.\" $NetBSD: aio_read.3,v 1.4 2010/05/17 19:22:31 jruoho Exp $
2.\"
3.\" Copyright (c) 1998 Terry Lambert
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25.\" SUCH DAMAGE.
26.\"
27.\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/sys/aio_read.2,v 1.23 2005/12/13 13:43:35 davidxu Exp $
28.\"
29.Dd May 17, 2010
30.Dt AIO_READ 3
31.Os
32.Sh NAME
33.Nm aio_read
34.Nd asynchronous read from a file (REALTIME)
35.Sh LIBRARY
36.Lb librt
37.Sh SYNOPSIS
38.In aio.h
39.Ft int
40.Fn aio_read "struct aiocb *aiocbp"
41.Sh DESCRIPTION
42The
43.Fn aio_read
44system call allows the calling process to read
45.Fa aiocbp-\*[Gt]aio_nbytes
46from the descriptor
47.Fa aiocbp-\*[Gt]aio_fildes
48beginning at the offset
49.Fa aiocbp-\*[Gt]aio_offset
50into the buffer pointed to by
51.Fa aiocbp-\*[Gt]aio_buf .
52The call returns immediately after the read request has
53been enqueued to the descriptor; the read may or may not have
54completed at the time the call returns.
55.Pp
56If
57.Dv _POSIX_PRIORITIZED_IO
58is defined, and the descriptor supports it,
59then the enqueued operation is submitted at a priority equal to that
60of the calling process minus
61.Fa aiocbp-\*[Gt]aio_reqprio .
62.Pp
63The
64.Fa aiocbp-\*[Gt]aio_lio_opcode
65argument
66is ignored by the
67.Fn aio_read
68system call.
69.Pp
70The
71.Fa aiocbp
72pointer may be subsequently used as an argument to
73.Fn aio_return
74and
75.Fn aio_error
76in order to determine return or error status for the enqueued operation
77while it is in progress.
78.Pp
79If the request could not be enqueued (generally due to invalid arguments),
80then the call returns without having enqueued the request.
81.Pp
82If the request is successfully enqueued, the value of
83.Fa aiocbp-\*[Gt]aio_offset
84can be modified during the request as context, so this value must
85not be referenced after the request is enqueued.
86.Sh RESTRICTIONS
87The Asynchronous I/O Control Block structure pointed to by
88.Fa aiocbp
89and the buffer that the
90.Fa aiocbp-\*[Gt]aio_buf
91member of that structure references must remain valid until the
92operation has completed.
93For this reason, use of auto (stack) variables
94for these objects is discouraged.
95.Pp
96The asynchronous I/O control buffer
97.Fa aiocbp
98should be zeroed before the
99.Fn aio_read
100call to avoid passing bogus context information to the kernel.
101.Pp
102Modifications of the Asynchronous I/O Control Block structure or the
103buffer contents after the request has been enqueued, but before the
104request has completed, are not allowed.
105.Pp
106If the file offset in
107.Fa aiocbp-\*[Gt]aio_offset
108is past the offset maximum for
109.Fa aiocbp-\*[Gt]aio_fildes ,
110no I/O will occur.
111.Sh RETURN VALUES
112.Rv -std aio_read
113.Sh DIAGNOSTICS
114None.
115.Sh ERRORS
116The
117.Fn aio_read
118system call will fail if:
119.Bl -tag -width Er
120.It Bq Er EAGAIN
121The request was not queued because of system resource limitations.
122.El
123.Pp
124The following conditions may be synchronously detected when the
125.Fn aio_read
126system call is made, or asynchronously, at any time thereafter.
127If they
128are detected at call time,
129.Fn aio_read
130returns \-1 and sets
131.Va errno
132appropriately; otherwise the
133.Fn aio_return
134system call must be called, and will return \-1, and
135.Fn aio_error
136must be called to determine the actual value that would have been
137returned in
138.Va errno .
139.Pp
140.Bl -tag -width Er
141.It Bq Er EBADF
142The
143.Fa aiocbp-\*[Gt]aio_fildes
144argument
145is invalid.
146.It Bq Er EINVAL
147The offset
148.Fa aiocbp-\*[Gt]aio_offset
149is not valid, the priority specified by
150.Fa aiocbp-\*[Gt]aio_reqprio
151is not a valid priority, or the number of bytes specified by
152.Fa aiocbp-\*[Gt]aio_nbytes
153is not valid.
154.It Bq Er EOVERFLOW
155The file is a regular file,
156.Fa aiocbp-\*[Gt]aio_nbytes
157is greater than zero, the starting offset in
158.Fa aiocbp-\*[Gt]aio_offset
159is before the end of the file, but is at or beyond the
160.Fa aiocbp-\*[Gt]aio_fildes
161offset maximum.
162.El
163.Pp
164If the request is successfully enqueued, but subsequently cancelled
165or an error occurs, the value returned by the
166.Fn aio_return
167system call is per the
168.Xr read 2
169system call, and the value returned by the
170.Fn aio_error
171system call is either one of the error returns from the
172.Xr read 2
173system call, or one of:
174.Bl -tag -width Er
175.It Bq Er EBADF
176The
177.Fa aiocbp-\*[Gt]aio_fildes
178argument
179is invalid for reading.
180.It Bq Er ECANCELED
181The request was explicitly cancelled via a call to
182.Fn aio_cancel .
183.It Bq Er EINVAL
184The offset
185.Fa aiocbp-\*[Gt]aio_offset
186would be invalid.
187.El
188.Sh SEE ALSO
189.Xr siginfo 2 ,
190.Xr aio 3
191.Sh STANDARDS
192The
193.Fn aio_read
194system call is expected to conform to the
195.St -p1003.1-2001
196standard.
197.Sh HISTORY
198The
199.Fn aio_read
200system call first appeared in
201.Nx 5.0 .
202