Skip to main content

io_uring/
opcode.rs

1//! Operation codes that can be used to construct [`squeue::Entry`](crate::squeue::Entry)s.
2
3#![allow(clippy::new_without_default)]
4
5use std::convert::TryInto;
6use std::mem;
7use std::os::unix::io::RawFd;
8
9use crate::squeue::Entry;
10use crate::squeue::Entry128;
11use crate::sys;
12use crate::types::{self, sealed};
13
14macro_rules! assign_fd {
15    ( $sqe:ident . fd = $opfd:expr ) => {
16        match $opfd {
17            sealed::Target::Fd(fd) => $sqe.fd = fd,
18            sealed::Target::Fixed(idx) => {
19                $sqe.fd = idx as _;
20                $sqe.flags |= crate::squeue::Flags::FIXED_FILE.bits();
21            }
22        }
23    };
24}
25
26macro_rules! opcode {
27    (@type impl sealed::UseFixed ) => {
28        sealed::Target
29    };
30    (@type impl sealed::UseFd ) => {
31        RawFd
32    };
33    (@type $name:ty ) => {
34        $name
35    };
36    (
37        $( #[$outer:meta] )*
38        pub struct $name:ident {
39            $( #[$new_meta:meta] )*
40
41            $( $field:ident : { $( $tnt:tt )+ } ),*
42
43            $(,)?
44
45            ;;
46
47            $(
48                $( #[$opt_meta:meta] )*
49                $opt_field:ident : $opt_tname:ty = $default:expr
50            ),*
51
52            $(,)?
53        }
54
55        pub const CODE = $opcode:expr;
56
57        $( #[$build_meta:meta] )*
58        pub fn build($self:ident) -> $entry:ty $build_block:block
59    ) => {
60        $( #[$outer] )*
61        pub struct $name {
62            $( $field : opcode!(@type $( $tnt )*), )*
63            $( $opt_field : $opt_tname, )*
64        }
65
66        impl $name {
67            $( #[$new_meta] )*
68            #[inline]
69            pub fn new($( $field : $( $tnt )* ),*) -> Self {
70                $name {
71                    $( $field: $field.into(), )*
72                    $( $opt_field: $default, )*
73                }
74            }
75
76            /// The opcode of the operation. This can be passed to
77            /// [`Probe::is_supported`](crate::Probe::is_supported) to check if this operation is
78            /// supported with the current kernel.
79            pub const CODE: u8 = $opcode as _;
80
81            $(
82                $( #[$opt_meta] )*
83                #[inline]
84                pub const fn $opt_field(mut self, $opt_field: $opt_tname) -> Self {
85                    self.$opt_field = $opt_field;
86                    self
87                }
88            )*
89
90            $( #[$build_meta] )*
91            #[inline]
92            pub fn build($self) -> $entry $build_block
93        }
94    }
95}
96
97/// inline zeroed to improve codegen
98#[inline(always)]
99fn sqe_zeroed() -> sys::io_uring_sqe {
100    unsafe { mem::zeroed() }
101}
102
103opcode! {
104    /// Do not perform any I/O.
105    ///
106    /// This is useful for testing the performance of the io_uring implementation itself.
107    #[derive(Debug)]
108    pub struct Nop { ;; }
109
110    pub const CODE = sys::IORING_OP_NOP;
111
112    pub fn build(self) -> Entry {
113        let Nop {} = self;
114
115        let mut sqe = sqe_zeroed();
116        sqe.opcode = Self::CODE;
117        sqe.fd = -1;
118        Entry(sqe)
119    }
120}
121
122opcode! {
123    /// Vectored read, equivalent to `preadv2(2)`.
124    #[derive(Debug)]
125    pub struct Readv {
126        fd: { impl sealed::UseFixed },
127        iovec: { *const libc::iovec },
128        len: { u32 },
129        ;;
130        ioprio: u16 = 0,
131        offset: u64 = 0,
132        /// specified for read operations, contains a bitwise OR of per-I/O flags,
133        /// as described in the `preadv2(2)` man page.
134        rw_flags: i32 = 0,
135        buf_group: u16 = 0
136    }
137
138    pub const CODE = sys::IORING_OP_READV;
139
140    pub fn build(self) -> Entry {
141        let Readv {
142            fd,
143            iovec, len, offset,
144            ioprio, rw_flags,
145            buf_group
146        } = self;
147
148        let mut sqe = sqe_zeroed();
149        sqe.opcode = Self::CODE;
150        assign_fd!(sqe.fd = fd);
151        sqe.ioprio = ioprio;
152        sqe.__bindgen_anon_2.addr = iovec as _;
153        sqe.len = len;
154        sqe.__bindgen_anon_1.off = offset;
155        sqe.__bindgen_anon_3.rw_flags = rw_flags as _;
156        sqe.__bindgen_anon_4.buf_group = buf_group;
157        Entry(sqe)
158    }
159}
160
161opcode! {
162    /// Vectored write, equivalent to `pwritev2(2)`.
163    #[derive(Debug)]
164    pub struct Writev {
165        fd: { impl sealed::UseFixed },
166        iovec: { *const libc::iovec },
167        len: { u32 },
168        ;;
169        ioprio: u16 = 0,
170        offset: u64 = 0,
171        /// specified for write operations, contains a bitwise OR of per-I/O flags,
172        /// as described in the `preadv2(2)` man page.
173        rw_flags: i32 = 0,
174        /// Write stream id (Linux 6.16+); `0` means no stream.
175        /// Older kernels ignore this field.
176        write_stream: u8 = 0
177    }
178
179    pub const CODE = sys::IORING_OP_WRITEV;
180
181    pub fn build(self) -> Entry {
182        let Writev {
183            fd,
184            iovec, len, offset,
185            ioprio, rw_flags,
186            write_stream
187        } = self;
188
189        let mut sqe = sqe_zeroed();
190        sqe.opcode = Self::CODE;
191        assign_fd!(sqe.fd = fd);
192        sqe.ioprio = ioprio;
193        sqe.__bindgen_anon_2.addr = iovec as _;
194        sqe.len = len;
195        sqe.__bindgen_anon_1.off = offset;
196        sqe.__bindgen_anon_3.rw_flags = rw_flags as _;
197        sqe.__bindgen_anon_5.__bindgen_anon_2.write_stream = write_stream;
198        Entry(sqe)
199    }
200}
201
202opcode! {
203    /// File sync. See also `fsync(2)`.
204    ///
205    /// Optionally [`offset`](Self::offset) and [`len`](Self::len) can be used to specify a range
206    /// within the file to be synced rather than syncing the entire file, which is the default
207    /// behavior.
208    ///
209    /// Note that, while I/O is initiated in the order in which it appears in the submission queue,
210    /// completions are unordered. For example, an application which places a write I/O followed by
211    /// an fsync in the submission queue cannot expect the fsync to apply to the write. The two
212    /// operations execute in parallel, so the fsync may complete before the write is issued to the
213    /// storage. The same is also true for previously issued writes that have not completed prior to
214    /// the fsync. To enforce ordering one may utilize linked SQEs, `IOSQE_IO_DRAIN` or wait for the
215    /// arrival of CQEs of requests which have to be ordered before a given request before
216    /// submitting its SQE.
217    #[derive(Debug)]
218    pub struct Fsync {
219        fd: { impl sealed::UseFixed },
220        ;;
221        /// Offset within the file to start the sync range. Together with [`len`](Self::len), this
222        /// selects a byte range; when both are zero (the default), the entire file is synced.
223        offset: u64 = 0,
224        /// Length of the range to sync, in bytes. When zero (the default) with
225        /// [`offset`](Self::offset) also zero, the entire file is synced.
226        len: u32 = 0,
227        /// The `flags` bit mask may contain either 0, for a normal file integrity sync,
228        /// or [types::FsyncFlags::DATASYNC] to provide data sync only semantics.
229        /// See the descriptions of `O_SYNC` and `O_DSYNC` in the `open(2)` manual page for more information.
230        flags: types::FsyncFlags = types::FsyncFlags::empty()
231    }
232
233    pub const CODE = sys::IORING_OP_FSYNC;
234
235    pub fn build(self) -> Entry {
236        let Fsync {
237            fd,
238            offset,
239            len,
240            flags,
241        } = self;
242
243        let mut sqe = sqe_zeroed();
244        sqe.opcode = Self::CODE;
245        assign_fd!(sqe.fd = fd);
246        sqe.len = len;
247        sqe.__bindgen_anon_1.off = offset;
248        sqe.__bindgen_anon_3.fsync_flags = flags.bits();
249        Entry(sqe)
250    }
251}
252
253opcode! {
254    /// Read from a file into a fixed buffer that has been previously registered with
255    /// [`Submitter::register_buffers`](crate::Submitter::register_buffers).
256    ///
257    /// The return values match those documented in the `preadv2(2)` man pages.
258    #[derive(Debug)]
259    pub struct ReadFixed {
260        fd: { impl sealed::UseFixed },
261        buf: { *mut u8 },
262        len: { u32 },
263        buf_index: { u16 },
264        ;;
265        ioprio: u16 = 0,
266        /// The offset of the file to read from.
267        offset: u64 = 0,
268        /// Specified for read operations, contains a bitwise OR of per-I/O flags, as described in
269        /// the `preadv2(2)` man page.
270        rw_flags: i32 = 0
271    }
272
273    pub const CODE = sys::IORING_OP_READ_FIXED;
274
275    pub fn build(self) -> Entry {
276        let ReadFixed {
277            fd,
278            buf, len, offset,
279            buf_index,
280            ioprio, rw_flags
281        } = self;
282
283        let mut sqe = sqe_zeroed();
284        sqe.opcode = Self::CODE;
285        assign_fd!(sqe.fd = fd);
286        sqe.ioprio = ioprio;
287        sqe.__bindgen_anon_2.addr = buf as _;
288        sqe.len = len;
289        sqe.__bindgen_anon_1.off = offset;
290        sqe.__bindgen_anon_3.rw_flags = rw_flags as _;
291        sqe.__bindgen_anon_4.buf_index = buf_index;
292        Entry(sqe)
293    }
294}
295
296opcode! {
297    /// Write to a file from a fixed buffer that have been previously registered with
298    /// [`Submitter::register_buffers`](crate::Submitter::register_buffers).
299    ///
300    /// The return values match those documented in the `pwritev2(2)` man pages.
301    #[derive(Debug)]
302    pub struct WriteFixed {
303        fd: { impl sealed::UseFixed },
304        buf: { *const u8 },
305        len: { u32 },
306        buf_index: { u16 },
307        ;;
308        ioprio: u16 = 0,
309        /// The offset of the file to write to.
310        offset: u64 = 0,
311        /// Specified for write operations, contains a bitwise OR of per-I/O flags, as described in
312        /// the `pwritev2(2)` man page.
313        rw_flags: i32 = 0,
314        /// Write stream id (Linux 6.16+); `0` means no stream.
315        /// Older kernels ignore this field.
316        write_stream: u8 = 0
317    }
318
319    pub const CODE = sys::IORING_OP_WRITE_FIXED;
320
321    pub fn build(self) -> Entry {
322        let WriteFixed {
323            fd,
324            buf, len, offset,
325            buf_index,
326            ioprio, rw_flags,
327            write_stream
328        } = self;
329
330        let mut sqe = sqe_zeroed();
331        sqe.opcode = Self::CODE;
332        assign_fd!(sqe.fd = fd);
333        sqe.ioprio = ioprio;
334        sqe.__bindgen_anon_2.addr = buf as _;
335        sqe.len = len;
336        sqe.__bindgen_anon_1.off = offset;
337        sqe.__bindgen_anon_3.rw_flags = rw_flags as _;
338        sqe.__bindgen_anon_5.__bindgen_anon_2.write_stream = write_stream;
339        sqe.__bindgen_anon_4.buf_index = buf_index;
340        Entry(sqe)
341    }
342}
343
344opcode! {
345    /// Poll the specified fd.
346    ///
347    /// Unlike poll or epoll without `EPOLLONESHOT`, this interface defaults to work in one shot mode.
348    /// That is, once the poll operation is completed, it will have to be resubmitted.
349    ///
350    /// If multi is set, the poll will work in multi shot mode instead. That means it will
351    /// repeatedly trigger when the requested event becomes true, and hence multiple CQEs can be
352    /// generated from this single submission. The CQE flags field will have IORING_CQE_F_MORE set
353    /// on completion if the application should expect further CQE entries from the original
354    /// request. If this flag isn't set on completion, then the poll request has been terminated
355    /// and no further events will be generated. This mode is available since 5.13.
356    #[derive(Debug)]
357    pub struct PollAdd {
358        /// The bits that may be set in `flags` are defined in `<poll.h>`,
359        /// and documented in `poll(2)`.
360        fd: { impl sealed::UseFixed },
361        flags: { u32 },
362        ;;
363        multi: bool = false
364    }
365
366    pub const CODE = sys::IORING_OP_POLL_ADD;
367
368    pub fn build(self) -> Entry {
369        let PollAdd { fd, flags, multi } = self;
370
371        let mut sqe = sqe_zeroed();
372        sqe.opcode = Self::CODE;
373        assign_fd!(sqe.fd = fd);
374        if multi {
375            sqe.len = sys::IORING_POLL_ADD_MULTI;
376        }
377
378        #[cfg(target_endian = "little")] {
379            sqe.__bindgen_anon_3.poll32_events = flags;
380        }
381
382        #[cfg(target_endian = "big")] {
383            let x = flags << 16;
384            let y = flags >> 16;
385            let flags = x | y;
386            sqe.__bindgen_anon_3.poll32_events = flags;
387        }
388
389        Entry(sqe)
390    }
391}
392
393opcode! {
394    /// Remove an existing [poll](PollAdd) request.
395    ///
396    /// If found, the `result` method of the `cqueue::Entry` will return 0.
397    /// If not found, `result` will return `-libc::ENOENT`.
398    #[derive(Debug)]
399    pub struct PollRemove {
400        user_data: { u64 }
401        ;;
402    }
403
404    pub const CODE = sys::IORING_OP_POLL_REMOVE;
405
406    pub fn build(self) -> Entry {
407        let PollRemove { user_data } = self;
408
409        let mut sqe = sqe_zeroed();
410        sqe.opcode = Self::CODE;
411        sqe.fd = -1;
412        sqe.__bindgen_anon_2.addr = user_data;
413        Entry(sqe)
414    }
415}
416
417opcode! {
418    /// Sync a file segment with disk, equivalent to `sync_file_range(2)`.
419    #[derive(Debug)]
420    pub struct SyncFileRange {
421        fd: { impl sealed::UseFixed },
422        len: { u32 },
423        ;;
424        /// the offset method holds the offset in bytes
425        offset: u64 = 0,
426        /// the flags method holds the flags for the command
427        flags: u32 = 0
428    }
429
430    pub const CODE = sys::IORING_OP_SYNC_FILE_RANGE;
431
432    pub fn build(self) -> Entry {
433        let SyncFileRange {
434            fd,
435            len, offset,
436            flags
437        } = self;
438
439        let mut sqe = sqe_zeroed();
440        sqe.opcode = Self::CODE;
441        assign_fd!(sqe.fd = fd);
442        sqe.len = len;
443        sqe.__bindgen_anon_1.off = offset;
444        sqe.__bindgen_anon_3.sync_range_flags = flags;
445        Entry(sqe)
446    }
447}
448
449opcode! {
450    /// Send a message on a socket, equivalent to `send(2)`.
451    ///
452    /// fd must be set to the socket file descriptor, addr must contains a pointer to the msghdr
453    /// structure, and flags holds the flags associated with the system call.
454    #[derive(Debug)]
455    pub struct SendMsg {
456        fd: { impl sealed::UseFixed },
457        msg: { *const libc::msghdr },
458        ;;
459        ioprio: u16 = 0,
460        flags: u32 = 0
461    }
462
463    pub const CODE = sys::IORING_OP_SENDMSG;
464
465    pub fn build(self) -> Entry {
466        let SendMsg { fd, msg, ioprio, flags } = self;
467
468        let mut sqe = sqe_zeroed();
469        sqe.opcode = Self::CODE;
470        assign_fd!(sqe.fd = fd);
471        sqe.ioprio = ioprio;
472        sqe.__bindgen_anon_2.addr = msg as _;
473        sqe.len = 1;
474        sqe.__bindgen_anon_3.msg_flags = flags;
475        Entry(sqe)
476    }
477}
478
479opcode! {
480    /// Receive a message on a socket, equivalent to `recvmsg(2)`.
481    ///
482    /// See also the description of [`SendMsg`].
483    #[derive(Debug)]
484    pub struct RecvMsg {
485        fd: { impl sealed::UseFixed },
486        msg: { *mut libc::msghdr },
487        ;;
488        ioprio: u16 = 0,
489        flags: u32 = 0,
490        buf_group: u16 = 0
491    }
492
493    pub const CODE = sys::IORING_OP_RECVMSG;
494
495    pub fn build(self) -> Entry {
496        let RecvMsg { fd, msg, ioprio, flags, buf_group } = self;
497
498        let mut sqe = sqe_zeroed();
499        sqe.opcode = Self::CODE;
500        assign_fd!(sqe.fd = fd);
501        sqe.ioprio = ioprio;
502        sqe.__bindgen_anon_2.addr = msg as _;
503        sqe.len = 1;
504        sqe.__bindgen_anon_3.msg_flags = flags;
505        sqe.__bindgen_anon_4.buf_group = buf_group;
506        Entry(sqe)
507    }
508}
509
510opcode! {
511    /// Receive multiple messages on a socket, equivalent to `recvmsg(2)`.
512    ///
513    /// Parameters:
514    ///     msg:       For this multishot variant of ResvMsg, only the msg_namelen and msg_controllen
515    ///                fields are relevant.
516    ///     buf_group: The id of the provided buffer pool to use for each received message.
517    ///
518    /// See also the description of [`SendMsg`] and [`types::RecvMsgOut`].
519    ///
520    /// The multishot version allows the application to issue a single receive request, which
521    /// repeatedly posts a CQE when data is available. It requires the MSG_WAITALL flag is not set.
522    /// Each CQE will take a buffer out of a provided buffer pool for receiving. The application
523    /// should check the flags of each CQE, regardless of its result. If a posted CQE does not have
524    /// the IORING_CQE_F_MORE flag set then the multishot receive will be done and the application
525    /// should issue a new request.
526    ///
527    /// Unlike [`RecvMsg`], this multishot recvmsg will prepend a struct which describes the layout
528    /// of the rest of the buffer in combination with the initial msghdr structure submitted with
529    /// the request. Use [`types::RecvMsgOut`] to parse the data received and access its
530    /// components.
531    ///
532    /// The recvmsg multishot variant is available since kernel 6.0.
533    #[derive(Debug)]
534    pub struct RecvMsgMulti {
535        fd: { impl sealed::UseFixed },
536        msg: { *const libc::msghdr },
537        buf_group: { u16 },
538        ;;
539        ioprio: u16 = 0,
540        flags: u32 = 0
541    }
542
543    pub const CODE = sys::IORING_OP_RECVMSG;
544
545    pub fn build(self) -> Entry {
546        let RecvMsgMulti { fd, msg, buf_group, ioprio, flags } = self;
547
548        let mut sqe = sqe_zeroed();
549        sqe.opcode = Self::CODE;
550        assign_fd!(sqe.fd = fd);
551        sqe.__bindgen_anon_2.addr = msg as _;
552        sqe.len = 1;
553        sqe.__bindgen_anon_3.msg_flags = flags;
554        sqe.__bindgen_anon_4.buf_group = buf_group;
555        sqe.flags |= crate::squeue::Flags::BUFFER_SELECT.bits();
556        sqe.ioprio = ioprio | (sys::IORING_RECV_MULTISHOT as u16);
557        Entry(sqe)
558    }
559}
560
561opcode! {
562    /// Register a timeout operation.
563    ///
564    /// A timeout will trigger a wakeup event on the completion ring for anyone waiting for events.
565    /// A timeout condition is met when either the specified timeout expires, or the specified number of events have completed.
566    /// Either condition will trigger the event.
567    /// The request will complete with `-ETIME` if the timeout got completed through expiration of the timer,
568    /// or 0 if the timeout got completed through requests completing on their own.
569    /// If the timeout was cancelled before it expired, the request will complete with `-ECANCELED`.
570    #[derive(Debug)]
571    pub struct Timeout {
572        timespec: { *const types::Timespec },
573        ;;
574        /// `count` may contain a completion event count.
575        /// If [`TimeoutFlags::MULTISHOT`](types::TimeoutFlags::MULTISHOT) is set in `flags`, this is the number of repeats.
576        /// A value of 0 means the timeout is indefinite and can only be stopped by a removal request.
577        count: u32 = 0,
578
579        flags: types::TimeoutFlags = types::TimeoutFlags::empty()
580    }
581
582    pub const CODE = sys::IORING_OP_TIMEOUT;
583
584    pub fn build(self) -> Entry {
585        let Timeout { timespec, count, flags } = self;
586
587        let mut sqe = sqe_zeroed();
588        sqe.opcode = Self::CODE;
589        sqe.fd = -1;
590        sqe.__bindgen_anon_2.addr = timespec as _;
591        sqe.len = 1;
592        sqe.__bindgen_anon_1.off = count as _;
593        sqe.__bindgen_anon_3.timeout_flags = flags.bits();
594        Entry(sqe)
595    }
596}
597
598// === 5.5 ===
599
600opcode! {
601    /// Attempt to remove an existing [timeout operation](Timeout).
602    pub struct TimeoutRemove {
603        user_data: { u64 },
604        ;;
605    }
606
607    pub const CODE = sys::IORING_OP_TIMEOUT_REMOVE;
608
609    pub fn build(self) -> Entry {
610        let TimeoutRemove { user_data } = self;
611
612        let mut sqe = sqe_zeroed();
613        sqe.opcode = Self::CODE;
614        sqe.fd = -1;
615        sqe.__bindgen_anon_2.addr = user_data;
616        Entry(sqe)
617    }
618}
619
620opcode! {
621    /// Attempt to update an existing [timeout operation](Timeout) with a new timespec.
622    /// The optional `count` value of the original timeout value cannot be updated.
623    pub struct TimeoutUpdate {
624        user_data: { u64 },
625        timespec: { *const types::Timespec },
626        ;;
627        flags: types::TimeoutFlags = types::TimeoutFlags::empty()
628    }
629
630    pub const CODE = sys::IORING_OP_TIMEOUT_REMOVE;
631
632    pub fn build(self) -> Entry {
633        let TimeoutUpdate { user_data, timespec, flags } = self;
634
635        let mut sqe = sqe_zeroed();
636        sqe.opcode = Self::CODE;
637        sqe.fd = -1;
638        sqe.__bindgen_anon_1.off = timespec as _;
639        sqe.__bindgen_anon_2.addr = user_data;
640        sqe.__bindgen_anon_3.timeout_flags = flags.bits() | sys::IORING_TIMEOUT_UPDATE;
641        Entry(sqe)
642    }
643}
644
645opcode! {
646    /// Accept a new connection on a socket, equivalent to `accept4(2)`.
647    pub struct Accept {
648        fd: { impl sealed::UseFixed },
649        addr: { *mut libc::sockaddr },
650        addrlen: { *mut libc::socklen_t },
651        ;;
652        file_index: Option<types::DestinationSlot> = None,
653        flags: i32 = 0
654    }
655
656    pub const CODE = sys::IORING_OP_ACCEPT;
657
658    pub fn build(self) -> Entry {
659        let Accept { fd, addr, addrlen, file_index, flags } = self;
660
661        let mut sqe = sqe_zeroed();
662        sqe.opcode = Self::CODE;
663        assign_fd!(sqe.fd = fd);
664        sqe.__bindgen_anon_2.addr = addr as _;
665        sqe.__bindgen_anon_1.addr2 = addrlen as _;
666        sqe.__bindgen_anon_3.accept_flags = flags as _;
667        if let Some(dest) = file_index {
668            sqe.__bindgen_anon_5.file_index = dest.kernel_index_arg();
669        }
670        Entry(sqe)
671    }
672}
673
674opcode! {
675    /// Set a socket option.
676    pub struct SetSockOpt {
677        fd: { impl sealed::UseFixed },
678        level: { u32 },
679        optname: { u32 },
680        optval: { *const libc::c_void },
681        optlen: { u32 },
682        ;;
683        flags: u32 = 0
684    }
685
686    pub const CODE = sys::IORING_OP_URING_CMD;
687
688    pub fn build(self) -> Entry {
689        let SetSockOpt { fd, level, optname, optval, optlen, flags } = self;
690        let mut sqe = sqe_zeroed();
691        sqe.opcode = Self::CODE;
692        assign_fd!(sqe.fd = fd);
693        sqe.__bindgen_anon_1.__bindgen_anon_1.cmd_op = sys::SOCKET_URING_OP_SETSOCKOPT;
694
695        sqe.__bindgen_anon_2.__bindgen_anon_1.level = level;
696        sqe.__bindgen_anon_2.__bindgen_anon_1.optname = optname;
697        sqe.__bindgen_anon_3.uring_cmd_flags = flags;
698        sqe.__bindgen_anon_5.optlen = optlen;
699        unsafe { *sqe.__bindgen_anon_6.optval.as_mut() = optval as u64 };
700        Entry(sqe)
701    }
702}
703
704opcode! {
705    /// Get a socket option, equivalent to `getsockopt(2)`.
706    ///
707    /// The value is written to `optval`, which has room for `optlen` bytes; on success the
708    /// completion's result is the value's length. The kernel only supports level `SOL_SOCKET`
709    /// (other levels fail with `EOPNOTSUPP`). Available since kernel 6.7.
710    pub struct GetSockOpt {
711        fd: { impl sealed::UseFixed },
712        level: { u32 },
713        optname: { u32 },
714        optval: { *mut libc::c_void },
715        optlen: { u32 },
716        ;;
717        flags: u32 = 0
718    }
719
720    pub const CODE = sys::IORING_OP_URING_CMD;
721
722    pub fn build(self) -> Entry {
723        let GetSockOpt { fd, level, optname, optval, optlen, flags } = self;
724        let mut sqe = sqe_zeroed();
725        sqe.opcode = Self::CODE;
726        assign_fd!(sqe.fd = fd);
727        sqe.__bindgen_anon_1.__bindgen_anon_1.cmd_op = sys::SOCKET_URING_OP_GETSOCKOPT;
728
729        sqe.__bindgen_anon_2.__bindgen_anon_1.level = level;
730        sqe.__bindgen_anon_2.__bindgen_anon_1.optname = optname;
731        sqe.__bindgen_anon_3.uring_cmd_flags = flags;
732        sqe.__bindgen_anon_5.optlen = optlen;
733        unsafe { *sqe.__bindgen_anon_6.optval.as_mut() = optval as u64 };
734        Entry(sqe)
735    }
736}
737
738opcode! {
739    /// Attempt to cancel an already issued request.
740    pub struct AsyncCancel {
741        user_data: { u64 }
742        ;;
743
744        // TODO flags
745    }
746
747    pub const CODE = sys::IORING_OP_ASYNC_CANCEL;
748
749    pub fn build(self) -> Entry {
750        let AsyncCancel { user_data } = self;
751
752        let mut sqe = sqe_zeroed();
753        sqe.opcode = Self::CODE;
754        sqe.fd = -1;
755        sqe.__bindgen_anon_2.addr = user_data;
756        Entry(sqe)
757    }
758}
759
760opcode! {
761    /// This request must be linked with another request through
762    /// [`Flags::IO_LINK`](crate::squeue::Flags::IO_LINK) which is described below.
763    /// Unlike [`Timeout`], [`LinkTimeout`] acts on the linked request, not the completion queue.
764    pub struct LinkTimeout {
765        timespec: { *const types::Timespec },
766        ;;
767        flags: types::TimeoutFlags = types::TimeoutFlags::empty()
768    }
769
770    pub const CODE = sys::IORING_OP_LINK_TIMEOUT;
771
772    pub fn build(self) -> Entry {
773        let LinkTimeout { timespec, flags } = self;
774
775        let mut sqe = sqe_zeroed();
776        sqe.opcode = Self::CODE;
777        sqe.fd = -1;
778        sqe.__bindgen_anon_2.addr = timespec as _;
779        sqe.len = 1;
780        sqe.__bindgen_anon_3.timeout_flags = flags.bits();
781        Entry(sqe)
782    }
783}
784
785opcode! {
786    /// Connect a socket, equivalent to `connect(2)`.
787    pub struct Connect {
788        fd: { impl sealed::UseFixed },
789        addr: { *const libc::sockaddr },
790        addrlen: { libc::socklen_t }
791        ;;
792    }
793
794    pub const CODE = sys::IORING_OP_CONNECT;
795
796    pub fn build(self) -> Entry {
797        let Connect { fd, addr, addrlen } = self;
798
799        let mut sqe = sqe_zeroed();
800        sqe.opcode = Self::CODE;
801        assign_fd!(sqe.fd = fd);
802        sqe.__bindgen_anon_2.addr = addr as _;
803        sqe.__bindgen_anon_1.off = addrlen as _;
804        Entry(sqe)
805    }
806}
807
808// === 5.6 ===
809
810opcode! {
811    /// Preallocate or deallocate space to a file, equivalent to `fallocate(2)`.
812    pub struct Fallocate {
813        fd: { impl sealed::UseFixed },
814        len: { u64 },
815        ;;
816        offset: u64 = 0,
817        mode: i32 = 0
818    }
819
820    pub const CODE = sys::IORING_OP_FALLOCATE;
821
822    pub fn build(self) -> Entry {
823        let Fallocate { fd, len, offset, mode } = self;
824
825        let mut sqe = sqe_zeroed();
826        sqe.opcode = Self::CODE;
827        assign_fd!(sqe.fd = fd);
828        sqe.__bindgen_anon_2.addr = len;
829        sqe.len = mode as _;
830        sqe.__bindgen_anon_1.off = offset;
831        Entry(sqe)
832    }
833}
834
835opcode! {
836    /// Open a file, equivalent to `openat(2)`.
837    pub struct OpenAt {
838        dirfd: { impl sealed::UseFd },
839        pathname: { *const libc::c_char },
840        ;;
841        file_index: Option<types::DestinationSlot> = None,
842        flags: i32 = 0,
843        mode: libc::mode_t = 0
844    }
845
846    pub const CODE = sys::IORING_OP_OPENAT;
847
848    pub fn build(self) -> Entry {
849        let OpenAt { dirfd, pathname, file_index, flags, mode } = self;
850
851        let mut sqe = sqe_zeroed();
852        sqe.opcode = Self::CODE;
853        sqe.fd = dirfd;
854        sqe.__bindgen_anon_2.addr = pathname as _;
855        sqe.len = mode;
856        sqe.__bindgen_anon_3.open_flags = flags as _;
857        if let Some(dest) = file_index {
858            sqe.__bindgen_anon_5.file_index = dest.kernel_index_arg();
859        }
860        Entry(sqe)
861    }
862}
863
864opcode! {
865    /// Close a file descriptor, equivalent to `close(2)`.
866    ///
867    /// Use a types::Fixed(fd) argument to close an io_uring direct descriptor.
868    pub struct Close {
869        fd: { impl sealed::UseFixed },
870        ;;
871    }
872
873    pub const CODE = sys::IORING_OP_CLOSE;
874
875    pub fn build(self) -> Entry {
876        let Close { fd } = self;
877
878        let mut sqe = sqe_zeroed();
879        sqe.opcode = Self::CODE;
880        match fd {
881            sealed::Target::Fd(fd) => sqe.fd = fd,
882            sealed::Target::Fixed(idx) => {
883                sqe.fd = 0;
884                sqe.__bindgen_anon_5.file_index = idx + 1;
885            }
886        }
887        Entry(sqe)
888    }
889}
890
891opcode! {
892    /// This command is an alternative to using
893    /// [`Submitter::register_files_update`](crate::Submitter::register_files_update) which then
894    /// works in an async fashion, like the rest of the io_uring commands.
895    pub struct FilesUpdate {
896        fds: { *const RawFd },
897        len: { u32 },
898        ;;
899        offset: i32 = 0
900    }
901
902    pub const CODE = sys::IORING_OP_FILES_UPDATE;
903
904    pub fn build(self) -> Entry {
905        let FilesUpdate { fds, len, offset } = self;
906
907        let mut sqe = sqe_zeroed();
908        sqe.opcode = Self::CODE;
909        sqe.fd = -1;
910        sqe.__bindgen_anon_2.addr = fds as _;
911        sqe.len = len;
912        sqe.__bindgen_anon_1.off = offset as _;
913        Entry(sqe)
914    }
915}
916
917opcode! {
918    /// Get file status, equivalent to `statx(2)`.
919    pub struct Statx {
920        dirfd: { impl sealed::UseFd },
921        pathname: { *const libc::c_char },
922        statxbuf: { *mut types::statx },
923        ;;
924        flags: i32 = 0,
925        mask: u32 = 0
926    }
927
928    pub const CODE = sys::IORING_OP_STATX;
929
930    pub fn build(self) -> Entry {
931        let Statx {
932            dirfd, pathname, statxbuf,
933            flags, mask
934        } = self;
935
936        let mut sqe = sqe_zeroed();
937        sqe.opcode = Self::CODE;
938        sqe.fd = dirfd;
939        sqe.__bindgen_anon_2.addr = pathname as _;
940        sqe.len = mask;
941        sqe.__bindgen_anon_1.off = statxbuf as _;
942        sqe.__bindgen_anon_3.statx_flags = flags as _;
943        Entry(sqe)
944    }
945}
946
947opcode! {
948    /// Issue the equivalent of a `pread(2)` or `pwrite(2)` system call
949    ///
950    /// * `fd` is the file descriptor to be operated on,
951    /// * `addr` contains the buffer in question,
952    /// * `len` contains the length of the IO operation,
953    ///
954    /// These are non-vectored versions of the `IORING_OP_READV` and `IORING_OP_WRITEV` opcodes.
955    /// See also `read(2)` and `write(2)` for the general description of the related system call.
956    ///
957    /// Available since 5.6.
958    pub struct Read {
959        fd: { impl sealed::UseFixed },
960        buf: { *mut u8 },
961        len: { u32 },
962        ;;
963        /// `offset` contains the read or write offset.
964        ///
965        /// If `fd` does not refer to a seekable file, `offset` must be set to zero.
966        /// If `offset` is set to `-1`, the offset will use (and advance) the file position,
967        /// like the `read(2)` and `write(2)` system calls.
968        offset: u64 = 0,
969        ioprio: u16 = 0,
970        rw_flags: i32 = 0,
971        buf_group: u16 = 0
972    }
973
974    pub const CODE = sys::IORING_OP_READ;
975
976    pub fn build(self) -> Entry {
977        let Read {
978            fd,
979            buf, len, offset,
980            ioprio, rw_flags,
981            buf_group
982        } = self;
983
984        let mut sqe = sqe_zeroed();
985        sqe.opcode = Self::CODE;
986        assign_fd!(sqe.fd = fd);
987        sqe.ioprio = ioprio;
988        sqe.__bindgen_anon_2.addr = buf as _;
989        sqe.len = len;
990        sqe.__bindgen_anon_1.off = offset;
991        sqe.__bindgen_anon_3.rw_flags = rw_flags as _;
992        sqe.__bindgen_anon_4.buf_group = buf_group;
993        Entry(sqe)
994    }
995}
996
997opcode! {
998    /// Issue the equivalent of a `pread(2)` or `pwrite(2)` system call
999    ///
1000    /// * `fd` is the file descriptor to be operated on,
1001    /// * `addr` contains the buffer in question,
1002    /// * `len` contains the length of the IO operation,
1003    ///
1004    /// These are non-vectored versions of the `IORING_OP_READV` and `IORING_OP_WRITEV` opcodes.
1005    /// See also `read(2)` and `write(2)` for the general description of the related system call.
1006    ///
1007    /// Available since 5.6.
1008    pub struct Write {
1009        fd: { impl sealed::UseFixed },
1010        buf: { *const u8 },
1011        len: { u32 },
1012        ;;
1013        /// `offset` contains the read or write offset.
1014        ///
1015        /// If `fd` does not refer to a seekable file, `offset` must be set to zero.
1016        /// If `offsett` is set to `-1`, the offset will use (and advance) the file position,
1017        /// like the `read(2)` and `write(2)` system calls.
1018        offset: u64 = 0,
1019        ioprio: u16 = 0,
1020        rw_flags: i32 = 0,
1021        /// `write_stream` identifies a write stream, added in Linux 6.16
1022        /// (used by NVMe FDP, for example). `0` means no stream.
1023        /// Older kernels ignore this field.
1024        write_stream: u8 = 0
1025    }
1026
1027    pub const CODE = sys::IORING_OP_WRITE;
1028
1029    pub fn build(self) -> Entry {
1030        let Write {
1031            fd,
1032            buf, len, offset,
1033            ioprio, rw_flags,
1034            write_stream
1035        } = self;
1036
1037        let mut sqe = sqe_zeroed();
1038        sqe.opcode = Self::CODE;
1039        assign_fd!(sqe.fd = fd);
1040        sqe.ioprio = ioprio;
1041        sqe.__bindgen_anon_2.addr = buf as _;
1042        sqe.len = len;
1043        sqe.__bindgen_anon_1.off = offset;
1044        sqe.__bindgen_anon_3.rw_flags = rw_flags as _;
1045        sqe.__bindgen_anon_5.__bindgen_anon_2.write_stream = write_stream;
1046        Entry(sqe)
1047    }
1048}
1049
1050opcode! {
1051    /// Predeclare an access pattern for file data, equivalent to `posix_fadvise(2)`.
1052    pub struct Fadvise {
1053        fd: { impl sealed::UseFixed },
1054        len: { libc::off_t },
1055        advice: { i32 },
1056        ;;
1057        offset: u64 = 0,
1058    }
1059
1060    pub const CODE = sys::IORING_OP_FADVISE;
1061
1062    pub fn build(self) -> Entry {
1063        let Fadvise { fd, len, advice, offset } = self;
1064
1065        let mut sqe = sqe_zeroed();
1066        sqe.opcode = Self::CODE;
1067        assign_fd!(sqe.fd = fd);
1068        sqe.len = len as _;
1069        sqe.__bindgen_anon_1.off = offset;
1070        sqe.__bindgen_anon_3.fadvise_advice = advice as _;
1071        Entry(sqe)
1072    }
1073}
1074
1075opcode! {
1076    /// Give advice about use of memory, equivalent to `madvise(2)`.
1077    pub struct Madvise {
1078        addr: { *const libc::c_void },
1079        len: { libc::off_t },
1080        advice: { i32 },
1081        ;;
1082    }
1083
1084    pub const CODE = sys::IORING_OP_MADVISE;
1085
1086    pub fn build(self) -> Entry {
1087        let Madvise { addr, len, advice } = self;
1088
1089        let mut sqe = sqe_zeroed();
1090        sqe.opcode = Self::CODE;
1091        sqe.fd = -1;
1092        sqe.__bindgen_anon_2.addr = addr as _;
1093        sqe.len = len as _;
1094        sqe.__bindgen_anon_3.fadvise_advice = advice as _;
1095        Entry(sqe)
1096    }
1097}
1098
1099opcode! {
1100    /// Send a message on a socket, equivalent to `send(2)`.
1101    pub struct Send {
1102        fd: { impl sealed::UseFixed },
1103        buf: { *const u8 },
1104        len: { u32 },
1105        ;;
1106        ioprio: u16 = 0,
1107        flags: i32 = 0,
1108        buf_group: u16 = 0,
1109
1110        /// Set the destination address, for sending from an unconnected socket.
1111        ///
1112        /// When set, `dest_addr_len` must be set as well.
1113        /// See also `man 3 io_uring_prep_send_set_addr`.
1114        dest_addr: *const libc::sockaddr = core::ptr::null(),
1115        dest_addr_len: libc::socklen_t = 0,
1116    }
1117
1118    pub const CODE = sys::IORING_OP_SEND;
1119
1120    pub fn build(self) -> Entry {
1121        let Send { fd, buf, len, ioprio, flags, buf_group, dest_addr, dest_addr_len } = self;
1122
1123        let mut sqe = sqe_zeroed();
1124        sqe.opcode = Self::CODE;
1125        assign_fd!(sqe.fd = fd);
1126        sqe.__bindgen_anon_2.addr = buf as _;
1127        sqe.__bindgen_anon_1.addr2 = dest_addr as _;
1128        sqe.__bindgen_anon_5.__bindgen_anon_1.addr_len = dest_addr_len as _;
1129        sqe.len = len;
1130        sqe.ioprio = ioprio;
1131        sqe.__bindgen_anon_3.msg_flags = flags as _;
1132        sqe.__bindgen_anon_4.buf_group = buf_group;
1133        Entry(sqe)
1134    }
1135}
1136
1137opcode! {
1138    /// Receive a message from a socket, equivalent to `recv(2)`.
1139    pub struct Recv {
1140        fd: { impl sealed::UseFixed },
1141        buf: { *mut u8 },
1142        len: { u32 },
1143        ;;
1144        ioprio: u16 = 0,
1145        flags: i32 = 0,
1146        buf_group: u16 = 0
1147    }
1148
1149    pub const CODE = sys::IORING_OP_RECV;
1150
1151    pub fn build(self) -> Entry {
1152        let Recv { fd, buf, len, ioprio, flags, buf_group } = self;
1153
1154        let mut sqe = sqe_zeroed();
1155        sqe.opcode = Self::CODE;
1156        assign_fd!(sqe.fd = fd);
1157        sqe.__bindgen_anon_2.addr = buf as _;
1158        sqe.len = len;
1159        sqe.ioprio = ioprio;
1160        sqe.__bindgen_anon_3.msg_flags = flags as _;
1161        sqe.__bindgen_anon_4.buf_group = buf_group;
1162        Entry(sqe)
1163    }
1164}
1165
1166opcode! {
1167    /// Receive multiple messages from a socket, equivalent to `recv(2)`.
1168    ///
1169    /// Parameter:
1170    ///     buf_group: The id of the provided buffer pool to use for each received message.
1171    ///
1172    /// MSG_WAITALL should not be set in flags.
1173    ///
1174    /// The multishot version allows the application to issue a single receive request, which
1175    /// repeatedly posts a CQE when data is available. Each CQE will take a buffer out of a
1176    /// provided buffer pool for receiving. The application should check the flags of each CQE,
1177    /// regardless of its result. If a posted CQE does not have the IORING_CQE_F_MORE flag set then
1178    /// the multishot receive will be done and the application should issue a new request.
1179    ///
1180    /// Multishot variants are available since kernel 6.0.
1181
1182    pub struct RecvMulti {
1183        fd: { impl sealed::UseFixed },
1184        buf_group: { u16 },
1185        ;;
1186        flags: i32 = 0,
1187        len: u32 = 0,
1188    }
1189
1190    pub const CODE = sys::IORING_OP_RECV;
1191
1192    pub fn build(self) -> Entry {
1193        let RecvMulti { fd, buf_group, flags, len } = self;
1194
1195        let mut sqe = sqe_zeroed();
1196        sqe.opcode = Self::CODE;
1197        assign_fd!(sqe.fd = fd);
1198        sqe.len = len;
1199        sqe.__bindgen_anon_3.msg_flags = flags as _;
1200        sqe.__bindgen_anon_4.buf_group = buf_group;
1201        sqe.flags |= crate::squeue::Flags::BUFFER_SELECT.bits();
1202        sqe.ioprio = sys::IORING_RECV_MULTISHOT as _;
1203        Entry(sqe)
1204    }
1205}
1206
1207opcode! {
1208    /// Open a file, equivalent to `openat2(2)`.
1209    pub struct OpenAt2 {
1210        dirfd: { impl sealed::UseFd },
1211        pathname: { *const libc::c_char },
1212        how: { *const types::OpenHow }
1213        ;;
1214        file_index: Option<types::DestinationSlot> = None,
1215    }
1216
1217    pub const CODE = sys::IORING_OP_OPENAT2;
1218
1219    pub fn build(self) -> Entry {
1220        let OpenAt2 { dirfd, pathname, how, file_index } = self;
1221
1222        let mut sqe = sqe_zeroed();
1223        sqe.opcode = Self::CODE;
1224        sqe.fd = dirfd;
1225        sqe.__bindgen_anon_2.addr = pathname as _;
1226        sqe.len = mem::size_of::<sys::open_how>() as _;
1227        sqe.__bindgen_anon_1.off = how as _;
1228        if let Some(dest) = file_index {
1229            sqe.__bindgen_anon_5.file_index = dest.kernel_index_arg();
1230        }
1231        Entry(sqe)
1232    }
1233}
1234
1235opcode! {
1236    /// Modify an epoll file descriptor, equivalent to `epoll_ctl(2)`.
1237    pub struct EpollCtl {
1238        epfd: { impl sealed::UseFixed },
1239        fd: { impl sealed::UseFd },
1240        op: { i32 },
1241        ev: { *const types::epoll_event },
1242        ;;
1243    }
1244
1245    pub const CODE = sys::IORING_OP_EPOLL_CTL;
1246
1247    pub fn build(self) -> Entry {
1248        let EpollCtl { epfd, fd, op, ev } = self;
1249
1250        let mut sqe = sqe_zeroed();
1251        sqe.opcode = Self::CODE;
1252        assign_fd!(sqe.fd = epfd);
1253        sqe.__bindgen_anon_2.addr = ev as _;
1254        sqe.len = op as _;
1255        sqe.__bindgen_anon_1.off = fd as _;
1256        Entry(sqe)
1257    }
1258}
1259
1260// === 5.7 ===
1261
1262opcode! {
1263    /// Splice data to/from a pipe, equivalent to `splice(2)`.
1264    ///
1265    /// if `fd_in` refers to a pipe, `off_in` must be `-1`;
1266    /// The description of `off_in` also applied to `off_out`.
1267    pub struct Splice {
1268        fd_in: { impl sealed::UseFixed },
1269        off_in: { i64 },
1270        fd_out: { impl sealed::UseFixed },
1271        off_out: { i64 },
1272        len: { u32 },
1273        ;;
1274        /// see man `splice(2)` for description of flags.
1275        flags: u32 = 0
1276    }
1277
1278    pub const CODE = sys::IORING_OP_SPLICE;
1279
1280    pub fn build(self) -> Entry {
1281        let Splice { fd_in, off_in, fd_out, off_out, len, mut flags } = self;
1282
1283        let mut sqe = sqe_zeroed();
1284        sqe.opcode = Self::CODE;
1285        assign_fd!(sqe.fd = fd_out);
1286        sqe.len = len;
1287        sqe.__bindgen_anon_1.off = off_out as _;
1288
1289        sqe.__bindgen_anon_5.splice_fd_in = match fd_in {
1290            sealed::Target::Fd(fd) => fd,
1291            sealed::Target::Fixed(idx) => {
1292                flags |= sys::SPLICE_F_FD_IN_FIXED;
1293                idx as _
1294            }
1295        };
1296
1297        sqe.__bindgen_anon_2.splice_off_in = off_in as _;
1298        sqe.__bindgen_anon_3.splice_flags = flags;
1299        Entry(sqe)
1300    }
1301}
1302
1303opcode! {
1304    /// Register `nbufs` buffers that each have the length `len` with ids starting from `bid` in the
1305    /// group `bgid` that can be used for any request. See
1306    /// [`BUFFER_SELECT`](crate::squeue::Flags::BUFFER_SELECT) for more info.
1307    pub struct ProvideBuffers {
1308        addr: { *mut u8 },
1309        len: { i32 },
1310        nbufs: { u16 },
1311        bgid: { u16 },
1312        bid: { u16 }
1313        ;;
1314    }
1315
1316    pub const CODE = sys::IORING_OP_PROVIDE_BUFFERS;
1317
1318    pub fn build(self) -> Entry {
1319        let ProvideBuffers { addr, len, nbufs, bgid, bid } = self;
1320
1321        let mut sqe = sqe_zeroed();
1322        sqe.opcode = Self::CODE;
1323        sqe.fd = nbufs as _;
1324        sqe.__bindgen_anon_2.addr = addr as _;
1325        sqe.len = len as _;
1326        sqe.__bindgen_anon_1.off = bid as _;
1327        sqe.__bindgen_anon_4.buf_group = bgid;
1328        Entry(sqe)
1329    }
1330}
1331
1332opcode! {
1333    /// Remove some number of buffers from a buffer group. See
1334    /// [`BUFFER_SELECT`](crate::squeue::Flags::BUFFER_SELECT) for more info.
1335    pub struct RemoveBuffers {
1336        nbufs: { u16 },
1337        bgid: { u16 }
1338        ;;
1339    }
1340
1341    pub const CODE = sys::IORING_OP_REMOVE_BUFFERS;
1342
1343    pub fn build(self) -> Entry {
1344        let RemoveBuffers { nbufs, bgid } = self;
1345
1346        let mut sqe = sqe_zeroed();
1347        sqe.opcode = Self::CODE;
1348        sqe.fd = nbufs as _;
1349        sqe.__bindgen_anon_4.buf_group = bgid;
1350        Entry(sqe)
1351    }
1352}
1353
1354// === 5.8 ===
1355
1356opcode! {
1357    /// Duplicate pipe content, equivalent to `tee(2)`.
1358    pub struct Tee {
1359        fd_in: { impl sealed::UseFixed },
1360        fd_out: { impl sealed::UseFixed },
1361        len: { u32 }
1362        ;;
1363        flags: u32 = 0
1364    }
1365
1366    pub const CODE = sys::IORING_OP_TEE;
1367
1368    pub fn build(self) -> Entry {
1369        let Tee { fd_in, fd_out, len, mut flags } = self;
1370
1371        let mut sqe = sqe_zeroed();
1372        sqe.opcode = Self::CODE;
1373
1374        assign_fd!(sqe.fd = fd_out);
1375        sqe.len = len;
1376
1377        sqe.__bindgen_anon_5.splice_fd_in = match fd_in {
1378            sealed::Target::Fd(fd) => fd,
1379            sealed::Target::Fixed(idx) => {
1380                flags |= sys::SPLICE_F_FD_IN_FIXED;
1381                idx as _
1382            }
1383        };
1384
1385        sqe.__bindgen_anon_3.splice_flags = flags;
1386
1387        Entry(sqe)
1388    }
1389}
1390
1391// === 5.11 ===
1392
1393opcode! {
1394    /// Shut down all or part of a full duplex connection on a socket, equivalent to `shutdown(2)`.
1395    /// Available since kernel 5.11.
1396    pub struct Shutdown {
1397        fd: { impl sealed::UseFixed },
1398        how: { i32 },
1399        ;;
1400    }
1401
1402    pub const CODE = sys::IORING_OP_SHUTDOWN;
1403
1404    pub fn build(self) -> Entry {
1405        let Shutdown { fd, how } = self;
1406
1407        let mut sqe = sqe_zeroed();
1408        sqe.opcode = Self::CODE;
1409        assign_fd!(sqe.fd = fd);
1410        sqe.len = how as _;
1411        Entry(sqe)
1412    }
1413}
1414
1415opcode! {
1416    // Change the name or location of a file, equivalent to `renameat2(2)`.
1417    // Available since kernel 5.11.
1418    pub struct RenameAt {
1419        olddirfd: { impl sealed::UseFd },
1420        oldpath: { *const libc::c_char },
1421        newdirfd: { impl sealed::UseFd },
1422        newpath: { *const libc::c_char },
1423        ;;
1424        flags: u32 = 0
1425    }
1426
1427    pub const CODE = sys::IORING_OP_RENAMEAT;
1428
1429    pub fn build(self) -> Entry {
1430        let RenameAt {
1431            olddirfd, oldpath,
1432            newdirfd, newpath,
1433            flags
1434        } = self;
1435
1436        let mut sqe = sqe_zeroed();
1437        sqe.opcode = Self::CODE;
1438        sqe.fd = olddirfd;
1439        sqe.__bindgen_anon_2.addr = oldpath as _;
1440        sqe.len = newdirfd as _;
1441        sqe.__bindgen_anon_1.off = newpath as _;
1442        sqe.__bindgen_anon_3.rename_flags = flags;
1443        Entry(sqe)
1444    }
1445}
1446
1447opcode! {
1448    // Delete a name and possible the file it refers to, equivalent to `unlinkat(2)`.
1449    // Available since kernel 5.11.
1450    pub struct UnlinkAt {
1451        dirfd: { impl sealed::UseFd },
1452        pathname: { *const libc::c_char },
1453        ;;
1454        flags: i32 = 0
1455    }
1456
1457    pub const CODE = sys::IORING_OP_UNLINKAT;
1458
1459    pub fn build(self) -> Entry {
1460        let UnlinkAt { dirfd, pathname, flags } = self;
1461
1462        let mut sqe = sqe_zeroed();
1463        sqe.opcode = Self::CODE;
1464        sqe.fd = dirfd;
1465        sqe.__bindgen_anon_2.addr = pathname as _;
1466        sqe.__bindgen_anon_3.unlink_flags = flags as _;
1467        Entry(sqe)
1468    }
1469}
1470
1471// === 5.15 ===
1472
1473opcode! {
1474    /// Make a directory, equivalent to `mkdirat(2)`.
1475    pub struct MkDirAt {
1476        dirfd: { impl sealed::UseFd },
1477        pathname: { *const libc::c_char },
1478        ;;
1479        mode: libc::mode_t = 0
1480    }
1481
1482    pub const CODE = sys::IORING_OP_MKDIRAT;
1483
1484    pub fn build(self) -> Entry {
1485        let MkDirAt { dirfd, pathname, mode } = self;
1486
1487        let mut sqe = sqe_zeroed();
1488        sqe.opcode = Self::CODE;
1489        sqe.fd = dirfd;
1490        sqe.__bindgen_anon_2.addr = pathname as _;
1491        sqe.len = mode;
1492        Entry(sqe)
1493    }
1494}
1495
1496opcode! {
1497    /// Create a symlink, equivalent to `symlinkat(2)`.
1498    pub struct SymlinkAt {
1499        newdirfd: { impl sealed::UseFd },
1500        target: { *const libc::c_char },
1501        linkpath: { *const libc::c_char },
1502        ;;
1503    }
1504
1505    pub const CODE = sys::IORING_OP_SYMLINKAT;
1506
1507    pub fn build(self) -> Entry {
1508        let SymlinkAt { newdirfd, target, linkpath } = self;
1509
1510        let mut sqe = sqe_zeroed();
1511        sqe.opcode = Self::CODE;
1512        sqe.fd = newdirfd;
1513        sqe.__bindgen_anon_2.addr = target as _;
1514        sqe.__bindgen_anon_1.addr2 = linkpath as _;
1515        Entry(sqe)
1516    }
1517}
1518
1519opcode! {
1520    /// Create a hard link, equivalent to `linkat(2)`.
1521    pub struct LinkAt {
1522        olddirfd: { impl sealed::UseFd },
1523        oldpath: { *const libc::c_char },
1524        newdirfd: { impl sealed::UseFd },
1525        newpath: { *const libc::c_char },
1526        ;;
1527        flags: i32 = 0
1528    }
1529
1530    pub const CODE = sys::IORING_OP_LINKAT;
1531
1532    pub fn build(self) -> Entry {
1533        let LinkAt { olddirfd, oldpath, newdirfd, newpath, flags } = self;
1534
1535        let mut sqe = sqe_zeroed();
1536        sqe.opcode = Self::CODE;
1537        sqe.fd = olddirfd as _;
1538        sqe.__bindgen_anon_2.addr = oldpath as _;
1539        sqe.len = newdirfd as _;
1540        sqe.__bindgen_anon_1.addr2 = newpath as _;
1541        sqe.__bindgen_anon_3.hardlink_flags = flags as _;
1542        Entry(sqe)
1543    }
1544}
1545
1546// === 5.17 ===
1547
1548opcode! {
1549    /// Get extended attribute, equivalent to `getxattr(2)`.
1550    pub struct GetXattr {
1551        name: { *const libc::c_char },
1552        value: { *mut libc::c_void },
1553        path: { *const libc::c_char },
1554        len: { u32 },
1555        ;;
1556    }
1557
1558    pub const CODE = sys::IORING_OP_GETXATTR;
1559
1560    pub fn build(self) -> Entry {
1561        let GetXattr { name, value, path, len } = self;
1562
1563        let mut sqe = sqe_zeroed();
1564        sqe.opcode = Self::CODE;
1565        sqe.__bindgen_anon_2.addr = name as _;
1566        sqe.len = len;
1567        sqe.__bindgen_anon_1.off = value as _;
1568        unsafe { sqe.__bindgen_anon_6.__bindgen_anon_1.as_mut().addr3 = path as _ };
1569        sqe.__bindgen_anon_3.xattr_flags = 0;
1570        Entry(sqe)
1571    }
1572}
1573
1574opcode! {
1575    /// Set extended attribute, equivalent to `setxattr(2)`.
1576    pub struct SetXattr {
1577        name: { *const libc::c_char },
1578        value: { *const libc::c_void },
1579        path: { *const libc::c_char },
1580        len: { u32 },
1581        ;;
1582        flags: i32 = 0
1583    }
1584
1585    pub const CODE = sys::IORING_OP_SETXATTR;
1586
1587    pub fn build(self) -> Entry {
1588        let SetXattr { name, value, path, flags, len } = self;
1589
1590        let mut sqe = sqe_zeroed();
1591        sqe.opcode = Self::CODE;
1592        sqe.__bindgen_anon_2.addr = name as _;
1593        sqe.len = len;
1594        sqe.__bindgen_anon_1.off = value as _;
1595        unsafe { sqe.__bindgen_anon_6.__bindgen_anon_1.as_mut().addr3 = path as _ };
1596        sqe.__bindgen_anon_3.xattr_flags = flags as _;
1597        Entry(sqe)
1598    }
1599}
1600
1601opcode! {
1602    /// Get extended attribute from a file descriptor, equivalent to `fgetxattr(2)`.
1603    pub struct FGetXattr {
1604        fd: { impl sealed::UseFixed },
1605        name: { *const libc::c_char },
1606        value: { *mut libc::c_void },
1607        len: { u32 },
1608        ;;
1609    }
1610
1611    pub const CODE = sys::IORING_OP_FGETXATTR;
1612
1613    pub fn build(self) -> Entry {
1614        let FGetXattr { fd, name, value, len } = self;
1615
1616        let mut sqe = sqe_zeroed();
1617        sqe.opcode = Self::CODE;
1618        assign_fd!(sqe.fd = fd);
1619        sqe.__bindgen_anon_2.addr = name as _;
1620        sqe.len = len;
1621        sqe.__bindgen_anon_1.off = value as _;
1622        sqe.__bindgen_anon_3.xattr_flags = 0;
1623        Entry(sqe)
1624    }
1625}
1626
1627opcode! {
1628    /// Set extended attribute on a file descriptor, equivalent to `fsetxattr(2)`.
1629    pub struct FSetXattr {
1630        fd: { impl sealed::UseFixed },
1631        name: { *const libc::c_char },
1632        value: { *const libc::c_void },
1633        len: { u32 },
1634        ;;
1635        flags: i32 = 0
1636    }
1637
1638    pub const CODE = sys::IORING_OP_FSETXATTR;
1639
1640    pub fn build(self) -> Entry {
1641        let FSetXattr { fd, name, value, flags, len } = self;
1642
1643        let mut sqe = sqe_zeroed();
1644        sqe.opcode = Self::CODE;
1645        assign_fd!(sqe.fd = fd);
1646        sqe.__bindgen_anon_2.addr = name as _;
1647        sqe.len = len;
1648        sqe.__bindgen_anon_1.off = value as _;
1649        sqe.__bindgen_anon_3.xattr_flags = flags as _;
1650        Entry(sqe)
1651    }
1652}
1653
1654// === 5.18 ===
1655
1656opcode! {
1657    /// Send a message (with data) to a target ring.
1658    pub struct MsgRingData {
1659        ring_fd: { impl sealed::UseFd },
1660        result: { i32 },
1661        user_data: { u64 },
1662        user_flags: { Option<u32> },
1663        ;;
1664        opcode_flags: u32 = 0
1665    }
1666
1667    pub const CODE = sys::IORING_OP_MSG_RING;
1668
1669    pub fn build(self) -> Entry {
1670        let MsgRingData { ring_fd, result, user_data, user_flags, opcode_flags } = self;
1671
1672        let mut sqe = sqe_zeroed();
1673        sqe.opcode = Self::CODE;
1674        sqe.__bindgen_anon_2.addr = sys::IORING_MSG_DATA.into();
1675        sqe.fd = ring_fd;
1676        sqe.len = result as u32;
1677        sqe.__bindgen_anon_1.off = user_data;
1678        sqe.__bindgen_anon_3.msg_ring_flags = opcode_flags;
1679        if let Some(flags) = user_flags {
1680            sqe.__bindgen_anon_5.file_index = flags;
1681            unsafe {sqe.__bindgen_anon_3.msg_ring_flags |= sys::IORING_MSG_RING_FLAGS_PASS};
1682        }
1683        Entry(sqe)
1684    }
1685}
1686
1687// === 5.19 ===
1688
1689opcode! {
1690    /// Attempt to cancel an already issued request, receiving a cancellation
1691    /// builder, which allows for the new cancel criterias introduced since
1692    /// 5.19.
1693    pub struct AsyncCancel2 {
1694        builder: { types::CancelBuilder }
1695        ;;
1696    }
1697
1698    pub const CODE = sys::IORING_OP_ASYNC_CANCEL;
1699
1700    pub fn build(self) -> Entry {
1701        let AsyncCancel2 { builder } = self;
1702
1703        let mut sqe = sqe_zeroed();
1704        sqe.opcode = Self::CODE;
1705        sqe.fd = builder.to_fd();
1706        sqe.__bindgen_anon_2.addr = builder.user_data.unwrap_or(0);
1707        sqe.__bindgen_anon_3.cancel_flags = builder.flags.bits();
1708        Entry(sqe)
1709    }
1710}
1711
1712opcode! {
1713    /// A file/device-specific 16-byte command, akin (but not equivalent) to `ioctl(2)`.
1714    pub struct UringCmd16 {
1715        fd: { impl sealed::UseFixed },
1716        cmd_op: { u32 },
1717        ;;
1718        /// The `buf_index` is an index into an array of fixed buffers,
1719        /// and is only valid if fixed buffers were registered.
1720        buf_index: Option<u16> = None,
1721        /// Arbitrary command data.
1722        cmd: [u8; 16] = [0u8; 16],
1723        /// The `addr` is typically a pointer to buffer or iovecs,
1724        /// but some file/device command also need to pass an addr.
1725        /// For example, the [ublk](https://docs.kernel.org/block/ublk.html#usage-requirements)
1726        /// needs to set `addr` to some special value.
1727        addr: Option<u64> = None,
1728    }
1729
1730    pub const CODE = sys::IORING_OP_URING_CMD;
1731
1732    pub fn build(self) -> Entry {
1733        let UringCmd16 { fd, cmd_op, cmd, buf_index, addr } = self;
1734
1735        let mut sqe = sqe_zeroed();
1736        sqe.opcode = Self::CODE;
1737        assign_fd!(sqe.fd = fd);
1738        sqe.__bindgen_anon_1.__bindgen_anon_1.cmd_op = cmd_op;
1739        unsafe { *sqe.__bindgen_anon_6.cmd.as_mut().as_mut_ptr().cast::<[u8; 16]>() = cmd };
1740        if let Some(buf_index) = buf_index {
1741            sqe.__bindgen_anon_4.buf_index = buf_index;
1742            unsafe {
1743                sqe.__bindgen_anon_3.uring_cmd_flags |= sys::IORING_URING_CMD_FIXED;
1744            }
1745        }
1746        if let Some(addr) = addr {
1747            sqe.__bindgen_anon_2.addr = addr;
1748        }
1749        Entry(sqe)
1750    }
1751}
1752
1753opcode! {
1754    /// A file/device-specific 80-byte command, akin (but not equivalent) to `ioctl(2)`.
1755    pub struct UringCmd80 {
1756        fd: { impl sealed::UseFixed },
1757        cmd_op: { u32 },
1758        ;;
1759        /// The `buf_index` is an index into an array of fixed buffers,
1760        /// and is only valid if fixed buffers were registered.
1761        buf_index: Option<u16> = None,
1762        /// Arbitrary command data.
1763        cmd: [u8; 80] = [0u8; 80],
1764        /// The `addr` is typically a pointer to buffer or iovecs,
1765        /// but some file/device command also need to pass an addr.
1766        /// For example, the [ublk](https://docs.kernel.org/block/ublk.html#usage-requirements)
1767        /// needs to set `addr` to some special value.
1768        addr: Option<u64> = None,
1769    }
1770
1771    pub const CODE = sys::IORING_OP_URING_CMD;
1772
1773    pub fn build(self) -> Entry128 {
1774        let UringCmd80 { fd, cmd_op, cmd, buf_index, addr } = self;
1775
1776        let cmd1 = cmd[..16].try_into().unwrap();
1777        let cmd2 = cmd[16..].try_into().unwrap();
1778
1779        let mut sqe = sqe_zeroed();
1780        sqe.opcode = Self::CODE;
1781        assign_fd!(sqe.fd = fd);
1782        sqe.__bindgen_anon_1.__bindgen_anon_1.cmd_op = cmd_op;
1783        unsafe { *sqe.__bindgen_anon_6.cmd.as_mut().as_mut_ptr().cast::<[u8; 16]>() = cmd1 };
1784        if let Some(buf_index) = buf_index {
1785            sqe.__bindgen_anon_4.buf_index = buf_index;
1786            unsafe {
1787                sqe.__bindgen_anon_3.uring_cmd_flags |= sys::IORING_URING_CMD_FIXED;
1788            }
1789        }
1790        if let Some(addr) = addr {
1791            sqe.__bindgen_anon_2.addr = addr;
1792        }
1793        Entry128(Entry(sqe), cmd2)
1794    }
1795}
1796
1797opcode! {
1798    /// Create an endpoint for communication, equivalent to `socket(2)`.
1799    ///
1800    /// If the `file_index` argument is set, the resulting socket is
1801    /// directly mapped to the given fixed-file slot instead of being
1802    /// returned as a normal file descriptor. The application must first
1803    /// have registered a file table, and the target slot should fit into
1804    /// it.
1805    ///
1806    /// Available since 5.19.
1807    pub struct Socket {
1808        domain: { i32 },
1809        socket_type: { i32 },
1810        protocol: { i32 },
1811        ;;
1812        file_index: Option<types::DestinationSlot> = None,
1813        flags: i32 = 0,
1814    }
1815
1816    pub const CODE = sys::IORING_OP_SOCKET;
1817
1818    pub fn build(self) -> Entry {
1819        let Socket { domain, socket_type, protocol, file_index, flags } = self;
1820
1821        let mut sqe = sqe_zeroed();
1822        sqe.opcode = Self::CODE;
1823        sqe.fd = domain as _;
1824        sqe.__bindgen_anon_1.off = socket_type as _;
1825        sqe.len = protocol as _;
1826        sqe.__bindgen_anon_3.rw_flags = flags as _;
1827        if let Some(dest) = file_index {
1828            sqe.__bindgen_anon_5.file_index = dest.kernel_index_arg();
1829        }
1830        Entry(sqe)
1831    }
1832}
1833
1834opcode! {
1835    /// Accept multiple new connections on a socket.
1836    ///
1837    /// Set the `allocate_file_index` property if fixed file table entries should be used.
1838    ///
1839    /// Available since 5.19.
1840    pub struct AcceptMulti {
1841        fd: { impl sealed::UseFixed },
1842        ;;
1843        allocate_file_index: bool = false,
1844        flags: i32 = 0
1845    }
1846
1847    pub const CODE = sys::IORING_OP_ACCEPT;
1848
1849    pub fn build(self) -> Entry {
1850        let AcceptMulti { fd, allocate_file_index, flags } = self;
1851
1852        let mut sqe = sqe_zeroed();
1853        sqe.opcode = Self::CODE;
1854        assign_fd!(sqe.fd = fd);
1855        sqe.ioprio = sys::IORING_ACCEPT_MULTISHOT as u16;
1856        // No out SockAddr is passed for the multishot accept case.
1857        // The user should perform a syscall to get any resulting connection's remote address.
1858        sqe.__bindgen_anon_3.accept_flags = flags as _;
1859        if allocate_file_index {
1860            sqe.__bindgen_anon_5.file_index = sys::IORING_FILE_INDEX_ALLOC as u32;
1861        }
1862        Entry(sqe)
1863    }
1864}
1865
1866// === 6.0 ===
1867
1868opcode! {
1869    /// Send a message (with fixed FD) to a target ring.
1870    pub struct MsgRingSendFd {
1871        ring_fd: { impl sealed::UseFd },
1872        fixed_slot_src: { types::Fixed },
1873        dest_slot_index: { types::DestinationSlot },
1874        user_data: { u64 },
1875        ;;
1876        opcode_flags: u32 = 0
1877    }
1878
1879    pub const CODE = sys::IORING_OP_MSG_RING;
1880
1881    pub fn build(self) -> Entry {
1882        let MsgRingSendFd { ring_fd, fixed_slot_src, dest_slot_index, user_data, opcode_flags } = self;
1883
1884        let mut sqe = sqe_zeroed();
1885        sqe.opcode = Self::CODE;
1886        sqe.__bindgen_anon_2.addr = sys::IORING_MSG_SEND_FD.into();
1887        sqe.fd = ring_fd;
1888        sqe.__bindgen_anon_1.off = user_data;
1889        unsafe { sqe.__bindgen_anon_6.__bindgen_anon_1.as_mut().addr3 = fixed_slot_src.0 as u64 };
1890        sqe.__bindgen_anon_5.file_index = dest_slot_index.kernel_index_arg();
1891        sqe.__bindgen_anon_3.msg_ring_flags = opcode_flags;
1892        Entry(sqe)
1893    }
1894}
1895
1896// === 6.0 ===
1897
1898opcode! {
1899    /// Send a zerocopy message on a socket, equivalent to `send(2)`.
1900    ///
1901    /// When `dest_addr` is non-zero it points to the address of the target with `dest_addr_len`
1902    /// specifying its size, turning the request into a `sendto(2)`
1903    ///
1904    /// A fixed (pre-mapped) buffer can optionally be used from pre-mapped buffers that have been
1905    /// previously registered with [`Submitter::register_buffers`](crate::Submitter::register_buffers).
1906    ///
1907    /// This operation might result in two completion queue entries.
1908    /// See the `IORING_OP_SEND_ZC` section at [io_uring_enter][] for the exact semantics.
1909    /// Notifications posted by this operation can be checked with [notif](crate::cqueue::notif).
1910    ///
1911    /// [io_uring_enter]: https://man7.org/linux/man-pages/man2/io_uring_enter.2.html
1912    pub struct SendZc {
1913        fd: { impl sealed::UseFixed },
1914        buf: { *const u8 },
1915        len: { u32 },
1916        ;;
1917        /// The `buf_index` is an index into an array of fixed buffers, and is only valid if fixed
1918        /// buffers were registered.
1919        ///
1920        /// The buf and len arguments must fall within a region specified by buf_index in the
1921        /// previously registered buffer. The buffer need not be aligned with the start of the
1922        /// registered buffer.
1923        buf_index: Option<u16> = None,
1924        dest_addr: *const libc::sockaddr = core::ptr::null(),
1925        dest_addr_len: libc::socklen_t = 0,
1926        flags: i32 = 0,
1927        zc_flags: u16 = 0,
1928    }
1929
1930    pub const CODE = sys::IORING_OP_SEND_ZC;
1931
1932    pub fn build(self) -> Entry {
1933        let SendZc { fd, buf, len, buf_index, dest_addr, dest_addr_len, flags, zc_flags } = self;
1934
1935        let mut sqe = sqe_zeroed();
1936        sqe.opcode = Self::CODE;
1937        assign_fd!(sqe.fd = fd);
1938        sqe.__bindgen_anon_2.addr = buf as _;
1939        sqe.len = len;
1940        sqe.__bindgen_anon_3.msg_flags = flags as _;
1941        sqe.ioprio = zc_flags;
1942        if let Some(buf_index) = buf_index {
1943            sqe.__bindgen_anon_4.buf_index = buf_index;
1944            sqe.ioprio |= sys::IORING_RECVSEND_FIXED_BUF as u16;
1945        }
1946        sqe.__bindgen_anon_1.addr2 = dest_addr as _;
1947        sqe.__bindgen_anon_5.__bindgen_anon_1.addr_len = dest_addr_len as _;
1948        Entry(sqe)
1949    }
1950}
1951
1952// === 6.1 ===
1953
1954opcode! {
1955    /// Send a zerocopy message on a socket, equivalent to `send(2)`.
1956    ///
1957    /// fd must be set to the socket file descriptor, addr must contains a pointer to the msghdr
1958    /// structure, and flags holds the flags associated with the system call.
1959    #[derive(Debug)]
1960    pub struct SendMsgZc {
1961        fd: { impl sealed::UseFixed },
1962        msg: { *const libc::msghdr },
1963        ;;
1964        ioprio: u16 = 0,
1965        flags: u32 = 0,
1966        /// The `buf_index` is an index into an array of fixed buffers, and is only valid if fixed
1967        /// buffers were registered.
1968        ///
1969        /// Every iovec in `msg` must fall within the region specified by `buf_index` in the
1970        /// previously registered buffer. Available since kernel 6.15.
1971        buf_index: Option<u16> = None
1972    }
1973
1974    pub const CODE = sys::IORING_OP_SENDMSG_ZC;
1975
1976    pub fn build(self) -> Entry {
1977        let SendMsgZc { fd, msg, ioprio, flags, buf_index } = self;
1978
1979        let mut sqe = sqe_zeroed();
1980        sqe.opcode = Self::CODE;
1981        assign_fd!(sqe.fd = fd);
1982        sqe.ioprio = ioprio;
1983        if let Some(buf_index) = buf_index {
1984            sqe.__bindgen_anon_4.buf_index = buf_index;
1985            sqe.ioprio |= sys::IORING_RECVSEND_FIXED_BUF as u16;
1986        }
1987        sqe.__bindgen_anon_2.addr = msg as _;
1988        sqe.len = 1;
1989        sqe.__bindgen_anon_3.msg_flags = flags;
1990        Entry(sqe)
1991    }
1992}
1993
1994// === 6.7 ===
1995
1996opcode! {
1997    /// Issue the equivalent of `pread(2)` with multi-shot semantics.
1998    pub struct ReadMulti {
1999        fd: { impl sealed::UseFixed },
2000        len: { u32 },
2001        buf_group: { u16 },
2002        ;;
2003        offset: u64 = 0,
2004    }
2005
2006    pub const CODE = sys::IORING_OP_READ_MULTISHOT;
2007
2008    pub fn build(self) -> Entry {
2009        let Self { fd, len, buf_group, offset } = self;
2010
2011        let mut sqe = sqe_zeroed();
2012        sqe.opcode = Self::CODE;
2013        assign_fd!(sqe.fd = fd);
2014        sqe.__bindgen_anon_1.off = offset;
2015        sqe.len = len;
2016        sqe.__bindgen_anon_4.buf_group = buf_group;
2017        sqe.flags |= crate::squeue::Flags::BUFFER_SELECT.bits();
2018        Entry(sqe)
2019    }
2020}
2021
2022opcode! {
2023    /// Wait on a futex, like but not equivalant to `futex(2)`'s `FUTEX_WAIT_BITSET`.
2024    ///
2025    /// Wait on a futex at address `futex` and which still has the value `val` and with `futex2(2)`
2026    /// flags of `futex_flags`. `musk` can be set to a specific bitset mask, which will be matched
2027    /// by the waking side to decide who to wake up. To always get woken, an application may use
2028    /// `FUTEX_BITSET_MATCH_ANY` (truncated to futex bits). `futex_flags` follows the `futex2(2)`
2029    /// flags, not the `futex(2)` v1 interface flags. `flags` are currently unused and hence `0`
2030    /// must be passed.
2031    #[derive(Debug)]
2032    pub struct FutexWait {
2033        futex: { *const u32 },
2034        val: { u64 },
2035        mask: { u64 },
2036        futex_flags: { u32 },
2037        ;;
2038        flags: u32 = 0
2039    }
2040
2041    pub const CODE = sys::IORING_OP_FUTEX_WAIT;
2042
2043    pub fn build(self) -> Entry {
2044        let FutexWait { futex, val, mask, futex_flags, flags } = self;
2045
2046        let mut sqe = sqe_zeroed();
2047        sqe.opcode = Self::CODE;
2048        sqe.fd = futex_flags as _;
2049        sqe.__bindgen_anon_2.addr = futex as usize as _;
2050        sqe.__bindgen_anon_1.off = val;
2051        unsafe { sqe.__bindgen_anon_6.__bindgen_anon_1.as_mut().addr3 = mask };
2052        sqe.__bindgen_anon_3.futex_flags = flags;
2053        Entry(sqe)
2054    }
2055}
2056
2057opcode! {
2058    /// Wake up waiters on a futex, like but not equivalant to `futex(2)`'s `FUTEX_WAKE_BITSET`.
2059    ///
2060    /// Wake any waiters on the futex indicated by `futex` and at most `val` futexes. `futex_flags`
2061    /// indicates the `futex2(2)` modifier flags. If a given bitset for who to wake is desired,
2062    /// then that must be set in `mask`. Use `FUTEX_BITSET_MATCH_ANY` (truncated to futex bits) to
2063    /// match any waiter on the given futex. `flags` are currently unused and hence `0` must be
2064    /// passed.
2065    #[derive(Debug)]
2066    pub struct FutexWake {
2067        futex: { *const u32 },
2068        val: { u64 },
2069        mask: { u64 },
2070        futex_flags: { u32 },
2071        ;;
2072        flags: u32 = 0
2073    }
2074
2075    pub const CODE = sys::IORING_OP_FUTEX_WAKE;
2076
2077    pub fn build(self) -> Entry {
2078        let FutexWake { futex, val, mask, futex_flags, flags } = self;
2079
2080        let mut sqe = sqe_zeroed();
2081        sqe.opcode = Self::CODE;
2082        sqe.fd = futex_flags as _;
2083        sqe.__bindgen_anon_2.addr = futex as usize as _;
2084        sqe.__bindgen_anon_1.off = val;
2085        unsafe { sqe.__bindgen_anon_6.__bindgen_anon_1.as_mut().addr3 = mask };
2086        sqe.__bindgen_anon_3.futex_flags = flags;
2087        Entry(sqe)
2088    }
2089}
2090
2091opcode! {
2092    /// Wait on multiple futexes.
2093    ///
2094    /// Wait on multiple futexes at the same time. Futexes are given by `futexv` and `nr_futex` is
2095    /// the number of futexes in that array. Unlike `FutexWait`, the desired bitset mask and values
2096    /// are passed in `futexv`. `flags` are currently unused and hence `0` must be passed.
2097    #[derive(Debug)]
2098    pub struct FutexWaitV {
2099        futexv: { *const types::FutexWaitV },
2100        nr_futex: { u32 },
2101        ;;
2102        flags: u32 = 0
2103    }
2104
2105    pub const CODE = sys::IORING_OP_FUTEX_WAITV;
2106
2107    pub fn build(self) -> Entry {
2108        let FutexWaitV { futexv, nr_futex, flags } = self;
2109
2110        let mut sqe = sqe_zeroed();
2111        sqe.opcode = Self::CODE;
2112        sqe.__bindgen_anon_2.addr = futexv as usize as _;
2113        sqe.len = nr_futex;
2114        sqe.__bindgen_anon_3.futex_flags = flags;
2115        Entry(sqe)
2116    }
2117}
2118
2119opcode! {
2120    /// Issue the equivalent of a `waitid(2)` system call.
2121    ///
2122    /// Available since kernel 6.7.
2123    #[derive(Debug)]
2124    pub struct WaitId {
2125        idtype: { libc::idtype_t },
2126        id: { libc::id_t },
2127        options: { libc::c_int },
2128        ;;
2129        infop: *const libc::siginfo_t = std::ptr::null(),
2130        flags: libc::c_uint = 0,
2131    }
2132
2133    pub const CODE = sys::IORING_OP_WAITID;
2134
2135    pub fn build(self) -> Entry {
2136        let mut sqe = sqe_zeroed();
2137        sqe.opcode = Self::CODE;
2138        sqe.fd = self.id as _;
2139        sqe.len = self.idtype as _;
2140        sqe.__bindgen_anon_3.waitid_flags = self.flags;
2141        sqe.__bindgen_anon_5.file_index = self.options as _;
2142        sqe.__bindgen_anon_1.addr2 = self.infop as _;
2143        Entry(sqe)
2144    }
2145}
2146
2147// === 6.8 ===
2148
2149opcode! {
2150    /// Install a fixed file descriptor
2151    ///
2152    /// Turns a direct descriptor into a regular file descriptor that can be later used by regular
2153    /// system calls that take a normal raw file descriptor
2154    #[derive(Debug)]
2155    pub struct FixedFdInstall {
2156        fd: { types::Fixed },
2157        file_flags: { u32 },
2158        ;;
2159    }
2160
2161    pub const CODE = sys::IORING_OP_FIXED_FD_INSTALL;
2162
2163    pub fn build(self) -> Entry {
2164        let FixedFdInstall { fd, file_flags } = self;
2165
2166        let mut sqe = sqe_zeroed();
2167        sqe.opcode = Self::CODE;
2168        sqe.fd = fd.0 as _;
2169        sqe.flags = crate::squeue::Flags::FIXED_FILE.bits();
2170        sqe.__bindgen_anon_3.install_fd_flags = file_flags;
2171        Entry(sqe)
2172    }
2173}
2174
2175// === 6.9 ===
2176
2177opcode! {
2178    /// Perform file truncation, equivalent to `ftruncate(2)`.
2179    #[derive(Debug)]
2180    pub struct Ftruncate {
2181        fd: { impl sealed::UseFixed },
2182        len: { u64 },
2183        ;;
2184    }
2185
2186    pub const CODE = sys::IORING_OP_FTRUNCATE;
2187
2188    pub fn build(self) -> Entry {
2189        let Ftruncate { fd, len } = self;
2190
2191        let mut sqe = sqe_zeroed();
2192        sqe.opcode = Self::CODE;
2193        assign_fd!(sqe.fd = fd);
2194        sqe.__bindgen_anon_1.off = len;
2195        Entry(sqe)
2196    }
2197}
2198
2199// === 6.10 ===
2200
2201opcode! {
2202    /// Send a bundle of messages on a socket in a single request.
2203    pub struct SendBundle {
2204        fd: { impl sealed::UseFixed },
2205        buf_group: { u16 },
2206        ;;
2207        flags: i32 = 0,
2208        len: u32 = 0
2209    }
2210
2211    pub const CODE = sys::IORING_OP_SEND;
2212
2213    pub fn build(self) -> Entry {
2214        let SendBundle { fd, len, flags, buf_group } = self;
2215
2216        let mut sqe = sqe_zeroed();
2217        sqe.opcode = Self::CODE;
2218        assign_fd!(sqe.fd = fd);
2219        sqe.len = len;
2220        sqe.__bindgen_anon_3.msg_flags = flags as _;
2221        sqe.ioprio |= sys::IORING_RECVSEND_BUNDLE as u16;
2222        sqe.flags |= crate::squeue::Flags::BUFFER_SELECT.bits();
2223        sqe.__bindgen_anon_4.buf_group = buf_group;
2224        Entry(sqe)
2225    }
2226}
2227
2228opcode! {
2229    /// Receive a bundle of buffers from a socket.
2230    ///
2231    /// Parameter
2232    ///     buf_group: The id of the provided buffer pool to use for the bundle.
2233    ///
2234    /// Note that as of kernel 6.10 first recv always gets a single buffer, while second
2235    /// obtains the bundle of remaining buffers. This behavior may change in the future.
2236    ///
2237    /// Bundle variant is available since kernel 6.10
2238    pub struct RecvBundle {
2239        fd: { impl sealed::UseFixed },
2240        buf_group: { u16 },
2241        ;;
2242        flags: i32 = 0
2243    }
2244
2245    pub const CODE = sys::IORING_OP_RECV;
2246
2247    pub fn build(self) -> Entry {
2248        let RecvBundle { fd, buf_group, flags } = self;
2249
2250        let mut sqe = sqe_zeroed();
2251        sqe.opcode = Self::CODE;
2252        assign_fd!(sqe.fd = fd);
2253        sqe.__bindgen_anon_3.msg_flags = flags as _;
2254        sqe.__bindgen_anon_4.buf_group = buf_group;
2255        sqe.flags |= crate::squeue::Flags::BUFFER_SELECT.bits();
2256        sqe.ioprio |= sys::IORING_RECVSEND_BUNDLE as u16;
2257        Entry(sqe)
2258    }
2259}
2260
2261opcode! {
2262    /// Receive multiple messages from a socket as a bundle.
2263    ///
2264    /// Parameter:
2265    ///     buf_group: The id of the provided buffer pool to use for each received message.
2266    ///
2267    /// MSG_WAITALL should not be set in flags.
2268    ///
2269    /// The multishot version allows the application to issue a single receive request, which
2270    /// repeatedly posts a CQE when data is available. Each CQE will take a bundle of buffers
2271    /// out of a provided buffer pool for receiving. The application should check the flags of each CQE,
2272    /// regardless of its result. If a posted CQE does not have the IORING_CQE_F_MORE flag set then
2273    /// the multishot receive will be done and the application should issue a new request.
2274    ///
2275    /// Note that as of kernel 6.10 first CQE always gets a single buffer, while second
2276    /// obtains the bundle of remaining buffers. This behavior may change in the future.
2277    ///
2278    /// Multishot bundle variant is available since kernel 6.10.
2279    pub struct RecvMultiBundle {
2280        fd: { impl sealed::UseFixed },
2281        buf_group: { u16 },
2282        ;;
2283        flags: i32 = 0
2284    }
2285
2286    pub const CODE = sys::IORING_OP_RECV;
2287
2288    pub fn build(self) -> Entry {
2289        let RecvMultiBundle { fd, buf_group, flags } = self;
2290
2291        let mut sqe = sqe_zeroed();
2292        sqe.opcode = Self::CODE;
2293        assign_fd!(sqe.fd = fd);
2294        sqe.__bindgen_anon_3.msg_flags = flags as _;
2295        sqe.__bindgen_anon_4.buf_group = buf_group;
2296        sqe.flags |= crate::squeue::Flags::BUFFER_SELECT.bits();
2297        sqe.ioprio = sys::IORING_RECV_MULTISHOT as _;
2298        sqe.ioprio |= sys::IORING_RECVSEND_BUNDLE as u16;
2299        Entry(sqe)
2300    }
2301}
2302
2303// === 6.11 ===
2304
2305opcode! {
2306    /// Bind a socket, equivalent to `bind(2)`.
2307    pub struct Bind {
2308        fd: { impl sealed::UseFixed },
2309        addr: { *const libc::sockaddr },
2310        addrlen: { libc::socklen_t }
2311        ;;
2312    }
2313
2314    pub const CODE = sys::IORING_OP_BIND;
2315
2316    pub fn build(self) -> Entry {
2317        let Bind { fd, addr, addrlen } = self;
2318
2319        let mut sqe = sqe_zeroed();
2320        sqe.opcode = Self::CODE;
2321        assign_fd!(sqe.fd = fd);
2322        sqe.__bindgen_anon_2.addr = addr as _;
2323        sqe.__bindgen_anon_1.off = addrlen as _;
2324        Entry(sqe)
2325    }
2326}
2327
2328opcode! {
2329    /// Listen on a socket, equivalent to `listen(2)`.
2330    pub struct Listen {
2331        fd: { impl sealed::UseFixed },
2332        backlog: { i32 },
2333        ;;
2334    }
2335
2336    pub const CODE = sys::IORING_OP_LISTEN;
2337
2338    pub fn build(self) -> Entry {
2339        let Listen { fd, backlog } = self;
2340
2341        let mut sqe = sqe_zeroed();
2342        sqe.opcode = Self::CODE;
2343        assign_fd!(sqe.fd = fd);
2344        sqe.len = backlog as _;
2345        Entry(sqe)
2346    }
2347}
2348
2349// === 6.15 ===
2350
2351opcode! {
2352    /// Issue the zerocopy equivalent of a `recv(2)` system call.
2353    pub struct RecvZc {
2354        fd: { impl sealed::UseFixed },
2355        len: { u32 },
2356        ;;
2357        ifq: u32 = 0,
2358        ioprio: u16 = 0,
2359    }
2360
2361    pub const CODE = sys::IORING_OP_RECV_ZC;
2362
2363    pub fn build(self) -> Entry {
2364        let Self { fd, len, ifq, ioprio } = self;
2365
2366        let mut sqe = sqe_zeroed();
2367        sqe.opcode = Self::CODE;
2368        assign_fd!(sqe.fd = fd);
2369        sqe.len = len;
2370        sqe.ioprio = ioprio | sys::IORING_RECV_MULTISHOT as u16;
2371        sqe.__bindgen_anon_5.zcrx_ifq_idx = ifq;
2372        Entry(sqe)
2373    }
2374}
2375
2376opcode! {
2377    /// Issue the equivalent of a `epoll_wait(2)` system call.
2378    pub struct EpollWait {
2379        fd: { impl sealed::UseFixed },
2380        events: { *mut types::epoll_event },
2381        max_events: { u32 },
2382        ;;
2383        flags: u32 = 0,
2384    }
2385
2386    pub const CODE = sys::IORING_OP_EPOLL_WAIT;
2387
2388    pub fn build(self) -> Entry {
2389        let Self { fd, events, max_events, flags } = self;
2390
2391        let mut sqe = sqe_zeroed();
2392        sqe.opcode = Self::CODE;
2393        assign_fd!(sqe.fd = fd);
2394        sqe.__bindgen_anon_2.addr = events as u64;
2395        sqe.len = max_events;
2396        sqe.__bindgen_anon_3.poll32_events = flags;
2397        Entry(sqe)
2398    }
2399}
2400
2401opcode! {
2402    /// Vectored read into a fixed buffer, equivalent to `preadv2(2)`.
2403    pub struct ReadvFixed {
2404        fd: { impl sealed::UseFixed },
2405        iovec: { *const ::libc::iovec },
2406        len: { u32 },
2407        buf_index: { u16 },
2408        ;;
2409        ioprio: u16 = 0,
2410        offset: u64 = 0,
2411        rw_flags: i32 = 0,
2412    }
2413
2414    pub const CODE = sys::IORING_OP_READV_FIXED;
2415
2416    pub fn build(self) -> Entry {
2417        let Self { fd, iovec, len, buf_index, offset, ioprio, rw_flags } = self;
2418
2419        let mut sqe = sqe_zeroed();
2420        sqe.opcode = Self::CODE;
2421        assign_fd!(sqe.fd = fd);
2422        sqe.__bindgen_anon_1.off = offset as _;
2423        sqe.__bindgen_anon_2.addr = iovec as _;
2424        sqe.len = len;
2425        sqe.__bindgen_anon_4.buf_index = buf_index;
2426        sqe.ioprio = ioprio;
2427        sqe.__bindgen_anon_3.rw_flags = rw_flags as _;
2428        Entry(sqe)
2429    }
2430}
2431
2432opcode! {
2433    /// Vectored write from a fixed buffer, equivalent to `pwritev2(2)`.
2434    pub struct WritevFixed {
2435        fd: { impl sealed::UseFixed },
2436        iovec: { *const ::libc::iovec },
2437        len: { u32 },
2438        buf_index: { u16 },
2439        ;;
2440        ioprio: u16 = 0,
2441        offset: u64 = 0,
2442        rw_flags: i32 = 0,
2443        /// Write stream id (Linux 6.16+); `0` means no stream.
2444        /// Older kernels ignore this field.
2445        write_stream: u8 = 0,
2446    }
2447
2448    pub const CODE = sys::IORING_OP_WRITEV_FIXED;
2449
2450    pub fn build(self) -> Entry {
2451        let Self { fd, iovec, len, buf_index, offset, ioprio, rw_flags, write_stream } = self;
2452
2453        let mut sqe = sqe_zeroed();
2454        sqe.opcode = Self::CODE;
2455        assign_fd!(sqe.fd = fd);
2456        sqe.__bindgen_anon_1.off = offset as _;
2457        sqe.__bindgen_anon_2.addr = iovec as _;
2458        sqe.len = len;
2459        sqe.__bindgen_anon_4.buf_index = buf_index;
2460        sqe.ioprio = ioprio;
2461        sqe.__bindgen_anon_3.rw_flags = rw_flags as _;
2462        sqe.__bindgen_anon_5.__bindgen_anon_2.write_stream = write_stream;
2463        Entry(sqe)
2464    }
2465}
2466
2467// === 6.16 ===
2468
2469opcode! {
2470    // Create a pipe, equivalent to `pipe(2)`.
2471    pub struct Pipe {
2472        fds: { *mut RawFd },
2473        ;;
2474        flags: u32 = 0,
2475        file_index: Option<types::DestinationSlot> = None,
2476    }
2477
2478    pub const CODE = sys::IORING_OP_PIPE;
2479
2480    pub fn build(self) -> Entry {
2481        let Self { fds, flags, file_index } = self;
2482
2483        let mut sqe = sqe_zeroed();
2484        sqe.opcode = Self::CODE;
2485        sqe.fd = 0;
2486        sqe.__bindgen_anon_2.addr = fds as _;
2487        sqe.__bindgen_anon_3.pipe_flags = flags;
2488        if let Some(dest) = file_index {
2489            sqe.__bindgen_anon_5.file_index = dest.kernel_index_arg();
2490        }
2491        Entry(sqe)
2492    }
2493}