aio.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /****************************************************************************
  2. * include/aio.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. #ifndef __INCLUDE_AIO_H
  21. #define __INCLUDE_AIO_H
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <nuttx/config.h>
  26. #include <sys/types.h>
  27. #include <time.h>
  28. #include <nuttx/signal.h>
  29. #include <nuttx/wqueue.h>
  30. /****************************************************************************
  31. * Pre-processor Definitions
  32. ****************************************************************************/
  33. /* Configuration ************************************************************/
  34. /* These interfaces are not available to kernel code */
  35. #if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__)
  36. # undef CONFIG_FS_AIO
  37. #endif
  38. /* Work queue support is required. The low-priority work queue is required
  39. * so that the asynchronous I/O does not interfere with high priority driver
  40. * operations. If this pre-requisite is met, then asynchronous I/O support
  41. * can be enabled with CONFIG_FS_AIO
  42. */
  43. #ifdef CONFIG_FS_AIO
  44. #ifndef CONFIG_SCHED_WORKQUEUE
  45. # error Asynchronous I/O requires CONFIG_SCHED_WORKQUEUE
  46. #endif
  47. #ifndef CONFIG_SCHED_LPWORK
  48. # error Asynchronous I/O requires CONFIG_SCHED_LPWORK
  49. #endif
  50. /* Standard Definitions *****************************************************/
  51. /* aio_cancel return values
  52. *
  53. * AIO_ALLDONE - Indicates that none of the requested operations could
  54. * be cancelled since they are already complete.
  55. * AIO_CANCELED - Indicates that all requested operations have been
  56. * cancelled.
  57. * AIO_NOTCANCELED - Indicates that some of the requested operations could
  58. * not be cancelled since they are in progress.
  59. */
  60. #define AIO_CANCELED 0
  61. #define AIO_ALLDONE 1
  62. #define AIO_NOTCANCELED 2
  63. /* lio_listio element operations
  64. *
  65. * LIO_NOP - Indicates that no transfer is requested.
  66. * LIO_READ - Requests a read operation.
  67. * LIO_WRITE - Requests a write operation.
  68. */
  69. #define LIO_NOP 0
  70. #define LIO_READ 1
  71. #define LIO_WRITE 2
  72. /* lio_listio modes
  73. *
  74. * LIO_NOWAIT - Indicates that the calling thread is to continue
  75. * execution while the lio_listio() operation is being
  76. * performed, and no notification is given when the
  77. * operation is complete.
  78. * LIO_WAIT - Indicates that the calling thread is to suspend until
  79. * the lio_listio() operation is complete.
  80. */
  81. #define LIO_NOWAIT 0
  82. #define LIO_WAIT 1
  83. /****************************************************************************
  84. * Type Definitions
  85. ****************************************************************************/
  86. struct aiocb
  87. {
  88. /* Standard fields required by POSIX */
  89. struct sigevent aio_sigevent; /* Signal number and value */
  90. FAR volatile void *aio_buf; /* Location of buffer */
  91. off_t aio_offset; /* File offset */
  92. size_t aio_nbytes; /* Length of transfer */
  93. int16_t aio_fildes; /* File descriptor (should be int) */
  94. int8_t aio_reqprio; /* Request priority offset (not used, should be int) */
  95. uint8_t aio_lio_opcode; /* Operation to be performed (should be int) */
  96. /* Non-standard, implementation-dependent data. For portability reasons,
  97. * application code should never reference these elements.
  98. */
  99. struct sigwork_s aio_sigwork; /* Signal work */
  100. volatile ssize_t aio_result; /* Support for aio_error() and aio_return() */
  101. FAR void *aio_priv; /* Used by signal handlers */
  102. };
  103. /****************************************************************************
  104. * Public Data
  105. ****************************************************************************/
  106. #ifdef __cplusplus
  107. #define EXTERN extern "C"
  108. extern "C"
  109. {
  110. #else
  111. #define EXTERN extern
  112. #endif
  113. /****************************************************************************
  114. * Public Function Prototypes
  115. ****************************************************************************/
  116. int aio_cancel(int fildes, FAR struct aiocb *aiocbp);
  117. int aio_error(FAR const struct aiocb *aiocbp);
  118. int aio_fsync(int op, FAR struct aiocb *aiocbp);
  119. int aio_read(FAR struct aiocb *aiocbp);
  120. ssize_t aio_return(FAR struct aiocb *aiocbp);
  121. int aio_suspend(FAR const struct aiocb * const list[], int nent,
  122. FAR const struct timespec *timeout);
  123. int aio_write(FAR struct aiocb *aiocbp);
  124. int lio_listio(int mode, FAR struct aiocb * const list[], int nent,
  125. FAR struct sigevent *sig);
  126. #undef EXTERN
  127. #ifdef __cplusplus
  128. }
  129. #endif
  130. #endif /* CONFIG_FS_AIO */
  131. #endif /* __INCLUDE_AIO_H */