aio.h 7.6 KB

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