io_uring_prep_splice(3)
β¨ io_uring_prep_splice β the liburing girlies' guide π
okay so bestie, you're in the liburing manual, section 3, and today's main character is io_uring_prep_splice(3). yes that's a mouthful. yes it's iconic. let's go π¦
πΈ NAME πΈ
io_uring_prep_splice β get an splice request all set up and ready to slay
β¨ SYNOPSIS β¨
#include <fcntl.h>
#include <liburing.h>
void io_uring_prep_splice(struct io_uring_sqe *sqe,
int fd_in,
int64_t off_in,
int fd_out,
int64_t off_out,
unsigned int nbytes,
unsigned int splice_flags);
like. look at all those parameters. she's got range π
π DESCRIPTION π
So io_uring_prep_splice(3) prepares a splice request. Basically it takes your submission queue entry, your sqe, and sets it up so that the input is the file descriptor fd_in at offset off_in, and it splices that data over to the file descriptor fd_out at offset off_out. π«
Then nbytes bytes of data should get spliced between those two descriptors. And splice_flags are the modifier flags for the operation β peep splice(2) for the generic splice flags, she's got the lore.
Now, if fd_out is a descriptor you've already registered, you can set IOSQE_FIXED_FILE in the SQE to say so. And for the input file, there's this io_uring-specific one: SPLICE_F_FD_IN_FIXED can be set in splice_flags, and then you pass fd_in as a registered file descriptor offset. cute, right? π
Here's the rules for the offsets, and ngl these matter:
- If
fd_inrefers to a pipe,off_inis ignored and must be set to-1. - If
fd_indoes not refer to a pipe andoff_inis-1, thennbytesare read fromfd_instarting from the file offset, and that file offset gets incremented by however many bytes were read. - If
fd_indoes not refer to a pipe andoff_inis not-1, then the starting offset offd_inwill beoff_in.
And the same exact rules apply to fd_out and off_out. no cap. π
So yeah β this function prepares an async splice(2) request. Go read that man page for the details, she knows things.
π RETURN VALUE π
None. literally nothing. she returns void, bestie, it's giving mysterious. π
π ERRORS π
The CQE res field will contain the result of the operation. Check the related man page for what values are possible.
And here's the thing that trips people up: synchronous system calls return -1 on failure and set errno to the actual error value, but io_uring never uses errno. Instead it returns the negated errno directly in the CQE res field. periodt. π
π SEE ALSO π
π§ NOTES π§
Note that even iffd_inorfd_outrefers to a pipe, the splice operation can still fail withEINVALif one of the fd doesn't explicitly support splice operation, e.g. reading from terminal is unsupported from kernel 5.7 to 5.11.
so like. don't come for her when that happens. it's a kernel thing. π
okay that's the whole page, you ate that π«Ά this was liburing-2.2, dated March 13, 2022 β mwah, go splice something gorgeous, ily, bye bestie βπβ¨
π¦ where this page comes from
- alpine 3.22: liburing-doc 2.9-r0 Β· LGPL-2.1-or-later OR MIT
- alpine 3.23: liburing-doc 2.12-r0 Β· LGPL-2.1-or-later OR MIT
- alpine 3.24: liburing-doc 2.14-r0 Β· LGPL-2.1-or-later OR MIT
- centos-stream 10: liburing-devel 2.12-1.el10 Β· (GPLv2 with exceptions and LGPLv2+) or MIT
- centos-stream 9: liburing-devel 2.12-1.el9 Β· (GPLv2 with exceptions and LGPLv2+) or MIT
- centos-stream 9: liburing-devel 2.12-1.el9 Β· (GPLv2 with exceptions and LGPLv2+) or MIT
- debian trixie: liburing-dev 2.9-1
- fedora 43: liburing-devel 2.9-2.fc43 Β· (GPL-2.0-only WITH Linux-syscall-note OR MIT) AND (LGPL-2.0-or-later OR MIT)
- fedora 43: liburing-devel 2.9-2.fc43 Β· (GPL-2.0-only WITH Linux-syscall-note OR MIT) AND (LGPL-2.0-or-later OR MIT)
- fedora 44: liburing-devel 2.13-2.fc44 Β· (GPL-2.0-only WITH Linux-syscall-note OR MIT) AND (LGPL-2.0-or-later OR MIT)
- fedora 44: liburing-devel 2.13-2.fc44 Β· (GPL-2.0-only WITH Linux-syscall-note OR MIT) AND (LGPL-2.0-or-later OR MIT)
- nixpkgs unstable: liburing 2.14
- opensuse-leap 16.0: liburing-devel 2.8-160000.3.1 Β· (GPL-2.0-only AND LGPL-2.1-or-later) OR MIT
- opensuse-leap 16.0: liburing-devel 2.8-160000.3.1 Β· (GPL-2.0-only AND LGPL-2.1-or-later) OR MIT
- opensuse-leap 16.0: liburing-devel 2.8-160000.3.1 Β· (GPL-2.0-only AND LGPL-2.1-or-later) OR MIT
- opensuse-leap 16.0: liburing-devel 2.8-160000.3.1 Β· (GPL-2.0-only AND LGPL-2.1-or-later) OR MIT
- ubuntu noble: liburing-dev 2.5-1build1
- ubuntu questing: liburing-dev 2.11-1
- ubuntu resolute: liburing-dev 2.14-1
- π the page's license: LGPL-2.0-or-later
- Copyright (C) 2022 Jens Axboe <axboe@kernel.dk>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms