1#![allow(dead_code)]
6
7use crate::errno::Errno;
8use crate::{syscall_1, syscall_2};
9use alloc::boxed::Box;
10use core::pin::Pin;
11const SYSCALL_IO_SETUP: u32 = 209u32;
12const SYSCALL_IO_DESTROY: u32 = 207u32;
13
14const IOCB_CMD_PREAD: u16 = 0u16;
15const IOCB_CMD_PWRITE: u16 = 1u16;
16const IOCB_CMD_FSYNC: u16 = 2u16;
17const IOCB_CMD_FDSYNC: u16 = 3u16;
18const IOCB_CMD_POLL: u16 = 5u16;
19const IOCB_CMD_NOOP: u16 = 6u16;
20const IOCB_CMD_PREADV: u16 = 7u16;
21const IOCB_CMD_PWRITEV: u16 = 8u16;
22
23pub struct AioContext(u32);
24impl Drop for AioContext {
25 fn drop(&mut self) {
26 unsafe {
27 let _ = io_destroy(self.0);
28 }
29 }
30}
31impl AioContext {
32 pub fn new(max_num_events: u32) -> Result<Self, Errno> {
33 unsafe { io_setup(max_num_events) }
34 }
35
36 }
38
39pub struct AioData {
40 data: Pin<Box<[u8]>>,
41}
42
43pub unsafe fn io_setup(max_num_events: u32) -> Result<AioContext, Errno> {
44 let mut out = 0u32;
45 let ptr = core::ptr::from_mut(&mut out);
46 let res = syscall_2!(SYSCALL_IO_SETUP, max_num_events, ptr);
47
48 if res < 0 {
49 return Err(res.into());
50 }
51 Ok(AioContext(out))
52}
53
54pub unsafe fn io_destroy(context: u32) -> Result<(), Errno> {
55 let res = syscall_1!(SYSCALL_IO_DESTROY, context);
56 if res < 0 {
57 return Err(res.into());
58 }
59 Ok(())
60}