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