aio.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /****************************************************************************
  2. * include/aio.h
  3. *
  4. * Copyright (C) 2014 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. #ifndef __INCLUDE_AIO_H
  36. #define __INCLUDE_AIO_H
  37. /****************************************************************************
  38. * Included Files
  39. ****************************************************************************/
  40. #include <nuttx/config.h>
  41. #include <sys/types.h>
  42. #include <time.h>
  43. #include <nuttx/signal.h>
  44. #include <nuttx/wqueue.h>
  45. /****************************************************************************
  46. * Pre-processor Definitions
  47. ****************************************************************************/
  48. /* Configuration ************************************************************/
  49. /* These interfaces are not available to kernel code */
  50. #if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__)
  51. # undef CONFIG_FS_AIO
  52. #endif
  53. /* Work queue support is required. The low-priority work queue is required
  54. * so that the asynchronous I/O does not interfere with high priority driver
  55. * operations. If this pre-requisite is met, then asynchronous I/O support
  56. * can be enabled with CONFIG_FS_AIO
  57. */
  58. #ifdef CONFIG_FS_AIO
  59. #ifndef CONFIG_SCHED_WORKQUEUE
  60. # error Asynchronous I/O requires CONFIG_SCHED_WORKQUEUE
  61. #endif
  62. #ifndef CONFIG_SCHED_LPWORK
  63. # error Asynchronous I/O requires CONFIG_SCHED_LPWORK
  64. #endif
  65. /* Standard Definitions *****************************************************/
  66. /* aio_cancel return values
  67. *
  68. * AIO_ALLDONE - Indicates that none of the requested operations could
  69. * be cancelled since they are already complete.
  70. * AIO_CANCELED - Indicates that all requested operations have been
  71. * cancelled.
  72. * AIO_NOTCANCELED - Indicates that some of the requested operations could
  73. * not be cancelled since they are in progress.
  74. */
  75. #define AIO_CANCELED 0
  76. #define AIO_ALLDONE 1
  77. #define AIO_NOTCANCELED 2
  78. /* lio_listio element operations
  79. *
  80. * LIO_NOP - Indicates that no transfer is requested.
  81. * LIO_READ - Requests a read operation.
  82. * LIO_WRITE - Requests a write operation.
  83. */
  84. #define LIO_NOP 0
  85. #define LIO_READ 1
  86. #define LIO_WRITE 2
  87. /* lio_listio modes
  88. *
  89. * LIO_NOWAIT - Indicates that the calling thread is to continue
  90. * execution while the lio_listio() operation is being
  91. * performed, and no notification is given when the
  92. * operation is complete.
  93. * LIO_WAIT - Indicates that the calling thread is to suspend until
  94. * the lio_listio() operation is complete.
  95. */
  96. #define LIO_NOWAIT 0
  97. #define LIO_WAIT 1
  98. /****************************************************************************
  99. * Type Definitions
  100. ****************************************************************************/
  101. struct aiocb
  102. {
  103. /* Standard fields required by POSIX */
  104. struct sigevent aio_sigevent; /* Signal number and value */
  105. FAR volatile void *aio_buf; /* Location of buffer */
  106. off_t aio_offset; /* File offset */
  107. size_t aio_nbytes; /* Length of transfer */
  108. #if (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS) > 127
  109. int16_t aio_fildes; /* File descriptor (should be int) */
  110. #else
  111. int8_t aio_fildes; /* File descriptor (should be int) */
  112. #endif
  113. int8_t aio_reqprio; /* Request priority offset (not used, should be int) */
  114. uint8_t aio_lio_opcode; /* Operation to be performed (should be int) */
  115. /* Non-standard, implementation-dependent data. For portability reasons,
  116. * application code should never reference these elements.
  117. */
  118. struct sigwork_s aio_sigwork; /* Signal work */
  119. volatile ssize_t aio_result; /* Support for aio_error() and aio_return() */
  120. FAR void *aio_priv; /* Used by signal handlers */
  121. };
  122. /****************************************************************************
  123. * Public Data
  124. ****************************************************************************/
  125. #ifdef __cplusplus
  126. #define EXTERN extern "C"
  127. extern "C"
  128. {
  129. #else
  130. #define EXTERN extern
  131. #endif
  132. /****************************************************************************
  133. * Public Function Prototypes
  134. ****************************************************************************/
  135. int aio_cancel(int fildes, FAR struct aiocb *aiocbp);
  136. int aio_error(FAR const struct aiocb *aiocbp);
  137. int aio_fsync(int op, FAR struct aiocb *aiocbp);
  138. int aio_read(FAR struct aiocb *aiocbp);
  139. ssize_t aio_return(FAR struct aiocb *aiocbp);
  140. int aio_suspend(FAR const struct aiocb * const list[], int nent,
  141. FAR const struct timespec *timeout);
  142. int aio_write(FAR struct aiocb *aiocbp);
  143. int lio_listio(int mode, FAR struct aiocb * const list[], int nent,
  144. FAR struct sigevent *sig);
  145. #undef EXTERN
  146. #ifdef __cplusplus
  147. }
  148. #endif
  149. #endif /* CONFIG_FS_AIO */
  150. #endif /* __INCLUDE_AIO_H */