blob: 7430bc81e1c4322ab81940fbe9dc3471e0be0a8f [file] [log] [blame]
Jerry Zhangecee4342017-07-18 14:07:57 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <asyncio/AsyncIO.h>
18#include <sys/syscall.h>
19#include <unistd.h>
20
21int io_setup(unsigned nr, aio_context_t* ctxp) {
22 memset(ctxp, 0, sizeof(*ctxp));
23 return syscall(__NR_io_setup, nr, ctxp);
24}
25
26int io_destroy(aio_context_t ctx) {
27 return syscall(__NR_io_destroy, ctx);
28}
29
30int io_submit(aio_context_t ctx, long nr, iocb** iocbpp) {
31 return syscall(__NR_io_submit, ctx, nr, iocbpp);
32}
33
34int io_getevents(aio_context_t ctx, long min_nr, long max_nr, io_event* events, timespec* timeout) {
35 return syscall(__NR_io_getevents, ctx, min_nr, max_nr, events, timeout);
36}
37
38int io_cancel(aio_context_t ctx, iocb* iocbp, io_event* result) {
39 return syscall(__NR_io_cancel, ctx, iocbp, result);
40}
41
42void io_prep(iocb* iocb, int fd, const void* buf, uint64_t count, int64_t offset, bool read) {
43 memset(iocb, 0, sizeof(*iocb));
44 iocb->aio_fildes = fd;
45 iocb->aio_lio_opcode = read ? IOCB_CMD_PREAD : IOCB_CMD_PWRITE;
46 iocb->aio_reqprio = 0;
47 iocb->aio_buf = reinterpret_cast<uint64_t>(buf);
48 iocb->aio_nbytes = count;
49 iocb->aio_offset = offset;
50}