AIO_WRITE(2)
β¨ AIO_WRITE(2) β¨ β the async write girlies' manual π
okay so bestie, this is the System Calls Manual page for aio_write, no cap. it's a realtime thing. it's giving concurrency. let's get into it π¦
πΈ NAME πΈ
aio_write β asynchronous write to a file (REALTIME)
literally it writes to a file but it does NOT wait around for it. main character energy.
π LIBRARY π
Standard C Library (libc, -lc)
π SYNOPSIS π
#include <aio.h>
int
aio_write(struct aiocb *iocb);
π DESCRIPTION π
okay so here's the tea. the aio_write() system call lets the calling process write iocb->aio_nbytes from the buffer pointed to by iocb->aio_buf over to the descriptor iocb->aio_fildes. and the way it does it?? the call returns immediately after the write request has been enqueued to the descriptor. so the write may or may not have actually completed by the time the call returns β she's mysterious like that β¨. if the request could not be enqueued, generally because of invalid arguments, the call just returns without having enqueued the request. nothing happened, move on π.
if O_APPEND is set for iocb->aio_fildes, then aio_write() operations append to the file in the same order as the calls were made (queued girlies stay in line, periodt). if O_APPEND is not set for the file descriptor, the write operation will occur at the absolute position from the beginning of the file plus iocb->aio_offset.
if _POSIX_PRIORITIZED_IO is defined, and the descriptor supports it, then the enqueued operation is submitted at a priority equal to that of the calling process minus iocb->aio_reqprio. yes, minus. math. π
the iocb pointer may be subsequently used as an argument to aio_return() and aio_error() so you can figure out the return or error status for the enqueued operation while it's still in progress. multitasking icon behavior.
if the request is successfully enqueued, the value of iocb->aio_offset can be modified during the request as context, so this value must not be referenced after the request is enqueued. do not. it's not yours anymore bestie, let it go π.
the iocb->aio_sigevent structure can be used to request notification of the operation's completion, as described in aio(4). she'll text you when she's done π«Ά.
π§ RESTRICTIONS π§
okay this is the part where we have to be responsible π:
- The Asynchronous I/O Control Block structure pointed to by
iocband the buffer that theiocb->aio_bufmember of that structure references must remain valid until the operation has completed. like, do not free her. do not move her. she is busy. - The asynchronous I/O control buffer
iocbshould be zeroed before theaio_write()system call, to avoid passing bogus context information to the kernel. bogus context is NOT the vibe. - Modifications of the Asynchronous I/O Control Block structure or the buffer contents are not allowed while the request is queued. hands off π ββοΈ.
- If the file offset in
iocb->aio_offsetis past the offset maximum foriocb->aio_fildes, no I/O will occur. nothing. zero. the void π.
π RETURN VALUES π
The aio_write() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.
that's it. 0 = slay, -1 = check errno, we move.
π₯ ERRORS π₯
The aio_write() system call will fail if:
[EAGAIN]β The request was not queued because of system resource limitations. (the system said "no room bestie" π)[EINVAL]β The asynchronous notification method iniocb->aio_sigevent.sigev_notifyis invalid or not supported.[EOPNOTSUPP]β Asynchronous write operations on the file descriptoriocb->aio_fildesare unsafe and unsafe asynchronous I/O operations are disabled.
The following conditions may be synchronously detected when the aio_write() system call is made, or asynchronously, at any time thereafter. If they are detected at call time, aio_write() returns -1 and sets errno appropriately; otherwise the aio_return() system call must be called, and will return -1, and aio_error() must be called to determine the actual value that would have been returned in errno. (yes you have to go ask the other two functions, it's a whole group chat investigation π)
[EBADF]β Theiocb->aio_fildesargument is invalid, or is not opened for writing.[EINVAL]β The offsetiocb->aio_offsetis not valid, the priority specified byiocb->aio_reqpriois not a valid priority, or the number of bytes specified byiocb->aio_nbytesis not valid.
If the request is successfully enqueued, but subsequently canceled or an error occurs, the value returned by the aio_return() system call is per the write(2) system call, and the value returned by the aio_error() system call is either one of the error returns from the write(2) system call, or one of:
[EBADF]β Theiocb->aio_fildesargument is invalid for writing.[ECANCELED]β The request was explicitly canceled via a call toaio_cancel().[EINVAL]β The offsetiocb->aio_offsetwould be invalid.
π SEE ALSO π
aio_cancel(2), aio_error(2), aio_return(2), aio_suspend(2), aio_waitcomplete(2), sigevent(3), siginfo(3), aio(4)
the whole friend group honestly π«Ά
β STANDARDS β
The aio_write() system call is expected to conform to the IEEE Std 1003.1 (βPOSIX.1β) standard. certified. official. iconic π.
π°οΈ HISTORY π°οΈ
The aio_write() system call first appeared in FreeBSD 3.0. vintage but make it async β¨.
ποΈ AUTHORS ποΈ
This manual page was written by Wes Peters <wes@softweyr.com>. thank you wes, king behavior π.
π BUGS π
Invalid information in iocb->_aiocb_private may confuse the kernel. the kernel gets confused. we've all been there π.
reminder bestie: zero theiocb, keep the buffer alive, and never peek atiocb->aio_offsetafter enqueue. that's the whole plot π
and that's a wrap on the Debian version of this page, dated August 19, 2016 β AIO_WRITE(2), signing off, mwah π πΈπ¦π
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1999 Softweyr LLC
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms