Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add io_uring_sqe64,io_uring_sqe128,io_uring_cqe16,io_uring_cqe32 #997

Open
ghost opened this issue Jan 17, 2024 · 1 comment
Open

add io_uring_sqe64,io_uring_sqe128,io_uring_cqe16,io_uring_cqe32 #997

ghost opened this issue Jan 17, 2024 · 1 comment

Comments

@ghost
Copy link

ghost commented Jan 17, 2024

#[repr(C)]
#[derive(Clone, Copy)]
pub struct IoUringSqe<T: Copy> {
    pub opcode: rustix::io_uring::IoringOp,
    pub flags: rustix::io_uring::IoringSqeFlags,
    pub ioprio: rustix::io_uring::ioprio_union,
    pub fd: rustix::fd::RawFd,
    pub off_or_addr2: rustix::io_uring::off_or_addr2_union,
    pub addr_or_splice_off_in: rustix::io_uring::addr_or_splice_off_in_union,
    pub len: rustix::io_uring::len_union,
    pub op_flags: rustix::io_uring::op_flags_union,
    pub user_data: rustix::io_uring::io_uring_user_data,
    pub buf: rustix::io_uring::buf_union,
    pub personality: u16,
    pub splice_fd_in_or_file_index: rustix::io_uring::splice_fd_in_or_file_index_union,
    pub addr3_or_cmd: addr3_or_cmd_union<T>,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub union addr3_or_cmd_union<T: Copy> {
    pub addr3: rustix::io_uring::addr3_struct,
    pub cmd: T,
}

pub type IoUringSqe64 = IoUringSqe<()>;
pub type IoUringSqe128 = IoUringSqe<[u8; 80]>;

#[repr(C)]
#[derive(Clone, Copy)]
pub struct IoUringCqe<T: Copy> {
    pub user_data: rustix::io_uring::io_uring_user_data,
    pub res: i32,
    pub flags: rustix::io_uring::IoringCqeFlags,
    pub big_cqe: T,
}

pub type IoUringCqe16 = IoUringCqe<()>;
pub type IoUringCqe32 = IoUringCqe<[u64; 2]>;
@ghost
Copy link
Author

ghost commented Jan 17, 2024

These structures originally had a fixed length, but for various reasons, kernel developers used flexible arrays. However, in Rust, we can use generics to make them better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants