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