Warning: That file was not part of the compilation database. It may have many parsing errors.

1/* /usr/include/libaio.h
2 *
3 * Copyright 2000,2001,2002 Red Hat, Inc.
4 *
5 * Written by Benjamin LaHaise <bcrl@redhat.com>
6 *
7 * libaio Linux async I/O interface
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23#ifndef __LIBAIO_H
24#define __LIBAIO_H
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#include <sys/types.h>
31#include <string.h>
32
33struct timespec;
34struct sockaddr;
35struct iovec;
36
37typedef struct io_context *io_context_t;
38
39typedef enum io_iocb_cmd {
40 IO_CMD_PREAD = 0,
41 IO_CMD_PWRITE = 1,
42
43 IO_CMD_FSYNC = 2,
44 IO_CMD_FDSYNC = 3,
45
46 IO_CMD_POLL = 5, /* Never implemented in mainline, see io_prep_poll */
47 IO_CMD_NOOP = 6,
48 IO_CMD_PREADV = 7,
49 IO_CMD_PWRITEV = 8,
50} io_iocb_cmd_t;
51
52/* little endian, 32 bits */
53#if defined(__i386__) || (defined(__arm__) && !defined(__ARMEB__)) || \
54 defined(__sh__) || defined(__bfin__) || defined(__MIPSEL__) || \
55 defined(__cris__) || (defined(__riscv) && __riscv_xlen == 32) || \
56 (defined(__GNUC__) && defined(__BYTE_ORDER__) && \
57 __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ && __SIZEOF_LONG__ == 4)
58#define PADDED(x, y) x; unsigned y
59#define PADDEDptr(x, y) x; unsigned y
60#define PADDEDul(x, y) unsigned long x; unsigned y
61
62/* little endian, 64 bits */
63#elif defined(__ia64__) || defined(__x86_64__) || defined(__alpha__) || \
64 (defined(__aarch64__) && defined(__AARCH64EL__)) || \
65 (defined(__riscv) && __riscv_xlen == 64) || \
66 (defined(__GNUC__) && defined(__BYTE_ORDER__) && \
67 __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ && __SIZEOF_LONG__ == 8)
68#define PADDED(x, y) x, y
69#define PADDEDptr(x, y) x
70#define PADDEDul(x, y) unsigned long x
71
72/* big endian, 64 bits */
73#elif defined(__powerpc64__) || defined(__s390x__) || \
74 (defined(__sparc__) && defined(__arch64__)) || \
75 (defined(__aarch64__) && defined(__AARCH64EB__)) || \
76 (defined(__GNUC__) && defined(__BYTE_ORDER__) && \
77 __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ && __SIZEOF_LONG__ == 8)
78#define PADDED(x, y) unsigned y; x
79#define PADDEDptr(x,y) x
80#define PADDEDul(x, y) unsigned long x
81
82/* big endian, 32 bits */
83#elif defined(__PPC__) || defined(__s390__) || \
84 (defined(__arm__) && defined(__ARMEB__)) || \
85 defined(__sparc__) || defined(__MIPSEB__) || defined(__m68k__) || \
86 defined(__hppa__) || defined(__frv__) || defined(__avr32__) || \
87 (defined(__GNUC__) && defined(__BYTE_ORDER__) && \
88 __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ && __SIZEOF_LONG__ == 4)
89#define PADDED(x, y) unsigned y; x
90#define PADDEDptr(x, y) unsigned y; x
91#define PADDEDul(x, y) unsigned y; unsigned long x
92
93#else
94#error endian?
95#endif
96
97struct io_iocb_poll {
98 PADDED(int events, __pad1);
99}; /* result code is the set of result flags or -'ve errno */
100
101struct io_iocb_sockaddr {
102 struct sockaddr *addr;
103 int len;
104}; /* result code is the length of the sockaddr, or -'ve errno */
105
106struct io_iocb_common {
107 PADDEDptr(void *buf, __pad1);
108 PADDEDul(nbytes, __pad2);
109 long long offset;
110 long long __pad3;
111 unsigned flags;
112 unsigned resfd;
113}; /* result code is the amount read or -'ve errno */
114
115struct io_iocb_vector {
116 const struct iovec *vec;
117 int nr;
118 long long offset;
119}; /* result code is the amount read or -'ve errno */
120
121struct iocb {
122 PADDEDptr(void *data, __pad1); /* Return in the io completion event */
123 /* key: For use in identifying io requests */
124 /* aio_rw_flags: RWF_* flags (such as RWF_NOWAIT) */
125 PADDED(unsigned key, aio_rw_flags);
126
127 short aio_lio_opcode;
128 short aio_reqprio;
129 int aio_fildes;
130
131 union {
132 struct io_iocb_common c;
133 struct io_iocb_vector v;
134 struct io_iocb_poll poll;
135 struct io_iocb_sockaddr saddr;
136 } u;
137};
138
139struct io_event {
140 PADDEDptr(void *data, __pad1);
141 PADDEDptr(struct iocb *obj, __pad2);
142 PADDEDul(res, __pad3);
143 PADDEDul(res2, __pad4);
144};
145
146#undef PADDED
147#undef PADDEDptr
148#undef PADDEDul
149
150typedef void (*io_callback_t)(io_context_t ctx, struct iocb *iocb, long res, long res2);
151
152/* library wrappers */
153extern int io_queue_init(int maxevents, io_context_t *ctxp);
154/*extern int io_queue_grow(io_context_t ctx, int new_maxevents);*/
155extern int io_queue_release(io_context_t ctx);
156/*extern int io_queue_wait(io_context_t ctx, struct timespec *timeout);*/
157extern int io_queue_run(io_context_t ctx);
158
159/* Actual syscalls */
160extern int io_setup(int maxevents, io_context_t *ctxp);
161extern int io_destroy(io_context_t ctx);
162extern int io_submit(io_context_t ctx, long nr, struct iocb *ios[]);
163extern int io_cancel(io_context_t ctx, struct iocb *iocb, struct io_event *evt);
164extern int io_getevents(io_context_t ctx_id, long min_nr, long nr, struct io_event *events, struct timespec *timeout);
165
166
167static inline void io_set_callback(struct iocb *iocb, io_callback_t cb)
168{
169 iocb->data = (void *)cb;
170}
171
172static inline void io_prep_pread(struct iocb *iocb, int fd, void *buf, size_t count, long long offset)
173{
174 memset(iocb, 0, sizeof(*iocb));
175 iocb->aio_fildes = fd;
176 iocb->aio_lio_opcode = IO_CMD_PREAD;
177 iocb->aio_reqprio = 0;
178 iocb->u.c.buf = buf;
179 iocb->u.c.nbytes = count;
180 iocb->u.c.offset = offset;
181}
182
183static inline void io_prep_pwrite(struct iocb *iocb, int fd, void *buf, size_t count, long long offset)
184{
185 memset(iocb, 0, sizeof(*iocb));
186 iocb->aio_fildes = fd;
187 iocb->aio_lio_opcode = IO_CMD_PWRITE;
188 iocb->aio_reqprio = 0;
189 iocb->u.c.buf = buf;
190 iocb->u.c.nbytes = count;
191 iocb->u.c.offset = offset;
192}
193
194static inline void io_prep_preadv(struct iocb *iocb, int fd, const struct iovec *iov, int iovcnt, long long offset)
195{
196 memset(iocb, 0, sizeof(*iocb));
197 iocb->aio_fildes = fd;
198 iocb->aio_lio_opcode = IO_CMD_PREADV;
199 iocb->aio_reqprio = 0;
200 iocb->u.c.buf = (void *)iov;
201 iocb->u.c.nbytes = iovcnt;
202 iocb->u.c.offset = offset;
203}
204
205static inline void io_prep_pwritev(struct iocb *iocb, int fd, const struct iovec *iov, int iovcnt, long long offset)
206{
207 memset(iocb, 0, sizeof(*iocb));
208 iocb->aio_fildes = fd;
209 iocb->aio_lio_opcode = IO_CMD_PWRITEV;
210 iocb->aio_reqprio = 0;
211 iocb->u.c.buf = (void *)iov;
212 iocb->u.c.nbytes = iovcnt;
213 iocb->u.c.offset = offset;
214}
215
216static inline void io_prep_preadv2(struct iocb *iocb, int fd, const struct iovec *iov, int iovcnt, long long offset, int flags)
217{
218 memset(iocb, 0, sizeof(*iocb));
219 iocb->aio_fildes = fd;
220 iocb->aio_lio_opcode = IO_CMD_PREADV;
221 iocb->aio_reqprio = 0;
222 iocb->aio_rw_flags = flags;
223 iocb->u.c.buf = (void *)iov;
224 iocb->u.c.nbytes = iovcnt;
225 iocb->u.c.offset = offset;
226}
227
228static inline void io_prep_pwritev2(struct iocb *iocb, int fd, const struct iovec *iov, int iovcnt, long long offset, int flags)
229{
230 memset(iocb, 0, sizeof(*iocb));
231 iocb->aio_fildes = fd;
232 iocb->aio_lio_opcode = IO_CMD_PWRITEV;
233 iocb->aio_reqprio = 0;
234 iocb->aio_rw_flags = flags;
235 iocb->u.c.buf = (void *)iov;
236 iocb->u.c.nbytes = iovcnt;
237 iocb->u.c.offset = offset;
238}
239
240/* Jeff Moyer says this was implemented in Red Hat AS2.1 and RHEL3.
241 * AFAICT, it was never in mainline, and should not be used. --RR */
242static inline void io_prep_poll(struct iocb *iocb, int fd, int events)
243{
244 memset(iocb, 0, sizeof(*iocb));
245 iocb->aio_fildes = fd;
246 iocb->aio_lio_opcode = IO_CMD_POLL;
247 iocb->aio_reqprio = 0;
248 iocb->u.poll.events = events;
249}
250
251static inline int io_poll(io_context_t ctx, struct iocb *iocb, io_callback_t cb, int fd, int events)
252{
253 io_prep_poll(iocb, fd, events);
254 io_set_callback(iocb, cb);
255 return io_submit(ctx, 1, &iocb);
256}
257
258static inline void io_prep_fsync(struct iocb *iocb, int fd)
259{
260 memset(iocb, 0, sizeof(*iocb));
261 iocb->aio_fildes = fd;
262 iocb->aio_lio_opcode = IO_CMD_FSYNC;
263 iocb->aio_reqprio = 0;
264}
265
266static inline int io_fsync(io_context_t ctx, struct iocb *iocb, io_callback_t cb, int fd)
267{
268 io_prep_fsync(iocb, fd);
269 io_set_callback(iocb, cb);
270 return io_submit(ctx, 1, &iocb);
271}
272
273static inline void io_prep_fdsync(struct iocb *iocb, int fd)
274{
275 memset(iocb, 0, sizeof(*iocb));
276 iocb->aio_fildes = fd;
277 iocb->aio_lio_opcode = IO_CMD_FDSYNC;
278 iocb->aio_reqprio = 0;
279}
280
281static inline int io_fdsync(io_context_t ctx, struct iocb *iocb, io_callback_t cb, int fd)
282{
283 io_prep_fdsync(iocb, fd);
284 io_set_callback(iocb, cb);
285 return io_submit(ctx, 1, &iocb);
286}
287
288static inline void io_set_eventfd(struct iocb *iocb, int eventfd)
289{
290 iocb->u.c.flags |= (1 << 0) /* IOCB_FLAG_RESFD */;
291 iocb->u.c.resfd = eventfd;
292}
293
294#ifdef __cplusplus
295}
296#endif
297
298#endif /* __LIBAIO_H */
299

Warning: That file was not part of the compilation database. It may have many parsing errors.