1 /* Copyright (C) 1996-2022 Free Software Foundation, Inc. 2 This file is part of the GNU C Library. 3 4 The GNU C Library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 The GNU C Library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with the GNU C Library; if not, see 16 <https://www.gnu.org/licenses/>. */ 17 18 /* 19 * ISO/IEC 9945-1:1996 6.7: Asynchronous Input and Output 20 */ 21 22 #ifndef _AIO_H 23 #define _AIO_H 1 24 25 #include <features.h> 26 #include <sys/types.h> 27 #include <bits/types/sigevent_t.h> 28 #include <bits/sigevent-consts.h> 29 #include <bits/types/struct_timespec.h> 30 31 __BEGIN_DECLS 32 33 /* Asynchronous I/O control block. */ 34 struct aiocb 35 { 36 int aio_fildes; /* File descriptor. */ 37 int aio_lio_opcode; /* Operation to be performed. */ 38 int aio_reqprio; /* Request priority offset. */ 39 volatile void *aio_buf; /* Location of buffer. */ 40 size_t aio_nbytes; /* Length of transfer. */ 41 struct sigevent aio_sigevent; /* Signal number and value. */ 42 43 /* Internal members. */ 44 struct aiocb *__next_prio; 45 int __abs_prio; 46 int __policy; 47 int __error_code; 48 __ssize_t __return_value; 49 50 #ifndef __USE_FILE_OFFSET64 51 __off_t aio_offset; /* File offset. */ 52 char __pad[sizeof (__off64_t) - sizeof (__off_t)]; 53 #else 54 __off64_t aio_offset; /* File offset. */ 55 #endif 56 char __glibc_reserved[32]; 57 }; 58 59 /* The same for the 64bit offsets. Please note that the members aio_fildes 60 to __return_value have to be the same in aiocb and aiocb64. */ 61 #ifdef __USE_LARGEFILE64 62 struct aiocb64 63 { 64 int aio_fildes; /* File descriptor. */ 65 int aio_lio_opcode; /* Operation to be performed. */ 66 int aio_reqprio; /* Request priority offset. */ 67 volatile void *aio_buf; /* Location of buffer. */ 68 size_t aio_nbytes; /* Length of transfer. */ 69 struct sigevent aio_sigevent; /* Signal number and value. */ 70 71 /* Internal members. */ 72 struct aiocb *__next_prio; 73 int __abs_prio; 74 int __policy; 75 int __error_code; 76 __ssize_t __return_value; 77 78 __off64_t aio_offset; /* File offset. */ 79 char __glibc_reserved[32]; 80 }; 81 #endif 82 83 84 #ifdef __USE_GNU 85 /* To optimize the implementation one can use the following struct. */ 86 struct aioinit 87 { 88 int aio_threads; /* Maximum number of threads. */ 89 int aio_num; /* Number of expected simultaneous requests. */ 90 int aio_locks; /* Not used. */ 91 int aio_usedba; /* Not used. */ 92 int aio_debug; /* Not used. */ 93 int aio_numusers; /* Not used. */ 94 int aio_idle_time; /* Number of seconds before idle thread 95 terminates. */ 96 int aio_reserved; 97 }; 98 #endif 99 100 101 /* Return values of the aio_cancel function. */ 102 enum 103 { 104 AIO_CANCELED, 105 #define AIO_CANCELED AIO_CANCELED 106 AIO_NOTCANCELED, 107 #define AIO_NOTCANCELED AIO_NOTCANCELED 108 AIO_ALLDONE 109 #define AIO_ALLDONE AIO_ALLDONE 110 }; 111 112 113 /* Operation codes for `aio_lio_opcode'. */ 114 enum 115 { 116 LIO_READ, 117 #define LIO_READ LIO_READ 118 LIO_WRITE, 119 #define LIO_WRITE LIO_WRITE 120 LIO_NOP 121 #define LIO_NOP LIO_NOP 122 }; 123 124 125 /* Synchronization options for `lio_listio' function. */ 126 enum 127 { 128 LIO_WAIT, 129 #define LIO_WAIT LIO_WAIT 130 LIO_NOWAIT 131 #define LIO_NOWAIT LIO_NOWAIT 132 }; 133 134 135 /* Allow user to specify optimization. */ 136 #ifdef __USE_GNU 137 extern void aio_init (const struct aioinit *__init) __THROW __nonnull ((1)); 138 #endif 139 140 141 #ifndef __USE_FILE_OFFSET64 142 /* Enqueue read request for given number of bytes and the given priority. */ 143 extern int aio_read (struct aiocb *__aiocbp) __THROW __nonnull ((1)); 144 /* Enqueue write request for given number of bytes and the given priority. */ 145 extern int aio_write (struct aiocb *__aiocbp) __THROW __nonnull ((1)); 146 147 /* Initiate list of I/O requests. */ 148 extern int lio_listio (int __mode, 149 struct aiocb *const __list[__restrict_arr], 150 int __nent, struct sigevent *__restrict __sig) 151 __THROW __nonnull ((2)); 152 153 /* Retrieve error status associated with AIOCBP. */ 154 extern int aio_error (const struct aiocb *__aiocbp) __THROW __nonnull ((1)); 155 /* Return status associated with AIOCBP. */ 156 extern __ssize_t aio_return (struct aiocb *__aiocbp) __THROW __nonnull ((1)); 157 158 /* Try to cancel asynchronous I/O requests outstanding against file 159 descriptor FILDES. */ 160 extern int aio_cancel (int __fildes, struct aiocb *__aiocbp) __THROW; 161 162 /* Suspend calling thread until at least one of the asynchronous I/O 163 operations referenced by LIST has completed. 164 165 This function is a cancellation point and therefore not marked with 166 __THROW. */ 167 extern int aio_suspend (const struct aiocb *const __list[], int __nent, 168 const struct timespec *__restrict __timeout) 169 __nonnull ((1)); 170 171 /* Force all operations associated with file desriptor described by 172 `aio_fildes' member of AIOCBP. */ 173 extern int aio_fsync (int __operation, struct aiocb *__aiocbp) 174 __THROW __nonnull ((2)); 175 #else 176 # ifdef __REDIRECT_NTH 177 extern int __REDIRECT_NTH (aio_read, (struct aiocb *__aiocbp), aio_read64) 178 __nonnull ((1)); 179 extern int __REDIRECT_NTH (aio_write, (struct aiocb *__aiocbp), aio_write64) 180 __nonnull ((1)); 181 182 extern int __REDIRECT_NTH (lio_listio, 183 (int __mode, 184 struct aiocb *const __list[__restrict_arr], 185 int __nent, struct sigevent *__restrict __sig), 186 lio_listio64) __nonnull ((2)); 187 188 extern int __REDIRECT_NTH (aio_error, (const struct aiocb *__aiocbp), 189 aio_error64) __nonnull ((1)); 190 extern __ssize_t __REDIRECT_NTH (aio_return, (struct aiocb *__aiocbp), 191 aio_return64) __nonnull ((1)); 192 193 extern int __REDIRECT_NTH (aio_cancel, 194 (int __fildes, struct aiocb *__aiocbp), 195 aio_cancel64); 196 # ifdef __USE_TIME_BITS64 197 extern int __REDIRECT_NTH (aio_suspend, 198 (const struct aiocb *const __list[], int __nent, 199 const struct timespec *__restrict __timeout), 200 __aio_suspend_time64) __nonnull ((1)); 201 # else 202 extern int __REDIRECT_NTH (aio_suspend, 203 (const struct aiocb *const __list[], int __nent, 204 const struct timespec *__restrict __timeout), 205 aio_suspend64) __nonnull ((1)); 206 # endif 207 extern int __REDIRECT_NTH (aio_fsync, 208 (int __operation, struct aiocb *__aiocbp), 209 aio_fsync64) __nonnull ((2)); 210 211 # else 212 # define aio_read aio_read64 213 # define aio_write aio_write64 214 # define lio_listio lio_listio64 215 # define aio_error aio_error64 216 # define aio_return aio_return64 217 # define aio_cancel aio_cancel64 218 # ifdef __USE_TIME_BITS64 219 # define aio_suspend __aio_suspend_time64 220 # else 221 # define aio_suspend aio_suspend64 222 # endif 223 # define aio_fsync aio_fsync64 224 # endif 225 #endif 226 227 #ifdef __USE_LARGEFILE64 228 extern int aio_read64 (struct aiocb64 *__aiocbp) __THROW __nonnull ((1)); 229 extern int aio_write64 (struct aiocb64 *__aiocbp) __THROW __nonnull ((1)); 230 231 extern int lio_listio64 (int __mode, 232 struct aiocb64 *const __list[__restrict_arr], 233 int __nent, struct sigevent *__restrict __sig) 234 __THROW __nonnull ((2)); 235 236 extern int aio_error64 (const struct aiocb64 *__aiocbp) 237 __THROW __nonnull ((1)); 238 extern __ssize_t aio_return64 (struct aiocb64 *__aiocbp) 239 __THROW __nonnull ((1)); 240 241 extern int aio_cancel64 (int __fildes, struct aiocb64 *__aiocbp) __THROW; 242 243 extern int aio_suspend64 (const struct aiocb64 *const __list[], int __nent, 244 const struct timespec *__restrict __timeout) 245 __THROW __nonnull ((1)); 246 247 extern int aio_fsync64 (int __operation, struct aiocb64 *__aiocbp) 248 __THROW __nonnull ((2)); 249 #endif 250 251 __END_DECLS 252 253 #endif /* aio.h */ 254