aio.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /* Copyright (C) 1996-2016 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. <http://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. #define __need_sigevent_t
  22. #include <bits/siginfo.h>
  23. #define __need_timespec
  24. #include <time.h>
  25. __BEGIN_DECLS
  26. /* Asynchronous I/O control block. */
  27. struct aiocb
  28. {
  29. int aio_fildes; /* File desriptor. */
  30. int aio_lio_opcode; /* Operation to be performed. */
  31. int aio_reqprio; /* Request priority offset. */
  32. volatile void *aio_buf; /* Location of buffer. */
  33. size_t aio_nbytes; /* Length of transfer. */
  34. struct sigevent aio_sigevent; /* Signal number and value. */
  35. /* Internal members. */
  36. struct aiocb *__next_prio;
  37. int __abs_prio;
  38. int __policy;
  39. int __error_code;
  40. __ssize_t __return_value;
  41. #ifndef __USE_FILE_OFFSET64
  42. __off_t aio_offset; /* File offset. */
  43. char __pad[sizeof (__off64_t) - sizeof (__off_t)];
  44. #else
  45. __off64_t aio_offset; /* File offset. */
  46. #endif
  47. char __glibc_reserved[32];
  48. };
  49. /* The same for the 64bit offsets. Please note that the members aio_fildes
  50. to __return_value have to be the same in aiocb and aiocb64. */
  51. #ifdef __USE_LARGEFILE64
  52. struct aiocb64
  53. {
  54. int aio_fildes; /* File desriptor. */
  55. int aio_lio_opcode; /* Operation to be performed. */
  56. int aio_reqprio; /* Request priority offset. */
  57. volatile void *aio_buf; /* Location of buffer. */
  58. size_t aio_nbytes; /* Length of transfer. */
  59. struct sigevent aio_sigevent; /* Signal number and value. */
  60. /* Internal members. */
  61. struct aiocb *__next_prio;
  62. int __abs_prio;
  63. int __policy;
  64. int __error_code;
  65. __ssize_t __return_value;
  66. __off64_t aio_offset; /* File offset. */
  67. char __glibc_reserved[32];
  68. };
  69. #endif
  70. #ifdef __USE_GNU
  71. /* To customize the implementation one can use the following struct.
  72. This implementation follows the one in Irix. */
  73. struct aioinit
  74. {
  75. int aio_threads; /* Maximal number of threads. */
  76. int aio_num; /* Number of expected simultanious requests. */
  77. int aio_locks; /* Not used. */
  78. int aio_usedba; /* Not used. */
  79. int aio_debug; /* Not used. */
  80. int aio_numusers; /* Not used. */
  81. int aio_idle_time; /* Number of seconds before idle thread
  82. terminates. */
  83. int aio_reserved;
  84. };
  85. #endif
  86. /* Return values of cancelation function. */
  87. enum
  88. {
  89. AIO_CANCELED,
  90. #define AIO_CANCELED AIO_CANCELED
  91. AIO_NOTCANCELED,
  92. #define AIO_NOTCANCELED AIO_NOTCANCELED
  93. AIO_ALLDONE
  94. #define AIO_ALLDONE AIO_ALLDONE
  95. };
  96. /* Operation codes for `aio_lio_opcode'. */
  97. enum
  98. {
  99. LIO_READ,
  100. #define LIO_READ LIO_READ
  101. LIO_WRITE,
  102. #define LIO_WRITE LIO_WRITE
  103. LIO_NOP
  104. #define LIO_NOP LIO_NOP
  105. };
  106. /* Synchronization options for `lio_listio' function. */
  107. enum
  108. {
  109. LIO_WAIT,
  110. #define LIO_WAIT LIO_WAIT
  111. LIO_NOWAIT
  112. #define LIO_NOWAIT LIO_NOWAIT
  113. };
  114. /* Allow user to specify optimization. */
  115. #ifdef __USE_GNU
  116. extern void aio_init (const struct aioinit *__init) __THROW __nonnull ((1));
  117. #endif
  118. #ifndef __USE_FILE_OFFSET64
  119. /* Enqueue read request for given number of bytes and the given priority. */
  120. extern int aio_read (struct aiocb *__aiocbp) __THROW __nonnull ((1));
  121. /* Enqueue write request for given number of bytes and the given priority. */
  122. extern int aio_write (struct aiocb *__aiocbp) __THROW __nonnull ((1));
  123. /* Initiate list of I/O requests. */
  124. extern int lio_listio (int __mode,
  125. struct aiocb *const __list[__restrict_arr],
  126. int __nent, struct sigevent *__restrict __sig)
  127. __THROW __nonnull ((2));
  128. /* Retrieve error status associated with AIOCBP. */
  129. extern int aio_error (const struct aiocb *__aiocbp) __THROW __nonnull ((1));
  130. /* Return status associated with AIOCBP. */
  131. extern __ssize_t aio_return (struct aiocb *__aiocbp) __THROW __nonnull ((1));
  132. /* Try to cancel asynchronous I/O requests outstanding against file
  133. descriptor FILDES. */
  134. extern int aio_cancel (int __fildes, struct aiocb *__aiocbp) __THROW;
  135. /* Suspend calling thread until at least one of the asynchronous I/O
  136. operations referenced by LIST has completed.
  137. This function is a cancellation point and therefore not marked with
  138. __THROW. */
  139. extern int aio_suspend (const struct aiocb *const __list[], int __nent,
  140. const struct timespec *__restrict __timeout)
  141. __nonnull ((1));
  142. /* Force all operations associated with file desriptor described by
  143. `aio_fildes' member of AIOCBP. */
  144. extern int aio_fsync (int __operation, struct aiocb *__aiocbp)
  145. __THROW __nonnull ((2));
  146. #else
  147. # ifdef __REDIRECT_NTH
  148. extern int __REDIRECT_NTH (aio_read, (struct aiocb *__aiocbp), aio_read64)
  149. __nonnull ((1));
  150. extern int __REDIRECT_NTH (aio_write, (struct aiocb *__aiocbp), aio_write64)
  151. __nonnull ((1));
  152. extern int __REDIRECT_NTH (lio_listio,
  153. (int __mode,
  154. struct aiocb *const __list[__restrict_arr],
  155. int __nent, struct sigevent *__restrict __sig),
  156. lio_listio64) __nonnull ((2));
  157. extern int __REDIRECT_NTH (aio_error, (const struct aiocb *__aiocbp),
  158. aio_error64) __nonnull ((1));
  159. extern __ssize_t __REDIRECT_NTH (aio_return, (struct aiocb *__aiocbp),
  160. aio_return64) __nonnull ((1));
  161. extern int __REDIRECT_NTH (aio_cancel,
  162. (int __fildes, struct aiocb *__aiocbp),
  163. aio_cancel64);
  164. extern int __REDIRECT_NTH (aio_suspend,
  165. (const struct aiocb *const __list[], int __nent,
  166. const struct timespec *__restrict __timeout),
  167. aio_suspend64) __nonnull ((1));
  168. extern int __REDIRECT_NTH (aio_fsync,
  169. (int __operation, struct aiocb *__aiocbp),
  170. aio_fsync64) __nonnull ((2));
  171. # else
  172. # define aio_read aio_read64
  173. # define aio_write aio_write64
  174. # define lio_listio lio_listio64
  175. # define aio_error aio_error64
  176. # define aio_return aio_return64
  177. # define aio_cancel aio_cancel64
  178. # define aio_suspend aio_suspend64
  179. # define aio_fsync aio_fsync64
  180. # endif
  181. #endif
  182. #ifdef __USE_LARGEFILE64
  183. extern int aio_read64 (struct aiocb64 *__aiocbp) __THROW __nonnull ((1));
  184. extern int aio_write64 (struct aiocb64 *__aiocbp) __THROW __nonnull ((1));
  185. extern int lio_listio64 (int __mode,
  186. struct aiocb64 *const __list[__restrict_arr],
  187. int __nent, struct sigevent *__restrict __sig)
  188. __THROW __nonnull ((2));
  189. extern int aio_error64 (const struct aiocb64 *__aiocbp)
  190. __THROW __nonnull ((1));
  191. extern __ssize_t aio_return64 (struct aiocb64 *__aiocbp)
  192. __THROW __nonnull ((1));
  193. extern int aio_cancel64 (int __fildes, struct aiocb64 *__aiocbp) __THROW;
  194. extern int aio_suspend64 (const struct aiocb64 *const __list[], int __nent,
  195. const struct timespec *__restrict __timeout)
  196. __THROW __nonnull ((1));
  197. extern int aio_fsync64 (int __operation, struct aiocb64 *__aiocbp)
  198. __THROW __nonnull ((2));
  199. #endif
  200. __END_DECLS
  201. #endif /* aio.h */