io_prep_pread(3)
π io_prep_pread(3) β the Linux AIO girlies' guide π
okay so bestie, we're in the Linux AIO section of the manual, and today's main character is io_prep_pread. she's a lil inline function, she's chill, she's literally just here to set things up. let's get into it π¦
β¨ NAME β¨
io_prep_pread β Set up asynchronous read
like, that's her whole job. setting up the async read. no cap. π
πΈ SYNOPSIS πΈ
#include <errno.h>
#include <libaio.h>
inline void io_prep_pread(struct iocb *iocb, int fd, void *buf, size_t count, long long offset);
struct iocb {
void *data;
unsigned key;
short aio_lio_opcode;
short aio_reqprio;
int aio_fildes;
};
okay so first things first: you gotta pull in <errno.h> and <libaio.h>, bestie. then there's the function signature β inline void io_prep_pread(...) β and yeah she's inline, she's void, she's not returning anything to you, she's just doing the prep work behind the scenes. and then the struct iocb is right there so you can see what you're actually filling in. iconic. π
π DESCRIPTION π
io_prep_pread() is an inline convenience function designed to facilitate the initialization of the iocb for an asynchronous read operation.
so basically, she's your little prep-bestie. before you can yeet an async read into the void, you need an iocb (that's the "io control block", the lil form you fill out) and she fills it out for you so you don't have to do it by hand. the way that she just handles it for you?? obsessed. π
here's the actual tea though, fr fr:
- The first
iocb->u.c.nbytes = countbytes of the file for whichiocb->aio_fildes = fdis a descriptor are written to the buffer starting atiocb->u.c.buf = buf. - Reading starts at the absolute position
ioc->u.c.offset = offsetin the file.
so like, count bytes, from the file that fd points at, landing in buf, starting from absolute position offset. that's the whole vibe check right there. β¨
lowkey important: this function returns immediately. she does NOT do the read. she just gets everything ready. to actually schedule the operation you must callio_submit(3). noio_submit, no read. periodt. π
π¨ warning bestie, real talk π¨ Simultaneous asynchronous operations using the sameiocbproduce undefined results. so like, don't be out here sharing oneiocbbetween multiple in-flight operations, that's giving chaos and not the cute kind. oneiocb, one operation, iykyk. π
π RETURN VALUES π
None.
(yeah. she returns nothing. she's a void queen. she gave you setup and that's it. π)
π§ ERRORS π§
None.
π«Ά SEE ALSO π«Ά
io(3)io_cancel(3)io_fsync(3)io_getevents(3)io_prep_fsync(3)io_prep_pwrite(3)io_queue_init(3)io_queue_release(3)io_queue_run(3)io_queue_wait(3)io_set_callback(3)io_submit(3)errno(3)
the whole friend group honestly, go say hi to all of them π
okay that's the whole page!! this one's from Linux, dated 2019-07-23, and yeah that's genuinely it β short page, big energy. go prep those iocbs and slay, bestie πΈβ¨π
π¦ where this page comes from
- alpine 3.22: libaio-doc 0.3.113-r2 Β· LGPL-2.1-or-later
- alpine 3.23: libaio-doc 0.3.113-r2 Β· LGPL-2.1-or-later
- alpine 3.24: libaio-doc 0.3.113-r2 Β· LGPL-2.1-or-later
- arch rolling: libaio 0.3.113-5 Β· LGPL-2.0-or-later
- debian bookworm: libaio-dev 0.3.113-4 Β· LGPL-2.1-or-later
- debian trixie: libaio-dev 0.3.113-8+b1 Β· LGPL-2.1-or-later
- ubuntu jammy: libaio-dev 0.3.112-13build1 Β· LGPL-2.1-or-later
- ubuntu noble: libaio-dev 0.3.113-6build1 Β· LGPL-2.1-or-later
- ubuntu noble: libaio-dev 0.3.113-6build1.1 Β· LGPL-2.1-or-later
- ubuntu questing: libaio-dev 0.3.113-8
- ubuntu resolute: libaio-dev 0.3.113-8build1 Β· LGPL-2.1-or-later
- ubuntu stonking: libaio-dev 0.3.113-9 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms