]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/aio.h
xnu-792.21.3.tar.gz
[apple/xnu.git] / bsd / sys / aio.h
CommitLineData
55e303ae 1/*
91447636 2 * Copyright (c) 2003-2005 Apple Computer, Inc. All rights reserved.
55e303ae 3 *
8f6c56a5 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55e303ae 5 *
8f6c56a5
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
8ad349bb 24 * limitations under the License.
8f6c56a5
A
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
55e303ae
A
27 */
28/*
29 * File: sys/aio.h
30 * Author: Umesh Vaishampayan [umeshv@apple.com]
31 * 05-Feb-2003 umeshv Created.
32 *
33 * Header file for POSIX Asynchronous IO APIs
34 *
35 */
36
37#ifndef _SYS_AIO_H_
38#define _SYS_AIO_H_
39
40#include <sys/signal.h>
91447636 41#include <sys/cdefs.h>
55e303ae
A
42
43struct aiocb {
44 int aio_fildes; /* File descriptor */
45 off_t aio_offset; /* File offset */
46 volatile void *aio_buf; /* Location of buffer */
47 size_t aio_nbytes; /* Length of transfer */
48 int aio_reqprio; /* Request priority offset */
49 struct sigevent aio_sigevent; /* Signal number and value */
50 int aio_lio_opcode; /* Operation to be performed */
51};
52
91447636
A
53// LP64todo - should this move?
54#ifdef KERNEL
55
21362eb3
A
56#if __DARWIN_ALIGN_NATURAL
57#pragma options align=natural
58#endif
59
91447636
A
60struct user_aiocb {
61 int aio_fildes; /* File descriptor */
62 off_t aio_offset; /* File offset */
21362eb3 63 user_addr_t aio_buf; /* Location of buffer */
91447636
A
64 user_size_t aio_nbytes; /* Length of transfer */
65 int aio_reqprio; /* Request priority offset */
21362eb3 66 struct user_sigevent aio_sigevent; /* Signal number and value */
91447636
A
67 int aio_lio_opcode; /* Operation to be performed */
68};
69
21362eb3
A
70#if __DARWIN_ALIGN_NATURAL
71#pragma options align=reset
72#endif
73
91447636
A
74#endif // KERNEL
75
55e303ae
A
76/*
77 * aio_cancel() return values
78 */
79
80/*
81 * none of the requested operations could be canceled since they are
82 * already complete.
83 */
84#define AIO_ALLDONE 0x1
85
86/* all requested operations have been canceled */
87#define AIO_CANCELED 0x2
88
89/*
90 * some of the requested operations could not be canceled since
91 * they are in progress
92 */
93#define AIO_NOTCANCELED 0x4
94
95
96/*
97 * lio_listio operation options
98 */
99
100#define LIO_NOP 0x0 /* option indicating that no transfer is requested */
101#define LIO_READ 0x1 /* option requesting a read */
102#define LIO_WRITE 0x2 /* option requesting a write */
103
104/*
105 * lio_listio() modes
106 */
107
108/*
109 * A lio_listio() synchronization operation indicating
110 * that the calling thread is to continue execution while
111 * the lio_listio() operation is being performed, and no
112 * notification is given when the operation is complete
113 */
114#define LIO_NOWAIT 0x1
115
116/*
117 * A lio_listio() synchronization operation indicating
118 * that the calling thread is to suspend until the
119 * lio_listio() operation is complete.
120 */
121#define LIO_WAIT 0x2
122
123/*
124 * Maximum number of operations in single lio_listio call
125 */
126#define AIO_LISTIO_MAX 16
127
128/*
129 * A aio_fsync() options
130 * that the calling thread is to continue execution while
131 * the lio_listio() operation is being performed, and no
132 * notification is given when the operation is complete
133 */
134
91447636
A
135#ifndef O_SYNC /* XXX investigate documentation error */
136#define O_SYNC 0x0080 /* queued IO is completed as if by fsync() */
137#endif
55e303ae
A
138#if 0 /* O_DSYNC - NOT SUPPORTED */
139#define O_DSYNC 0x1 /* queued async IO is completed as if by fdatasync() */
140#endif
141
142#ifndef KERNEL
143/*
144 * Prototypes
145 */
146
91447636
A
147__BEGIN_DECLS
148
55e303ae
A
149/*
150 * Attempt to cancel one or more asynchronous I/O requests currently outstanding
151 * against file descriptor fd. The aiocbp argument points to the asynchronous I/O
152 * control block for a particular request to be canceled. If aiocbp is NULL, then
153 * all outstanding cancelable asynchronous I/O requests against fd shall be canceled.
154 */
155int aio_cancel( int fd,
156 struct aiocb * aiocbp );
157
158/*
159 * Return the error status associated with the aiocb structure referenced by the
160 * aiocbp argument. The error status for an asynchronous I/O operation is the errno
161 * value that would be set by the corresponding read(), write(), or fsync()
162 * operation. If the operation has not yet completed, then the error status shall
163 * be equal to [EINPROGRESS].
164 */
165int aio_error( const struct aiocb * aiocbp );
166
167/*
168 * Asynchronously force all I/O operations associated with the file indicated by
169 * the file descriptor aio_fildes member of the aiocb structure referenced by the
170 * aiocbp argument and queued at the time of the call to aio_fsync() to the
171 * synchronized I/O completion state. The function call shall return when the
172 * synchronization request has been initiated or queued. op O_SYNC is the only
173 * supported opertation at this time.
174 * The aiocbp argument refers to an asynchronous I/O control block. The aiocbp
175 * value may be used as an argument to aio_error() and aio_return() in order to
176 * determine the error status and return status, respectively, of the asynchronous
177 * operation while it is proceeding. When the request is queued, the error status
178 * for the operation is [EINPROGRESS]. When all data has been successfully
179 * transferred, the error status shall be reset to reflect the success or failure
180 * of the operation.
181 */
182int aio_fsync( int op,
183 struct aiocb * aiocbp );
184
185/*
186 * Read aiocbp->aio_nbytes from the file associated with aiocbp->aio_fildes into
187 * the buffer pointed to by aiocbp->aio_buf. The function call shall return when
188 * the read request has been initiated or queued.
189 * The aiocbp value may be used as an argument to aio_error() and aio_return() in
190 * order to determine the error status and return status, respectively, of the
191 * asynchronous operation while it is proceeding. If an error condition is
192 * encountered during queuing, the function call shall return without having
193 * initiated or queued the request. The requested operation takes place at the
194 * absolute position in the file as given by aio_offset, as if lseek() were called
195 * immediately prior to the operation with an offset equal to aio_offset and a
196 * whence equal to SEEK_SET. After a successful call to enqueue an asynchronous
197 * I/O operation, the value of the file offset for the file is unspecified.
198 */
199int aio_read( struct aiocb * aiocbp );
200
201/*
202 * Return the return status associated with the aiocb structure referenced by
203 * the aiocbp argument. The return status for an asynchronous I/O operation is
204 * the value that would be returned by the corresponding read(), write(), or
205 * fsync() function call. If the error status for the operation is equal to
206 * [EINPROGRESS], then the return status for the operation is undefined. The
207 * aio_return() function may be called exactly once to retrieve the return status
208 * of a given asynchronous operation; thereafter, if the same aiocb structure
209 * is used in a call to aio_return() or aio_error(), an error may be returned.
210 * When the aiocb structure referred to by aiocbp is used to submit another
211 * asynchronous operation, then aio_return() may be successfully used to
212 * retrieve the return status of that operation.
213 */
214ssize_t aio_return( struct aiocb * aiocbp );
215
216/*
217 * Suspend the calling thread until at least one of the asynchronous I/O
218 * operations referenced by the aiocblist argument has completed, until a signal
219 * interrupts the function, or, if timeout is not NULL, until the time
220 * interval specified by timeout has passed. If any of the aiocb structures
221 * in the aiocblist correspond to completed asynchronous I/O operations (that is,
222 * the error status for the operation is not equal to [EINPROGRESS]) at the
223 * time of the call, the function shall return without suspending the calling
224 * thread. The aiocblist argument is an array of pointers to asynchronous I/O
225 * control blocks. The nent argument indicates the number of elements in the
226 * array. Each aiocb structure pointed to has been used in initiating an
227 * asynchronous I/O request via aio_read(), aio_write(), or lio_listio(). This
228 * array may contain NULL pointers, which are ignored.
229 */
230int aio_suspend( const struct aiocb *const aiocblist[],
231 int nent,
232 const struct timespec * timeoutp );
233
234/*
235 * Write aiocbp->aio_nbytes to the file associated with aiocbp->aio_fildes from
236 * the buffer pointed to by aiocbp->aio_buf. The function shall return when the
237 * write request has been initiated or, at a minimum, queued.
238 * The aiocbp argument may be used as an argument to aio_error() and aio_return()
239 * in order to determine the error status and return status, respectively, of the
240 * asynchronous operation while it is proceeding.
241 */
242int aio_write( struct aiocb * aiocbp );
243
244/*
245 * Initiate a list of I/O requests with a single function call. The mode
246 * argument takes one of the values LIO_WAIT or LIO_NOWAIT and determines whether
247 * the function returns when the I/O operations have been completed, or as soon
248 * as the operations have been queued. If the mode argument is LIO_WAIT, the
249 * function shall wait until all I/O is complete and the sig argument shall be
250 * ignored.
251 * If the mode argument is LIO_NOWAIT, the function shall return immediately, and
252 * asynchronous notification shall occur, according to the sig argument, when all
253 * the I/O operations complete. If sig is NULL, then no asynchronous notification
254 * shall occur.
255 */
256int lio_listio( int mode,
257 struct aiocb *const aiocblist[],
258 int nent,
259 struct sigevent *sigp );
91447636
A
260__END_DECLS
261
55e303ae
A
262#endif /* KERNEL */
263#endif /* _SYS_AIO_H_ */