io_uring_prep_close(3)
π io_uring_prep_close β from the liburing manual, bestie edition π
okay so. you wanna close a file descriptor but you wanna do it the io_uring way, all async and chic, and you opened the man page and it's giving... man page. don't worry, i got you. this whole page is about io_uring_prep_close(3) and its direct-descriptor sibling, and honestly? it's short. slay. let's go. β¨
πΈ NAME πΈ
io_uring_prep_close β prepare a file descriptor close request
like, it preps the request. it does not do the closing itself. we'll get there, bestie, patience π
π¦ SYNOPSIS π¦
#include <liburing.h>
void io_uring_prep_close(struct io_uring_sqe *sqe,
int fd);
void io_uring_prep_close_direct(struct io_uring_sqe *sqe,
unsigned file_index);
two functions. two vibes. one of them takes a regular fd, the other one takes a file_index because it's fancy. π
β¨ DESCRIPTION β¨
So io_uring_prep_close(3) prepares a close request. The submission queue entry sqe gets set up so that it will close the file descriptor indicated by fd. That's it. That's the whole thing. Queen of being straightforward. π
Now for the direct descriptor version β the one that closes a direct descriptor β the offset is specified by the file_index argument instead of the fd. This is identical to unregistering the direct descriptor, and it's just provided as a convenience. They really said "we'll do it for you, mwah". π«Ά
β οΈ okay but listen. Even though it's closing a direct descriptor, the application must not setIOSQE_FIXED_FILEon the SQE. Otherwise the request will complete with-EBADFas the result. Like, it will literally fail on you and you will be sad. do not do it. no cap. π
Both of these functions prepare an async close(2) request. So go read that man page for the details, because this page is not about to re-explain close(2) to you. iykyk.
π RETURN VALUE π
None.
(genuinely nothing. it's void. the results come back somewhere else, keep reading.) π
π ERRORS π
The CQE res field will contain the result of the operation. See the related man page for the details on possible values. β¨
For closing of a direct descriptor, the only failure cases are:
- the kernel running completely out of memory π
- the application having specified an invalid direct descriptor π
π¨ important vibe check: where synchronous system calls will return-1on failure and seterrnoto the actual error value, io_uring never useserrno. Instead it returns the negatederrnodirectly in the CQEresfield. So like, look atres, noterrno. periodt. π
π₯ SEE ALSO π₯
and that's the whole page, bestie, you ate it π
go forth and close your file descriptors responsibly. this was liburing-2.2, dated March 13, 2022 β mwah, bye, love you, don't forget the IOSQE_FIXED_FILE thing π¦ππΈ
π¦ 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
- arch rolling: liburing 2.15-1 Β· GPL-2.0-only WITH Linux-syscall-note OR MIT AND LGPL-2.0-or-later AND 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
- ubuntu questing: liburing-dev 2.11-1
- ubuntu resolute: liburing-dev 2.14-1
- ubuntu stonking: liburing-dev 2.15-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