io_uring_prep_write(3)
π io_uring_prep_write β bestie's guide to prepping a write π
okay so we're in the liburing Manual today and the star of the show is io_uring_prep_write(3). she's a lil function that preps up a write request so your app can yeet bytes at a file descriptor asynchronously. main character energy fr fr. β¨
πΈ NAME πΈ
io_uring_prep_write β prepare I/O write request π«Ά
π SYNOPSIS π
#include <liburing.h>
void io_uring_prep_write(struct io_uring_sqe *sqe,
int fd,
const void *buf,
unsigned nbytes,
__u64 offset);
like literally just copy that include and you're so good. π
π¦ DESCRIPTION π¦
so the way that io_uring_prep_write(3) works is: she prepares an IO write request. the submission queue entry sqe gets set up to use the file descriptor fd to start writing nbytes from the buffer buf at the specified offset. that's the whole vibe. π
now for the tea on files that support seeking: if the offset is set to -1, the write operation commences at the file offset, and the file offset is incremented by the number of bytes written. see write(2) for more details, bestie. π
β οΈ but no cap β for an async API, reading and updating the current file offset may result in unpredictable behavior, unless access to the file is serialized. so it is not encouraged to use this feature if it's possible to provide the desired IO offset from the application or library. like, if you can just pass the offset yourself, do that. pls. π
and on files that are not capable of seeking? the offset must be 0 or -1. those are the only two options, periodt. β
after the write has been prepared, it can be submitted with one of the submit functions. (shoutout to io_uring_submit(3), she's in SEE ALSO for a reason π)
β¨ RETURN VALUE β¨
None. that's it. she returns nothing. she's mysterious like that. π
π ERRORS π
the CQE res field will contain the result of the operation. see the related man page for details on possible values. π
and here's the thing that trips everyone up: 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 like, negative numbers are your error codes now. iykyk. π₯
π SEE ALSO π
okay that's the whole page, you ate that π stay hydrated, serialize your file access, and remember: this whole thing is from liburing-2.1, dated November 15, 2021. mwah π
π¦ 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 bookworm: liburing-dev 2.3-3
- 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) 2021 Stefan Roesch <shr@fb.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms