1*8269e767SBrooks Davis.\" Copyright (c) 1999 Softweyr LLC. 2*8269e767SBrooks Davis.\" All rights reserved. 3*8269e767SBrooks Davis.\" 4*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without 5*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions 6*8269e767SBrooks Davis.\" are met: 7*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright 8*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer. 9*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright 10*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer in the 11*8269e767SBrooks Davis.\" documentation and/or other materials provided with the distribution. 12*8269e767SBrooks Davis.\" 13*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY Softweyr LLC AND CONTRIBUTORS ``AS IS'' AND 14*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16*8269e767SBrooks Davis.\" ARE DISCLAIMED. IN NO EVENT SHALL Softweyr LLC OR CONTRIBUTORS BE LIABLE 17*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23*8269e767SBrooks Davis.\" SUCH DAMAGE. 24*8269e767SBrooks Davis.\" 25*8269e767SBrooks Davis.Dd November 15, 2023 26*8269e767SBrooks Davis.Dt AIO_WRITE 2 27*8269e767SBrooks Davis.Os 28*8269e767SBrooks Davis.Sh NAME 29*8269e767SBrooks Davis.Nm aio_write , 30*8269e767SBrooks Davis.Nm aio_writev 31*8269e767SBrooks Davis.Nd asynchronous write to a file (REALTIME) 32*8269e767SBrooks Davis.Sh LIBRARY 33*8269e767SBrooks Davis.Lb libc 34*8269e767SBrooks Davis.Sh SYNOPSIS 35*8269e767SBrooks Davis.In aio.h 36*8269e767SBrooks Davis.Ft int 37*8269e767SBrooks Davis.Fn aio_write "struct aiocb *iocb" 38*8269e767SBrooks Davis.In sys/uio.h 39*8269e767SBrooks Davis.Ft int 40*8269e767SBrooks Davis.Fn aio_writev "struct aiocb *iocb" 41*8269e767SBrooks Davis.Sh DESCRIPTION 42*8269e767SBrooks DavisThe 43*8269e767SBrooks Davis.Fn aio_write 44*8269e767SBrooks Davisand 45*8269e767SBrooks Davis.Fn aio_writev 46*8269e767SBrooks Davissystem calls allow the calling process to write 47*8269e767SBrooks Davisto the descriptor 48*8269e767SBrooks Davis.Fa iocb->aio_fildes . 49*8269e767SBrooks Davis.Fn aio_write 50*8269e767SBrooks Daviswill write 51*8269e767SBrooks Davis.Fa iocb->aio_nbytes 52*8269e767SBrooks Davisfrom the buffer pointed to by 53*8269e767SBrooks Davis.Fa iocb->aio_buf , 54*8269e767SBrooks Daviswhereas 55*8269e767SBrooks Davis.Fn aio_writev 56*8269e767SBrooks Davisgathers the data from the 57*8269e767SBrooks Davis.Fa iocb->aio_iovcnt 58*8269e767SBrooks Davisbuffers specified by the members of the 59*8269e767SBrooks Davis.Fa iocb->aio_iov 60*8269e767SBrooks Davisarray. 61*8269e767SBrooks DavisBoth syscalls return immediately after the write request has been enqueued 62*8269e767SBrooks Davisto the descriptor; the write may or may not have completed at the time 63*8269e767SBrooks Davisthe call returns. 64*8269e767SBrooks DavisIf the request could not be enqueued, generally due 65*8269e767SBrooks Davisto invalid arguments, the call returns without having enqueued the 66*8269e767SBrooks Davisrequest. 67*8269e767SBrooks Davis.Pp 68*8269e767SBrooks DavisFor 69*8269e767SBrooks Davis.Fn aio_writev 70*8269e767SBrooks Davisthe 71*8269e767SBrooks Davis.Fa iovec 72*8269e767SBrooks Davisstructure is defined in 73*8269e767SBrooks Davis.Xr writev 2 . 74*8269e767SBrooks Davis.Pp 75*8269e767SBrooks DavisIf 76*8269e767SBrooks Davis.Dv O_APPEND 77*8269e767SBrooks Davisis set for 78*8269e767SBrooks Davis.Fa iocb->aio_fildes , 79*8269e767SBrooks Daviswrite operations append to the file in the same order as the calls were 80*8269e767SBrooks Davismade. 81*8269e767SBrooks DavisIf 82*8269e767SBrooks Davis.Dv O_APPEND 83*8269e767SBrooks Davisis not set for the file descriptor, the write operation will occur at 84*8269e767SBrooks Davisthe absolute position from the beginning of the file plus 85*8269e767SBrooks Davis.Fa iocb->aio_offset . 86*8269e767SBrooks Davis.Pp 87*8269e767SBrooks DavisThe 88*8269e767SBrooks Davis.Fa iocb 89*8269e767SBrooks Davispointer may be subsequently used as an argument to 90*8269e767SBrooks Davis.Fn aio_return 91*8269e767SBrooks Davisand 92*8269e767SBrooks Davis.Fn aio_error 93*8269e767SBrooks Davisin order to determine return or error status for the enqueued operation 94*8269e767SBrooks Daviswhile it is in progress. 95*8269e767SBrooks Davis.Pp 96*8269e767SBrooks DavisIf the request is successfully enqueued, the value of 97*8269e767SBrooks Davis.Fa iocb->aio_offset 98*8269e767SBrooks Daviscan be modified during the request as context, so this value must not 99*8269e767SBrooks Davisbe referenced after the request is enqueued. 100*8269e767SBrooks Davis.Pp 101*8269e767SBrooks DavisThe 102*8269e767SBrooks Davis.Fa iocb->aio_sigevent 103*8269e767SBrooks Davisstructure can be used to request notification of the operation's 104*8269e767SBrooks Daviscompletion as described in 105*8269e767SBrooks Davis.Xr aio 4 . 106*8269e767SBrooks Davis.Sh RESTRICTIONS 107*8269e767SBrooks DavisThe Asynchronous I/O Control Block structure pointed to by 108*8269e767SBrooks Davis.Fa iocb 109*8269e767SBrooks Davisand the buffer that the 110*8269e767SBrooks Davis.Fa iocb->aio_buf 111*8269e767SBrooks Davismember of that structure references must remain valid until the 112*8269e767SBrooks Davisoperation has completed. 113*8269e767SBrooks Davis.Pp 114*8269e767SBrooks DavisThe asynchronous I/O control buffer 115*8269e767SBrooks Davis.Fa iocb 116*8269e767SBrooks Davisshould be zeroed before the 117*8269e767SBrooks Davis.Fn aio_write 118*8269e767SBrooks Davisor 119*8269e767SBrooks Davis.Fn aio_writev 120*8269e767SBrooks Davissystem call to avoid passing bogus context information to the kernel. 121*8269e767SBrooks Davis.Pp 122*8269e767SBrooks DavisModifications of the Asynchronous I/O Control Block structure or the 123*8269e767SBrooks Davisbuffer contents are not allowed while the request is queued. 124*8269e767SBrooks Davis.Pp 125*8269e767SBrooks DavisIf the file offset in 126*8269e767SBrooks Davis.Fa iocb->aio_offset 127*8269e767SBrooks Davisis past the offset maximum for 128*8269e767SBrooks Davis.Fa iocb->aio_fildes , 129*8269e767SBrooks Davisno I/O will occur. 130*8269e767SBrooks Davis.Sh RETURN VALUES 131*8269e767SBrooks Davis.Rv -std aio_write aio_writev 132*8269e767SBrooks Davis.Sh ERRORS 133*8269e767SBrooks DavisThe 134*8269e767SBrooks Davis.Fn aio_write 135*8269e767SBrooks Davisand 136*8269e767SBrooks Davis.Fn aio_writev 137*8269e767SBrooks Davissystem calls will fail if: 138*8269e767SBrooks Davis.Bl -tag -width Er 139*8269e767SBrooks Davis.It Bq Er EAGAIN 140*8269e767SBrooks DavisThe request was not queued because of system resource limitations. 141*8269e767SBrooks Davis.It Bq Er EFAULT 142*8269e767SBrooks DavisPart of 143*8269e767SBrooks Davis.Fa aio_iov 144*8269e767SBrooks Davispoints outside the process's allocated address space. 145*8269e767SBrooks Davis.It Bq Er EINVAL 146*8269e767SBrooks DavisThe asynchronous notification method in 147*8269e767SBrooks Davis.Fa iocb->aio_sigevent.sigev_notify 148*8269e767SBrooks Davisis invalid or not supported. 149*8269e767SBrooks Davis.It Bq Er EOPNOTSUPP 150*8269e767SBrooks DavisAsynchronous write operations on the file descriptor 151*8269e767SBrooks Davis.Fa iocb->aio_fildes 152*8269e767SBrooks Davisare unsafe and unsafe asynchronous I/O operations are disabled. 153*8269e767SBrooks Davis.El 154*8269e767SBrooks Davis.Pp 155*8269e767SBrooks DavisThe following conditions may be synchronously detected when the 156*8269e767SBrooks Davis.Fn aio_write 157*8269e767SBrooks Davisor 158*8269e767SBrooks Davis.Fn aio_writev 159*8269e767SBrooks Davissystem call is made, or asynchronously, at any time thereafter. 160*8269e767SBrooks DavisIf they 161*8269e767SBrooks Davisare detected at call time, 162*8269e767SBrooks Davis.Fn aio_write 163*8269e767SBrooks Davisor 164*8269e767SBrooks Davis.Fn aio_writev 165*8269e767SBrooks Davisreturns -1 and sets 166*8269e767SBrooks Davis.Va errno 167*8269e767SBrooks Davisappropriately; otherwise the 168*8269e767SBrooks Davis.Fn aio_return 169*8269e767SBrooks Davissystem call must be called, and will return -1, and 170*8269e767SBrooks Davis.Fn aio_error 171*8269e767SBrooks Davismust be called to determine the actual value that would have been 172*8269e767SBrooks Davisreturned in 173*8269e767SBrooks Davis.Va errno . 174*8269e767SBrooks Davis.Bl -tag -width Er 175*8269e767SBrooks Davis.It Bq Er EBADF 176*8269e767SBrooks DavisThe 177*8269e767SBrooks Davis.Fa iocb->aio_fildes 178*8269e767SBrooks Davisargument 179*8269e767SBrooks Davisis invalid, or is not opened for writing. 180*8269e767SBrooks Davis.It Bq Er EINVAL 181*8269e767SBrooks DavisThe offset 182*8269e767SBrooks Davis.Fa iocb->aio_offset 183*8269e767SBrooks Davisis not valid, the priority specified by 184*8269e767SBrooks Davis.Fa iocb->aio_reqprio 185*8269e767SBrooks Davisis not a valid priority, or the number of bytes specified by 186*8269e767SBrooks Davis.Fa iocb->aio_nbytes 187*8269e767SBrooks Davisis not valid. 188*8269e767SBrooks Davis.El 189*8269e767SBrooks Davis.Pp 190*8269e767SBrooks DavisIf the request is successfully enqueued, but subsequently canceled 191*8269e767SBrooks Davisor an error occurs, the value returned by the 192*8269e767SBrooks Davis.Fn aio_return 193*8269e767SBrooks Davissystem call is per the 194*8269e767SBrooks Davis.Xr write 2 195*8269e767SBrooks Davissystem call, and the value returned by the 196*8269e767SBrooks Davis.Fn aio_error 197*8269e767SBrooks Davissystem call is either one of the error returns from the 198*8269e767SBrooks Davis.Xr write 2 199*8269e767SBrooks Davissystem call, or one of: 200*8269e767SBrooks Davis.Bl -tag -width Er 201*8269e767SBrooks Davis.It Bq Er EBADF 202*8269e767SBrooks DavisThe 203*8269e767SBrooks Davis.Fa iocb->aio_fildes 204*8269e767SBrooks Davisargument 205*8269e767SBrooks Davisis invalid for writing. 206*8269e767SBrooks Davis.It Bq Er ECANCELED 207*8269e767SBrooks DavisThe request was explicitly canceled via a call to 208*8269e767SBrooks Davis.Fn aio_cancel . 209*8269e767SBrooks Davis.It Bq Er EINVAL 210*8269e767SBrooks DavisThe offset 211*8269e767SBrooks Davis.Fa iocb->aio_offset 212*8269e767SBrooks Daviswould be invalid. 213*8269e767SBrooks Davis.El 214*8269e767SBrooks Davis.Sh SEE ALSO 215*8269e767SBrooks Davis.Xr aio_cancel 2 , 216*8269e767SBrooks Davis.Xr aio_error 2 , 217*8269e767SBrooks Davis.Xr aio_return 2 , 218*8269e767SBrooks Davis.Xr aio_suspend 2 , 219*8269e767SBrooks Davis.Xr aio_waitcomplete 2 , 220*8269e767SBrooks Davis.Xr sigevent 3 , 221*8269e767SBrooks Davis.Xr siginfo 3 , 222*8269e767SBrooks Davis.Xr aio 4 223*8269e767SBrooks Davis.Sh STANDARDS 224*8269e767SBrooks DavisThe 225*8269e767SBrooks Davis.Fn aio_write 226*8269e767SBrooks Davissystem call 227*8269e767SBrooks Davisis expected to conform to the 228*8269e767SBrooks Davis.St -p1003.1 229*8269e767SBrooks Davisstandard. 230*8269e767SBrooks Davis.Pp 231*8269e767SBrooks DavisThe 232*8269e767SBrooks Davis.Fn aio_writev 233*8269e767SBrooks Davissystem call is a FreeBSD extension, and should not be used in portable code. 234*8269e767SBrooks Davis.Sh HISTORY 235*8269e767SBrooks DavisThe 236*8269e767SBrooks Davis.Fn aio_write 237*8269e767SBrooks Davissystem call first appeared in 238*8269e767SBrooks Davis.Fx 3.0 . 239*8269e767SBrooks DavisThe 240*8269e767SBrooks Davis.Fn aio_writev 241*8269e767SBrooks Davissystem call first appeared in 242*8269e767SBrooks Davis.Fx 13.0 . 243*8269e767SBrooks Davis.Sh AUTHORS 244*8269e767SBrooks DavisThis manual page was written by 245*8269e767SBrooks Davis.An Wes Peters Aq Mt wes@softweyr.com . 246*8269e767SBrooks Davis.Sh BUGS 247*8269e767SBrooks DavisInvalid information in 248*8269e767SBrooks Davis.Fa iocb->_aiocb_private 249*8269e767SBrooks Davismay confuse the kernel. 250