#![allow(clippy::new_without_default)]
use std::convert::TryInto;
use std::mem;
use std::os::unix::io::RawFd;
use crate::squeue::Entry;
use crate::squeue::Entry128;
use crate::sys;
use crate::types::{self, sealed};
macro_rules! assign_fd {
( $sqe:ident . fd = $opfd:expr ) => {
match $opfd {
sealed::Target::Fd(fd) => $sqe.fd = fd,
sealed::Target::Fixed(i) => {
$sqe.fd = i as _;
$sqe.flags |= crate::squeue::Flags::FIXED_FILE.bits();
}
}
};
}
macro_rules! opcode {
(@type impl sealed::UseFixed ) => {
sealed::Target
};
(@type impl sealed::UseFd ) => {
RawFd
};
(@type $name:ty ) => {
$name
};
(
$( #[$outer:meta] )*
pub struct $name:ident {
$( #[$new_meta:meta] )*
$( $field:ident : { $( $tnt:tt )+ } ),*
$(,)?
;;
$(
$( #[$opt_meta:meta] )*
$opt_field:ident : $opt_tname:ty = $default:expr
),*
$(,)?
}
pub const CODE = $opcode:expr;
$( #[$build_meta:meta] )*
pub fn build($self:ident) -> $entry:ty $build_block:block
) => {
$( #[$outer] )*
pub struct $name {
$( $field : opcode!(@type $( $tnt )*), )*
$( $opt_field : $opt_tname, )*
}
#[allow(deprecated)]
impl $name {
$( #[$new_meta] )*
#[inline]
pub fn new($( $field : $( $tnt )* ),*) -> Self {
$name {
$( $field: $field.into(), )*
$( $opt_field: $default, )*
}
}
pub const CODE: u8 = $opcode as _;
$(
$( #[$opt_meta] )*
#[inline]
pub const fn $opt_field(mut self, $opt_field: $opt_tname) -> Self {
self.$opt_field = $opt_field;
self
}
)*
$( #[$build_meta] )*
#[inline]
pub fn build($self) -> $entry $build_block
}
}
}
#[inline(always)]
fn sqe_zeroed() -> sys::io_uring_sqe {
unsafe { std::mem::zeroed() }
}
opcode!(
#[derive(Debug)]
pub struct Nop { ;; }
pub const CODE = sys::IORING_OP_NOP;
pub fn build(self) -> Entry {
let Nop {} = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = -1;
Entry(sqe)
}
);
opcode!(
#[derive(Debug)]
pub struct Readv {
fd: { impl sealed::UseFixed },
iovec: { *const libc::iovec },
len: { u32 },
;;
ioprio: u16 = 0,
offset64: libc::off64_t = 0,
rw_flags: types::RwFlags = 0,
buf_group: u16 = 0
}
pub const CODE = sys::IORING_OP_READV;
pub fn build(self) -> Entry {
let Readv {
fd,
iovec, len, offset64,
ioprio, rw_flags,
buf_group
} = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.ioprio = ioprio;
sqe.__bindgen_anon_2.addr = iovec as _;
sqe.len = len;
sqe.__bindgen_anon_1.off = offset64 as _;
sqe.__bindgen_anon_3.rw_flags = rw_flags;
sqe.__bindgen_anon_4.buf_group = buf_group;
Entry(sqe)
}
);
impl Readv {
#[inline]
pub const fn offset(self, offset: libc::off_t) -> Self {
self.offset64(offset as libc::off64_t)
}
}
opcode!(
#[derive(Debug)]
pub struct Writev {
fd: { impl sealed::UseFixed },
iovec: { *const libc::iovec },
len: { u32 },
;;
ioprio: u16 = 0,
offset64: libc::off64_t = 0,
rw_flags: types::RwFlags = 0
}
pub const CODE = sys::IORING_OP_WRITEV;
pub fn build(self) -> Entry {
let Writev {
fd,
iovec, len, offset64,
ioprio, rw_flags
} = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.ioprio = ioprio;
sqe.__bindgen_anon_2.addr = iovec as _;
sqe.len = len;
sqe.__bindgen_anon_1.off = offset64 as _;
sqe.__bindgen_anon_3.rw_flags = rw_flags;
Entry(sqe)
}
);
impl Writev {
#[inline]
pub const fn offset(self, offset: libc::off_t) -> Self {
self.offset64(offset as libc::off64_t)
}
}
opcode!(
#[derive(Debug)]
pub struct Fsync {
fd: { impl sealed::UseFixed },
;;
flags: types::FsyncFlags = types::FsyncFlags::empty()
}
pub const CODE = sys::IORING_OP_FSYNC;
pub fn build(self) -> Entry {
let Fsync { fd, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_3.fsync_flags = flags.bits();
Entry(sqe)
}
);
opcode!(
#[derive(Debug)]
pub struct ReadFixed {
fd: { impl sealed::UseFixed },
buf: { *mut u8 },
len: { u32 },
buf_index: { u16 },
;;
offset64: libc::off64_t = 0,
ioprio: u16 = 0,
rw_flags: types::RwFlags = 0
}
pub const CODE = sys::IORING_OP_READ_FIXED;
pub fn build(self) -> Entry {
let ReadFixed {
fd,
buf, len, offset64,
buf_index,
ioprio, rw_flags
} = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.ioprio = ioprio;
sqe.__bindgen_anon_2.addr = buf as _;
sqe.len = len;
sqe.__bindgen_anon_1.off = offset64 as _;
sqe.__bindgen_anon_3.rw_flags = rw_flags;
sqe.__bindgen_anon_4.buf_index = buf_index;
Entry(sqe)
}
);
impl ReadFixed {
#[inline]
pub const fn offset(self, offset: libc::off_t) -> Self {
self.offset64(offset as libc::off64_t)
}
}
opcode!(
#[derive(Debug)]
pub struct WriteFixed {
fd: { impl sealed::UseFixed },
buf: { *const u8 },
len: { u32 },
buf_index: { u16 },
;;
ioprio: u16 = 0,
offset64: libc::off64_t = 0,
rw_flags: types::RwFlags = 0
}
pub const CODE = sys::IORING_OP_WRITE_FIXED;
pub fn build(self) -> Entry {
let WriteFixed {
fd,
buf, len, offset64,
buf_index,
ioprio, rw_flags
} = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.ioprio = ioprio;
sqe.__bindgen_anon_2.addr = buf as _;
sqe.len = len;
sqe.__bindgen_anon_1.off = offset64 as _;
sqe.__bindgen_anon_3.rw_flags = rw_flags;
sqe.__bindgen_anon_4.buf_index = buf_index;
Entry(sqe)
}
);
impl WriteFixed {
#[inline]
pub const fn offset(self, offset: libc::off_t) -> Self {
self.offset64(offset as libc::off64_t)
}
}
opcode!(
#[derive(Debug)]
pub struct PollAdd {
fd: { impl sealed::UseFixed },
flags: { u32 },
;;
multi: bool = false
}
pub const CODE = sys::IORING_OP_POLL_ADD;
pub fn build(self) -> Entry {
let PollAdd { fd, flags, multi } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
if multi {
sqe.len = sys::IORING_POLL_ADD_MULTI;
}
#[cfg(target_endian = "little")] {
sqe.__bindgen_anon_3.poll32_events = flags;
}
#[cfg(target_endian = "big")] {
let x = flags << 16;
let y = flags >> 16;
let flags = x | y;
sqe.__bindgen_anon_3.poll32_events = flags;
}
Entry(sqe)
}
);
opcode!(
#[derive(Debug)]
pub struct PollRemove {
user_data: { u64 }
;;
}
pub const CODE = sys::IORING_OP_POLL_REMOVE;
pub fn build(self) -> Entry {
let PollRemove { user_data } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = -1;
sqe.__bindgen_anon_2.addr = user_data as _;
Entry(sqe)
}
);
opcode!(
#[derive(Debug)]
pub struct SyncFileRange {
fd: { impl sealed::UseFixed },
len: { u32 },
;;
offset: libc::off64_t = 0,
flags: u32 = 0
}
pub const CODE = sys::IORING_OP_SYNC_FILE_RANGE;
pub fn build(self) -> Entry {
let SyncFileRange {
fd,
len, offset,
flags
} = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.len = len as _;
sqe.__bindgen_anon_1.off = offset as _;
sqe.__bindgen_anon_3.sync_range_flags = flags;
Entry(sqe)
}
);
opcode!(
#[derive(Debug)]
pub struct SendMsg {
fd: { impl sealed::UseFixed },
msg: { *const libc::msghdr },
;;
ioprio: u16 = 0,
flags: u32 = 0
}
pub const CODE = sys::IORING_OP_SENDMSG;
pub fn build(self) -> Entry {
let SendMsg { fd, msg, ioprio, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.ioprio = ioprio;
sqe.__bindgen_anon_2.addr = msg as _;
sqe.len = 1;
sqe.__bindgen_anon_3.msg_flags = flags;
Entry(sqe)
}
);
opcode!(
#[derive(Debug)]
pub struct RecvMsg {
fd: { impl sealed::UseFixed },
msg: { *mut libc::msghdr },
;;
ioprio: u16 = 0,
flags: u32 = 0,
buf_group: u16 = 0
}
pub const CODE = sys::IORING_OP_RECVMSG;
pub fn build(self) -> Entry {
let RecvMsg { fd, msg, ioprio, flags, buf_group } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.ioprio = ioprio;
sqe.__bindgen_anon_2.addr = msg as _;
sqe.len = 1;
sqe.__bindgen_anon_3.msg_flags = flags;
sqe.__bindgen_anon_4.buf_group = buf_group;
Entry(sqe)
}
);
opcode!(
#[derive(Debug)]
pub struct RecvMsgMulti {
fd: { impl sealed::UseFixed },
msg: { *const libc::msghdr },
buf_group: { u16 },
;;
ioprio: u16 = 0,
flags: u32 = 0
}
pub const CODE = sys::IORING_OP_RECVMSG;
pub fn build(self) -> Entry {
let RecvMsgMulti { fd, msg, buf_group, ioprio, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_2.addr = msg as _;
sqe.len = 1;
sqe.__bindgen_anon_3.msg_flags = flags;
sqe.__bindgen_anon_4.buf_group = buf_group;
sqe.flags |= 1 << sys::IOSQE_BUFFER_SELECT_BIT;
sqe.ioprio = ioprio | (sys::IORING_RECV_MULTISHOT as u16);
Entry(sqe)
}
);
opcode!(
#[derive(Debug)]
pub struct Timeout {
timespec: { *const types::Timespec },
;;
count: u32 = 0,
flags: types::TimeoutFlags = types::TimeoutFlags::empty()
}
pub const CODE = sys::IORING_OP_TIMEOUT;
pub fn build(self) -> Entry {
let Timeout { timespec, count, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = -1;
sqe.__bindgen_anon_2.addr = timespec as _;
sqe.len = 1;
sqe.__bindgen_anon_1.off = count as _;
sqe.__bindgen_anon_3.timeout_flags = flags.bits();
Entry(sqe)
}
);
opcode!(
pub struct TimeoutRemove {
user_data: { u64 },
;;
flags: types::TimeoutFlags = types::TimeoutFlags::empty()
}
pub const CODE = sys::IORING_OP_TIMEOUT_REMOVE;
pub fn build(self) -> Entry {
let TimeoutRemove { user_data, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = -1;
sqe.__bindgen_anon_2.addr = user_data as _;
sqe.__bindgen_anon_3.timeout_flags = flags.bits();
Entry(sqe)
}
);
opcode!(
pub struct Accept {
fd: { impl sealed::UseFixed },
addr: { *mut libc::sockaddr },
addrlen: { *mut libc::socklen_t },
;;
file_index: Option<types::DestinationSlot> = None,
flags: i32 = 0
}
pub const CODE = sys::IORING_OP_ACCEPT;
pub fn build(self) -> Entry {
let Accept { fd, addr, addrlen, file_index, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_2.addr = addr as _;
sqe.__bindgen_anon_1.addr2 = addrlen as _;
sqe.__bindgen_anon_3.accept_flags = flags as _;
if let Some(dest) = file_index {
sqe.__bindgen_anon_5.file_index = dest.kernel_index_arg();
}
Entry(sqe)
}
);
opcode!(
pub struct AcceptMulti {
fd: { impl sealed::UseFixed },
;;
allocate_file_index: bool = false,
flags: i32 = 0
}
pub const CODE = sys::IORING_OP_ACCEPT;
pub fn build(self) -> Entry {
let AcceptMulti { fd, allocate_file_index, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.ioprio = sys::IORING_ACCEPT_MULTISHOT as u16;
sqe.__bindgen_anon_3.accept_flags = flags as _;
if allocate_file_index {
sqe.__bindgen_anon_5.file_index = sys::IORING_FILE_INDEX_ALLOC as u32;
}
Entry(sqe)
}
);
opcode!(
pub struct AsyncCancel {
user_data: { u64 }
;;
}
pub const CODE = sys::IORING_OP_ASYNC_CANCEL;
pub fn build(self) -> Entry {
let AsyncCancel { user_data } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = -1;
sqe.__bindgen_anon_2.addr = user_data as _;
Entry(sqe)
}
);
opcode!(
pub struct LinkTimeout {
timespec: { *const types::Timespec },
;;
flags: types::TimeoutFlags = types::TimeoutFlags::empty()
}
pub const CODE = sys::IORING_OP_LINK_TIMEOUT;
pub fn build(self) -> Entry {
let LinkTimeout { timespec, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = -1;
sqe.__bindgen_anon_2.addr = timespec as _;
sqe.len = 1;
sqe.__bindgen_anon_3.timeout_flags = flags.bits();
Entry(sqe)
}
);
opcode!(
pub struct Connect {
fd: { impl sealed::UseFixed },
addr: { *const libc::sockaddr },
addrlen: { libc::socklen_t }
;;
}
pub const CODE = sys::IORING_OP_CONNECT;
pub fn build(self) -> Entry {
let Connect { fd, addr, addrlen } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_2.addr = addr as _;
sqe.__bindgen_anon_1.off = addrlen as _;
Entry(sqe)
}
);
opcode!(
#[deprecated(note = "use Fallocate64 instead, which always takes a 64-bit length")]
pub struct Fallocate {
fd: { impl sealed::UseFixed },
len: { libc::off_t },
;;
offset64: libc::off64_t = 0,
mode: i32 = 0
}
pub const CODE = sys::IORING_OP_FALLOCATE;
pub fn build(self) -> Entry {
let Fallocate { fd, len, offset64, mode } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_2.addr = len as _;
sqe.len = mode as _;
sqe.__bindgen_anon_1.off = offset64 as _;
Entry(sqe)
}
);
#[allow(deprecated)]
impl Fallocate {
#[inline]
pub const fn offset(self, offset: libc::off_t) -> Self {
self.offset64(offset as libc::off64_t)
}
}
opcode!(
pub struct Fallocate64 {
fd: { impl sealed::UseFixed },
len: { libc::off64_t },
;;
offset64: libc::off64_t = 0,
mode: i32 = 0
}
pub const CODE = sys::IORING_OP_FALLOCATE;
pub fn build(self) -> Entry {
let Fallocate64 { fd, len, offset64, mode } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_2.addr = len as _;
sqe.len = mode as _;
sqe.__bindgen_anon_1.off = offset64 as _;
Entry(sqe)
}
);
impl Fallocate64 {
#[inline]
pub const fn offset(self, offset: libc::off_t) -> Self {
self.offset64(offset as libc::off64_t)
}
}
opcode!(
pub struct OpenAt {
dirfd: { impl sealed::UseFd },
pathname: { *const libc::c_char },
;;
file_index: Option<types::DestinationSlot> = None,
flags: i32 = 0,
mode: libc::mode_t = 0
}
pub const CODE = sys::IORING_OP_OPENAT;
pub fn build(self) -> Entry {
let OpenAt { dirfd, pathname, file_index, flags, mode } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = dirfd;
sqe.__bindgen_anon_2.addr = pathname as _;
sqe.len = mode;
sqe.__bindgen_anon_3.open_flags = flags as _;
if let Some(dest) = file_index {
sqe.__bindgen_anon_5.file_index = dest.kernel_index_arg();
}
Entry(sqe)
}
);
opcode!(
pub struct Close {
fd: { impl sealed::UseFixed },
;;
}
pub const CODE = sys::IORING_OP_CLOSE;
pub fn build(self) -> Entry {
let Close { fd } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
match fd {
sealed::Target::Fd(i) => sqe.fd = i,
sealed::Target::Fixed(i) => {
sqe.fd = 0;
sqe.__bindgen_anon_5.file_index = i+1;
}
}
Entry(sqe)
}
);
opcode!(
pub struct FilesUpdate {
fds: { *const RawFd },
len: { u32 },
;;
offset: i32 = 0
}
pub const CODE = sys::IORING_OP_FILES_UPDATE;
pub fn build(self) -> Entry {
let FilesUpdate { fds, len, offset } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = -1;
sqe.__bindgen_anon_2.addr = fds as _;
sqe.len = len;
sqe.__bindgen_anon_1.off = offset as _;
Entry(sqe)
}
);
opcode!(
pub struct Statx {
dirfd: { impl sealed::UseFd },
pathname: { *const libc::c_char },
statxbuf: { *mut types::statx },
;;
flags: i32 = 0,
mask: u32 = 0
}
pub const CODE = sys::IORING_OP_STATX;
pub fn build(self) -> Entry {
let Statx {
dirfd, pathname, statxbuf,
flags, mask
} = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = dirfd;
sqe.__bindgen_anon_2.addr = pathname as _;
sqe.len = mask;
sqe.__bindgen_anon_1.off = statxbuf as _;
sqe.__bindgen_anon_3.statx_flags = flags as _;
Entry(sqe)
}
);
opcode!(
pub struct Read {
fd: { impl sealed::UseFixed },
buf: { *mut u8 },
len: { u32 },
;;
offset64: libc::off64_t = 0,
ioprio: u16 = 0,
rw_flags: types::RwFlags = 0,
buf_group: u16 = 0
}
pub const CODE = sys::IORING_OP_READ;
pub fn build(self) -> Entry {
let Read {
fd,
buf, len, offset64,
ioprio, rw_flags,
buf_group
} = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.ioprio = ioprio;
sqe.__bindgen_anon_2.addr = buf as _;
sqe.len = len;
sqe.__bindgen_anon_1.off = offset64 as _;
sqe.__bindgen_anon_3.rw_flags = rw_flags;
sqe.__bindgen_anon_4.buf_group = buf_group;
Entry(sqe)
}
);
impl Read {
#[inline]
pub const fn offset(self, offset: libc::off_t) -> Self {
self.offset64(offset as libc::off64_t)
}
}
opcode!(
pub struct Write {
fd: { impl sealed::UseFixed },
buf: { *const u8 },
len: { u32 },
;;
offset64: libc::off64_t = 0,
ioprio: u16 = 0,
rw_flags: types::RwFlags = 0
}
pub const CODE = sys::IORING_OP_WRITE;
pub fn build(self) -> Entry {
let Write {
fd,
buf, len, offset64,
ioprio, rw_flags
} = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.ioprio = ioprio;
sqe.__bindgen_anon_2.addr = buf as _;
sqe.len = len;
sqe.__bindgen_anon_1.off = offset64 as _;
sqe.__bindgen_anon_3.rw_flags = rw_flags;
Entry(sqe)
}
);
impl Write {
#[inline]
pub const fn offset(self, offset: libc::off_t) -> Self {
self.offset64(offset as libc::off64_t)
}
}
opcode!(
pub struct Fadvise {
fd: { impl sealed::UseFixed },
len: { libc::off_t },
advice: { i32 },
;;
offset64: libc::off64_t = 0,
}
pub const CODE = sys::IORING_OP_FADVISE;
pub fn build(self) -> Entry {
let Fadvise { fd, len, advice, offset64 } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.len = len as _;
sqe.__bindgen_anon_1.off = offset64 as _;
sqe.__bindgen_anon_3.fadvise_advice = advice as _;
Entry(sqe)
}
);
impl Fadvise {
#[inline]
pub const fn offset(self, offset: libc::off_t) -> Self {
self.offset64(offset as libc::off64_t)
}
}
opcode!(
pub struct Madvise {
addr: { *const libc::c_void },
len: { libc::off_t },
advice: { i32 },
;;
}
pub const CODE = sys::IORING_OP_MADVISE;
pub fn build(self) -> Entry {
let Madvise { addr, len, advice } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = -1;
sqe.__bindgen_anon_2.addr = addr as _;
sqe.len = len as _;
sqe.__bindgen_anon_3.fadvise_advice = advice as _;
Entry(sqe)
}
);
opcode!(
pub struct Send {
fd: { impl sealed::UseFixed },
buf: { *const u8 },
len: { u32 },
;;
flags: i32 = 0
}
pub const CODE = sys::IORING_OP_SEND;
pub fn build(self) -> Entry {
let Send { fd, buf, len, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_2.addr = buf as _;
sqe.len = len;
sqe.__bindgen_anon_3.msg_flags = flags as _;
Entry(sqe)
}
);
opcode!(
pub struct Recv {
fd: { impl sealed::UseFixed },
buf: { *mut u8 },
len: { u32 },
;;
flags: i32 = 0,
buf_group: u16 = 0
}
pub const CODE = sys::IORING_OP_RECV;
pub fn build(self) -> Entry {
let Recv { fd, buf, len, flags, buf_group } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_2.addr = buf as _;
sqe.len = len;
sqe.__bindgen_anon_3.msg_flags = flags as _;
sqe.__bindgen_anon_4.buf_group = buf_group;
Entry(sqe)
}
);
opcode!(
pub struct RecvMulti {
fd: { impl sealed::UseFixed },
buf_group: { u16 },
;;
flags: i32 = 0,
}
pub const CODE = sys::IORING_OP_RECV;
pub fn build(self) -> Entry {
let RecvMulti { fd, buf_group, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_3.msg_flags = flags as _;
sqe.__bindgen_anon_4.buf_group = buf_group;
sqe.flags |= 1 << sys::IOSQE_BUFFER_SELECT_BIT;
sqe.ioprio = sys::IORING_RECV_MULTISHOT as _;
Entry(sqe)
}
);
opcode!(
pub struct OpenAt2 {
dirfd: { impl sealed::UseFd },
pathname: { *const libc::c_char },
how: { *const types::OpenHow }
;;
file_index: Option<types::DestinationSlot> = None,
}
pub const CODE = sys::IORING_OP_OPENAT2;
pub fn build(self) -> Entry {
let OpenAt2 { dirfd, pathname, how, file_index } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = dirfd;
sqe.__bindgen_anon_2.addr = pathname as _;
sqe.len = mem::size_of::<sys::open_how>() as _;
sqe.__bindgen_anon_1.off = how as _;
if let Some(dest) = file_index {
sqe.__bindgen_anon_5.file_index = dest.kernel_index_arg();
}
Entry(sqe)
}
);
opcode!(
pub struct EpollCtl {
epfd: { impl sealed::UseFixed },
fd: { impl sealed::UseFd },
op: { i32 },
ev: { *const types::epoll_event },
;;
}
pub const CODE = sys::IORING_OP_EPOLL_CTL;
pub fn build(self) -> Entry {
let EpollCtl { epfd, fd, op, ev } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = epfd);
sqe.__bindgen_anon_2.addr = ev as _;
sqe.len = op as _;
sqe.__bindgen_anon_1.off = fd as _;
Entry(sqe)
}
);
opcode!(
pub struct Splice {
fd_in: { impl sealed::UseFixed },
off_in: { i64 },
fd_out: { impl sealed::UseFixed },
off_out: { i64 },
len: { u32 },
;;
flags: u32 = 0
}
pub const CODE = sys::IORING_OP_SPLICE;
pub fn build(self) -> Entry {
let Splice { fd_in, off_in, fd_out, off_out, len, mut flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd_out);
sqe.len = len;
sqe.__bindgen_anon_1.off = off_out as _;
sqe.__bindgen_anon_5.splice_fd_in = match fd_in {
sealed::Target::Fd(fd) => fd,
sealed::Target::Fixed(i) => {
flags |= sys::SPLICE_F_FD_IN_FIXED;
i as _
}
};
sqe.__bindgen_anon_2.splice_off_in = off_in as _;
sqe.__bindgen_anon_3.splice_flags = flags;
Entry(sqe)
}
);
opcode!(
pub struct ProvideBuffers {
addr: { *mut u8 },
len: { i32 },
nbufs: { u16 },
bgid: { u16 },
bid: { u16 }
;;
}
pub const CODE = sys::IORING_OP_PROVIDE_BUFFERS;
pub fn build(self) -> Entry {
let ProvideBuffers { addr, len, nbufs, bgid, bid } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = nbufs as _;
sqe.__bindgen_anon_2.addr = addr as _;
sqe.len = len as _;
sqe.__bindgen_anon_1.off = bid as _;
sqe.__bindgen_anon_4.buf_group = bgid;
Entry(sqe)
}
);
opcode!(
pub struct RemoveBuffers {
nbufs: { u16 },
bgid: { u16 }
;;
}
pub const CODE = sys::IORING_OP_REMOVE_BUFFERS;
pub fn build(self) -> Entry {
let RemoveBuffers { nbufs, bgid } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = nbufs as _;
sqe.__bindgen_anon_4.buf_group = bgid;
Entry(sqe)
}
);
opcode!(
pub struct Tee {
fd_in: { impl sealed::UseFixed },
fd_out: { impl sealed::UseFixed },
len: { u32 }
;;
flags: u32 = 0
}
pub const CODE = sys::IORING_OP_TEE;
pub fn build(self) -> Entry {
let Tee { fd_in, fd_out, len, mut flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd_out);
sqe.len = len;
sqe.__bindgen_anon_5.splice_fd_in = match fd_in {
sealed::Target::Fd(fd) => fd,
sealed::Target::Fixed(i) => {
flags |= sys::SPLICE_F_FD_IN_FIXED;
i as _
}
};
sqe.__bindgen_anon_3.splice_flags = flags;
Entry(sqe)
}
);
opcode!(
pub struct Shutdown {
fd: { impl sealed::UseFixed },
how: { i32 },
;;
}
pub const CODE = sys::IORING_OP_SHUTDOWN;
pub fn build(self) -> Entry {
let Shutdown { fd, how } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.len = how as _;
Entry(sqe)
}
);
opcode!(
pub struct RenameAt {
olddirfd: { impl sealed::UseFd },
oldpath: { *const libc::c_char },
newdirfd: { impl sealed::UseFd },
newpath: { *const libc::c_char },
;;
flags: u32 = 0
}
pub const CODE = sys::IORING_OP_RENAMEAT;
pub fn build(self) -> Entry {
let RenameAt {
olddirfd, oldpath,
newdirfd, newpath,
flags
} = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = olddirfd;
sqe.__bindgen_anon_2.addr = oldpath as _;
sqe.len = newdirfd as _;
sqe.__bindgen_anon_1.off = newpath as _;
sqe.__bindgen_anon_3.rename_flags = flags;
Entry(sqe)
}
);
opcode!(
pub struct UnlinkAt {
dirfd: { impl sealed::UseFd },
pathname: { *const libc::c_char },
;;
flags: i32 = 0
}
pub const CODE = sys::IORING_OP_UNLINKAT;
pub fn build(self) -> Entry {
let UnlinkAt { dirfd, pathname, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = dirfd;
sqe.__bindgen_anon_2.addr = pathname as _;
sqe.__bindgen_anon_3.unlink_flags = flags as _;
Entry(sqe)
}
);
opcode!(
pub struct MkDirAt {
dirfd: { impl sealed::UseFd },
pathname: { *const libc::c_char },
;;
mode: libc::mode_t = 0
}
pub const CODE = sys::IORING_OP_MKDIRAT;
pub fn build(self) -> Entry {
let MkDirAt { dirfd, pathname, mode } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = dirfd;
sqe.__bindgen_anon_2.addr = pathname as _;
sqe.len = mode;
Entry(sqe)
}
);
opcode!(
pub struct SymlinkAt {
newdirfd: { impl sealed::UseFd },
target: { *const libc::c_char },
linkpath: { *const libc::c_char },
;;
}
pub const CODE = sys::IORING_OP_SYMLINKAT;
pub fn build(self) -> Entry {
let SymlinkAt { newdirfd, target, linkpath } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = newdirfd;
sqe.__bindgen_anon_2.addr = target as _;
sqe.__bindgen_anon_1.addr2 = linkpath as _;
Entry(sqe)
}
);
opcode!(
pub struct LinkAt {
olddirfd: { impl sealed::UseFd },
oldpath: { *const libc::c_char },
newdirfd: { impl sealed::UseFd },
newpath: { *const libc::c_char },
;;
flags: i32 = 0
}
pub const CODE = sys::IORING_OP_LINKAT;
pub fn build(self) -> Entry {
let LinkAt { olddirfd, oldpath, newdirfd, newpath, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = olddirfd as _;
sqe.__bindgen_anon_2.addr = oldpath as _;
sqe.len = newdirfd as _;
sqe.__bindgen_anon_1.addr2 = newpath as _;
sqe.__bindgen_anon_3.hardlink_flags = flags as _;
Entry(sqe)
}
);
opcode!(
pub struct MsgRingData {
ring_fd: { impl sealed::UseFd },
result: { i32 },
user_data: { u64 },
user_flags: { Option<u32> },
;;
opcode_flags: u32 = 0
}
pub const CODE = sys::IORING_OP_MSG_RING;
pub fn build(self) -> Entry {
let MsgRingData { ring_fd, result, user_data, user_flags, opcode_flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.__bindgen_anon_2.addr = sys::IORING_MSG_DATA.into();
sqe.fd = ring_fd;
sqe.len = result as u32;
sqe.__bindgen_anon_1.off = user_data;
sqe.__bindgen_anon_3.msg_ring_flags = opcode_flags;
if let Some(_flags) = user_flags {
}
Entry(sqe)
}
);
opcode!(
pub struct UringCmd16 {
fd: { impl sealed::UseFixed },
cmd_op: { u32 },
;;
cmd: [u8; 16] = [0u8; 16]
}
pub const CODE = sys::IORING_OP_URING_CMD;
pub fn build(self) -> Entry {
let UringCmd16 { fd, cmd_op, cmd } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_1.__bindgen_anon_1.cmd_op = cmd_op;
unsafe { *sqe.__bindgen_anon_6.cmd.as_mut().as_mut_ptr().cast::<[u8; 16]>() = cmd };
Entry(sqe)
}
);
opcode!(
pub struct UringCmd80 {
fd: { impl sealed::UseFixed },
cmd_op: { u32 },
;;
cmd: [u8; 80] = [0u8; 80]
}
pub const CODE = sys::IORING_OP_URING_CMD;
pub fn build(self) -> Entry128 {
let UringCmd80 { fd, cmd_op, cmd } = self;
let cmd1 = cmd[..16].try_into().unwrap();
let cmd2 = cmd[16..].try_into().unwrap();
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_1.__bindgen_anon_1.cmd_op = cmd_op;
unsafe { *sqe.__bindgen_anon_6.cmd.as_mut().as_mut_ptr().cast::<[u8; 16]>() = cmd1 };
Entry128(Entry(sqe), cmd2)
}
);
opcode!(
pub struct Socket {
domain: { i32 },
socket_type: { i32 },
protocol: { i32 },
;;
file_index: Option<types::DestinationSlot> = None,
flags: types::RwFlags = 0,
}
pub const CODE = sys::IORING_OP_SOCKET;
pub fn build(self) -> Entry {
let Socket { domain, socket_type, protocol, file_index, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.fd = domain as _;
sqe.__bindgen_anon_1.off = socket_type as _;
sqe.len = protocol as _;
sqe.__bindgen_anon_3.rw_flags = flags;
if let Some(dest) = file_index {
sqe.__bindgen_anon_5.file_index = dest.kernel_index_arg();
}
Entry(sqe)
}
);
opcode!(
pub struct MsgRingSendFd {
ring_fd: { impl sealed::UseFd },
fixed_slot_src: { types::Fixed },
dest_slot_index: { types::DestinationSlot },
result: { i32 },
user_data: { u64 },
;;
opcode_flags: u32 = 0
}
pub const CODE = sys::IORING_OP_MSG_RING;
pub fn build(self) -> Entry {
let MsgRingSendFd { ring_fd, fixed_slot_src, dest_slot_index, result, user_data, opcode_flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
sqe.__bindgen_anon_2.addr = sys::IORING_MSG_SEND_FD.into();
sqe.fd = ring_fd;
sqe.len = result as u32;
sqe.__bindgen_anon_1.off = user_data;
unsafe { sqe.__bindgen_anon_6.__bindgen_anon_1.as_mut().addr3 = fixed_slot_src.0 as u64 };
sqe.__bindgen_anon_5.file_index = dest_slot_index.kernel_index_arg();
sqe.__bindgen_anon_3.msg_ring_flags = opcode_flags;
Entry(sqe)
}
);
opcode!(
pub struct SendZc {
fd: { impl sealed::UseFixed },
buf: { *const u8 },
len: { u32 },
;;
buf_index: Option<u16> = None,
flags: i32 = 0,
zc_flags: u16 = 0,
}
pub const CODE = sys::IORING_OP_SEND_ZC;
pub fn build(self) -> Entry {
let SendZc { fd, buf, len, buf_index, flags, zc_flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.__bindgen_anon_2.addr = buf as _;
sqe.len = len;
sqe.__bindgen_anon_3.msg_flags = flags as _;
sqe.ioprio = zc_flags;
if let Some(buf_index) = buf_index {
sqe.__bindgen_anon_4.buf_index = buf_index;
sqe.ioprio |= sys::IORING_RECVSEND_FIXED_BUF as u16;
}
Entry(sqe)
}
);
opcode!(
#[derive(Debug)]
pub struct SendMsgZc {
fd: { impl sealed::UseFixed },
msg: { *const libc::msghdr },
;;
ioprio: u16 = 0,
flags: u32 = 0
}
pub const CODE = sys::IORING_OP_SENDMSG_ZC;
pub fn build(self) -> Entry {
let SendMsgZc { fd, msg, ioprio, flags } = self;
let mut sqe = sqe_zeroed();
sqe.opcode = Self::CODE;
assign_fd!(sqe.fd = fd);
sqe.ioprio = ioprio;
sqe.__bindgen_anon_2.addr = msg as _;
sqe.len = 1;
sqe.__bindgen_anon_3.msg_flags = flags;
Entry(sqe)
}
);