aio.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /* Copyright (C) 1996-2020 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 desriptor. */
  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 desriptor. */
  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 customize the implementation one can use the following struct.
  71. This implementation follows the one in Irix. */
  72. struct aioinit
  73. {
  74. int aio_threads; /* Maximal number of threads. */
  75. int aio_num; /* Number of expected simultanious requests. */
  76. int aio_locks; /* Not used. */
  77. int aio_usedba; /* Not used. */
  78. int aio_debug; /* Not used. */
  79. int aio_numusers; /* Not used. */
  80. int aio_idle_time; /* Number of seconds before idle thread
  81. terminates. */
  82. int aio_reserved;
  83. };
  84. #endif
  85. /* Return values of cancelation function. */
  86. enum
  87. {
  88. AIO_CANCELED,
  89. #define AIO_CANCELED AIO_CANCELED
  90. AIO_NOTCANCELED,
  91. #define AIO_NOTCANCELED AIO_NOTCANCELED
  92. AIO_ALLDONE
  93. #define AIO_ALLDONE AIO_ALLDONE
  94. };
  95. /* Operation codes for `aio_lio_opcode'. */
  96. enum
  97. {
  98. LIO_READ,
  99. #define LIO_READ LIO_READ
  100. LIO_WRITE,
  101. #define LIO_WRITE LIO_WRITE
  102. LIO_NOP
  103. #define LIO_NOP LIO_NOP
  104. };
  105. /* Synchronization options for `lio_listio' function. */
  106. enum
  107. {
  108. LIO_WAIT,
  109. #define LIO_WAIT LIO_WAIT
  110. LIO_NOWAIT
  111. #define LIO_NOWAIT LIO_NOWAIT
  112. };
  113. /* Allow user to specify optimization. */
  114. #ifdef __USE_GNU
  115. extern void aio_init (const struct aioinit *__init) __THROW __nonnull ((1));
  116. #endif
  117. #ifndef __USE_FILE_OFFSET64
  118. /* Enqueue read request for given number of bytes and the given priority. */
  119. extern int aio_read (struct aiocb *__aiocbp) __THROW __nonnull ((1));
  120. /* Enqueue write request for given number of bytes and the given priority. */
  121. extern int aio_write (struct aiocb *__aiocbp) __THROW __nonnull ((1));
  122. /* Initiate list of I/O requests. */
  123. extern int lio_listio (int __mode,
  124. struct aiocb *const __list[__restrict_arr],
  125. int __nent, struct sigevent *__restrict __sig)
  126. __THROW __nonnull ((2));
  127. /* Retrieve error status associated with AIOCBP. */
  128. extern int aio_error (const struct aiocb *__aiocbp) __THROW __nonnull ((1));
  129. /* Return status associated with AIOCBP. */
  130. extern __ssize_t aio_return (struct aiocb *__aiocbp) __THROW __nonnull ((1));
  131. /* Try to cancel asynchronous I/O requests outstanding against file
  132. descriptor FILDES. */
  133. extern int aio_cancel (int __fildes, struct aiocb *__aiocbp) __THROW;
  134. /* Suspend calling thread until at least one of the asynchronous I/O
  135. operations referenced by LIST has completed.
  136. This function is a cancellation point and therefore not marked with
  137. __THROW. */
  138. extern int aio_suspend (const struct aiocb *const __list[], int __nent,
  139. const struct timespec *__restrict __timeout)
  140. __nonnull ((1));
  141. /* Force all operations associated with file desriptor described by
  142. `aio_fildes' member of AIOCBP. */
  143. extern int aio_fsync (int __operation, struct aiocb *__aiocbp)
  144. __THROW __nonnull ((2));
  145. #else
  146. # ifdef __REDIRECT_NTH
  147. extern int __REDIRECT_NTH (aio_read, (struct aiocb *__aiocbp), aio_read64)
  148. __nonnull ((1));
  149. extern int __REDIRECT_NTH (aio_write, (struct aiocb *__aiocbp), aio_write64)
  150. __nonnull ((1));
  151. extern int __REDIRECT_NTH (lio_listio,
  152. (int __mode,
  153. struct aiocb *const __list[__restrict_arr],
  154. int __nent, struct sigevent *__restrict __sig),
  155. lio_listio64) __nonnull ((2));
  156. extern int __REDIRECT_NTH (aio_error, (const struct aiocb *__aiocbp),
  157. aio_error64) __nonnull ((1));
  158. extern __ssize_t __REDIRECT_NTH (aio_return, (struct aiocb *__aiocbp),
  159. aio_return64) __nonnull ((1));
  160. extern int __REDIRECT_NTH (aio_cancel,
  161. (int __fildes, struct aiocb *__aiocbp),
  162. aio_cancel64);
  163. extern int __REDIRECT_NTH (aio_suspend,
  164. (const struct aiocb *const __list[], int __nent,
  165. const struct timespec *__restrict __timeout),
  166. aio_suspend64) __nonnull ((1));
  167. extern int __REDIRECT_NTH (aio_fsync,
  168. (int __operation, struct aiocb *__aiocbp),
  169. aio_fsync64) __nonnull ((2));
  170. # else
  171. # define aio_read aio_read64
  172. # define aio_write aio_write64
  173. # define lio_listio lio_listio64
  174. # define aio_error aio_error64
  175. # define aio_return aio_return64
  176. # define aio_cancel aio_cancel64
  177. # define aio_suspend aio_suspend64
  178. # define aio_fsync aio_fsync64
  179. # endif
  180. #endif
  181. #ifdef __USE_LARGEFILE64
  182. extern int aio_read64 (struct aiocb64 *__aiocbp) __THROW __nonnull ((1));
  183. extern int aio_write64 (struct aiocb64 *__aiocbp) __THROW __nonnull ((1));
  184. extern int lio_listio64 (int __mode,
  185. struct aiocb64 *const __list[__restrict_arr],
  186. int __nent, struct sigevent *__restrict __sig)
  187. __THROW __nonnull ((2));
  188. extern int aio_error64 (const struct aiocb64 *__aiocbp)
  189. __THROW __nonnull ((1));
  190. extern __ssize_t aio_return64 (struct aiocb64 *__aiocbp)
  191. __THROW __nonnull ((1));
  192. extern int aio_cancel64 (int __fildes, struct aiocb64 *__aiocbp) __THROW;
  193. extern int aio_suspend64 (const struct aiocb64 *const __list[], int __nent,
  194. const struct timespec *__restrict __timeout)
  195. __THROW __nonnull ((1));
  196. extern int aio_fsync64 (int __operation, struct aiocb64 *__aiocbp)
  197. __THROW __nonnull ((2));
  198. #endif
  199. __END_DECLS
  200. #endif /* aio.h */