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