io_prep_fsync(3)
πΎ io_prep_fsync β Linux AIO, bestie edition β¨
okay so this is a page from the Linux AIO manual, section 3 (that's the library-functions girlies π ), and we're about to make your file's whole in-core state line up with what's on disk. no cap.
πΈ NAME πΈ
io_prep_fsync β Synchronize a file's complete in-core state with that on disk π«Ά
literally what it says. your RAM copy and your disk copy are gonna be the same, fr fr.
β¨ SYNOPSIS β¨
#include <errno.h>
#include <libaio.h>
static inline void io_prep_fsync(struct iocb *iocb, int fd);
struct iocb {
void *data;
unsigned key;
short aio_lio_opcode;
short aio_reqprio;
int aio_fildes;
};
yes bestie, two includes. errno.h AND libaio.h. both. we don't make the rules π
π¦ DESCRIPTION π¦
so this is an inline convenience function β a little helper β for setting up an iocb for an FSYNC request. think of it as the pre-game. the actual performance happens later.
it sets up the file where
iocb->aio_fildes = fd
is the descriptor, with the command
iocb->aio_lio_opcode = IO_CMD_FSYNC
now the real tea β β the io_prep_fsync() function shall set up an IO_CMD_FSYNC operation to asynchronously force all I/O operations associated with the file indicated by the file descriptor aio_fildes member of the iocb structure referenced by the iocb argument and queued at the time of the call to io_submit() to the synchronized I/O completion state. whew, that was a mouthful, but it ate. π₯
and the function call shall return when the synchronization request has been initiated or queued to the file or device β even when the data cannot be synchronized immediately. so like, it's out there, it's on its way, don't stress.
all currently queued I/O operations shall be completed as if by a call to fsync(2); that is, as defined for synchronized I/O file integrity completion. periodt. π
π okay important one: if the operation queued byio_prep_fsync()fails, then, as forfsync(2), outstanding I/O operations are not guaranteed to have been completed. not me being the bearer of bad news but you needed to know.
if io_prep_fsync() succeeds, then it is only the I/O that was queued at the time of the call to io_submit(3) that is guaranteed to be forced to the relevant completion state. the completion of subsequent I/O on the file descriptor is not guaranteed to be completed in a synchronized fashion. so likeβ¦ the guarantee has a cutoff date, and that date is "when you called io_submit(3)". iykyk. π
this function returns immediately. to actually schedule the operation, you have to call io_submit(3). it's giving "I set it up, you send it", honestly iconic teamwork.
π and listen: simultaneous asynchronous operations using the sameiocbproduce undefined results. don't do it. sharing oneiocbacross overlapping ops is not the vibe. main character energy only for one operation at a time on that struct, okay?
π RETURN VALUES π
None. nothing. void. she gives nothing and takes nothing. π
π ERRORS π
None. no errors reported here. clean, pristine, unbothered. β¨
π SEE ALSO π
io(3)io_cancel(3)io_fsync(3)io_getevents(3)io_prep_pread(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 read them all, they're all slaying in their own way. π«Ά
okay that's the page bestie!! this one's from Linux, dated 2019-07-23, and it's page io_prep_fsync(3) of the Linux AIO manual β mwah, go sync something. ππ¦πΈ
π¦ 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