io_uring_prep_read_fixed(3)

πŸ“¦
version 2.14 Β· 3 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, centos-stream 10, centos-stream 9, debian trixie, fedora 43, fedora 44, nixpkgs unstable, ubuntu questing, ubuntu resolute

πŸ’– io_uring_prep_read_fixed β€” the liburing manual, but make it cute ✨

okay so bestie, you know io_uring_prep_read? This is its fixed-buffer sister, and she is iconic. It's a liburing function, and no cap, it's giving "I read into memory you already registered" energy. Let's get into it πŸŽ€


✨ NAME ✨

io_uring_prep_read_fixed β€” prepare an I/O read request with a registered buffer πŸ¦‹


🌸 SYNOPSIS 🌸

#include <liburing.h>

void io_uring_prep_read_fixed(struct io_uring_sqe *sqe,
                        int fd,
                        void *buf,
                        unsigned nbytes,
                        __u64 offset,
                        int buf_index);

πŸ’… DESCRIPTION πŸ’…

So io_uring_prep_read_fixed(3) sets up an I/O read request that reads into a buffer you previously registered. Like, you already did the registration thing, now you're cashing in on it. πŸ‘‘

The submission queue entry sqe gets set up to use the file descriptor fd to start reading nbytes into the buffer buf at the specified offset, and the buffer it matches up with is the registered index buf_index. Slay.

This works just like io_uring_prep_read(3), except β€” and this is the whole plot twist β€” it requires you to use buffers that have been registered with io_uring_register_buffers(3). No registration, no service. πŸ™ˆ

The buf and nbytes arguments must fall within a region specified by buf_index in the previously registered buffer. That's a requirement, not a suggestion, fr fr. Good news though: the buffer does not need to be aligned with the start of the registered buffer. So you've got wiggle room, bestie. πŸ’–

After the read has been prepared, you can submit it with one of the submit functions. Then you wait, and the kernel does its little thing. ✨


🫢 RETURN VALUE 🫢

None. That's it. That's the whole return value. She prepares and dips. πŸ’€


😭 ERRORS 😭

The CQE res field will contain the result of the operation β€” that's where the actual tea lives. See the related man page for details on possible values.

⚠️ Big important thing, and I need you to listen: where synchronous system calls will return -1 on failure and set errno to the actual error value, io_uring never uses errno. Instead, it returns the negated errno directly in the CQE res field. So if you're out here checking errno after an io_uring op, you're looking in the wrong place and it's not gonna work out. πŸ’”

🌈 SEE ALSO 🌈


and that's the page, bestie! this one's from liburing-2.1, dated February 13, 2022 β€” the liburing manual, written by the liburing girlies, and honestly? we're obsessed. go register those buffers and read something. mwah πŸ’‹

πŸ“¦ where this page comes from