The Open Group Base Specifications Issue 8
IEEE Std 1003.1-2024
Copyright © 2001-2024 The IEEE and The Open Group

NAME

aio_write — asynchronous write to a file

SYNOPSIS

#include <aio.h>

int aio_write(struct aiocb *
aiocbp);

DESCRIPTION

The aio_write() function shall write aiocbp->aio_nbytes to the file associated with aiocbp->aio_fildes from the buffer pointed to by aiocbp->aio_buf. The function shall return when the write request has been initiated or, at a minimum, queued to the file or device.

[PIO] [Option Start] If prioritized I/O is supported for this file, then the asynchronous operation shall be submitted at a priority equal to a base scheduling priority minus aiocbp->aio_reqprio. If Thread Execution Scheduling is not supported, then the base scheduling priority is that of the calling process;
[Option End] [PIO TPS] [Option Start] otherwise, the base scheduling priority is that of the calling thread. [Option End]

The aiocbp argument may be used as an argument to aio_error() and aio_return() in order to determine the error status and return status, respectively, of the asynchronous operation while it is proceeding.

The aiocbp argument points to an aiocb structure. If the buffer pointed to by aiocbp->aio_buf or the control block pointed to by aiocbp becomes an illegal address prior to asynchronous I/O completion, then the behavior is undefined.

If O_APPEND is not set for the file descriptor aio_fildes, then the requested operation shall take place at the absolute position in the file as given by aio_offset, as if lseek() were called immediately prior to the operation with an offset equal to aio_offset and a whence equal to SEEK_SET. If O_APPEND is set for the file descriptor, or if aio_fildes is associated with a device that is incapable of seeking, write operations append to the file in the same order as the calls were made, except under circumstances described in 2.8.2 Asynchronous I/O . After a successful call to enqueue an asynchronous I/O operation, the value of the file offset for the file is unspecified.

The aio_sigevent member specifies the notification which occurs when the request is completed.

The aiocbp->aio_lio_opcode field shall be ignored by aio_write().

Simultaneous asynchronous operations using the same aiocbp produce undefined results.

[SIO] [Option Start] If synchronized I/O is enabled on the file associated with aiocbp->aio_fildes, the behavior of this function shall be according to the definitions of synchronized I/O data integrity completion, and synchronized I/O file integrity completion. [Option End]

For any system action that changes the process memory space while an asynchronous I/O is outstanding to the address range being changed, the result of that action is undefined.

For regular files, no data transfer shall occur past the offset maximum established in the open file description associated with aiocbp->aio_fildes.

If the request would cause the file size to exceed the soft file size limit for the process and there is no room for any bytes to be written, the request shall fail [XSI] [Option Start]  and the implementation shall generate a SIGXFSZ signal for the thread. [Option End]

RETURN VALUE

The aio_write() function shall return the value zero if the I/O operation is successfully queued; otherwise, the function shall return the value -1 and set errno to indicate the error.

ERRORS

The aio_write() function shall fail if:

[EAGAIN]
The requested asynchronous I/O operation was not queued due to system resource limitations.

Each of the following conditions may be detected synchronously at the time of the call to aio_write(), or asynchronously. If any of the conditions below are detected synchronously, the aio_write() function shall return -1 and set errno to the corresponding value. If any of the conditions below are detected asynchronously, the return status of the asynchronous operation shall be set to -1, and the error status of the asynchronous operation is set to the corresponding value.

[EBADF]
The aiocbp->aio_fildes argument is not a valid file descriptor open for writing.
[EINVAL]
The file offset value implied by aiocbp->aio_offset would be invalid,
[PIO] [Option Start] aiocbp->aio_reqprio is not a valid value, [Option End]  or aiocbp->aio_nbytes is an invalid value.

In the case that the aio_write() successfully queues the I/O operation, the return status of the asynchronous operation shall be one of the values normally returned by the write() function call. If the operation is successfully queued but is subsequently canceled or encounters an error, the error status for the asynchronous operation contains one of the values normally set by the write() function call, or one of the following:

[EBADF]
The aiocbp->aio_fildes argument is not a valid file descriptor open for writing.
[EINVAL]
The file offset value implied by aiocbp->aio_offset would be invalid.
[ECANCELED]
The requested I/O was canceled before the I/O completed due to an explicit aio_cancel() request.

The following condition may be detected synchronously or asynchronously:

[EFBIG]
The file is a regular file, aiobcp->aio_nbytes is greater than 0, and the starting position is greater than or equal to the offset maximum in the open file description associated with aiocbp->aio_fildes.
[EFBIG]
The file is a regular file, aiobcp->aio_nbytes is greater than 0, and there is no room for any bytes to be written at the starting position without exceeding the file size limit for the process. [XSI] [Option Start]  A SIGXFSZ signal shall also be generated for the thread. [Option End]
[EFBIG]
The file is a regular file, aiobcp->aio_nbytes is greater than 0, and there is no room for any bytes to be written at the starting position without exceeding the implementation-defined maximum file size.

The following sections are informative.

EXAMPLES

None.

APPLICATION USAGE

None.

RATIONALE

None.

FUTURE DIRECTIONS

None.

SEE ALSO

2.8.2 Asynchronous I/O , aio_cancel , aio_error , aio_read , aio_return , close , exec , exit , fork , lio_listio , lseek , write

XBD <aio.h>

CHANGE HISTORY

First released in Issue 5. Included for alignment with the POSIX Realtime Extension.

Large File Summit extensions are added.

Issue 6

The [ENOSYS] error condition has been removed as stubs need not be provided if an implementation does not support the Asynchronous Input and Output option.

The APPLICATION USAGE section is added.

The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:

IEEE Std 1003.1-2001/Cor 2-2004, item XSH/TC2/D6/14 is applied, rewording the DESCRIPTION when prioritized I/O is supported to account for threads, and removing the words "to the calling process" in the RETURN VALUE section.

IEEE Std 1003.1-2001/Cor 2-2004, item XSH/TC2/D6/15 is applied, updating the [EINVAL] error, so that detection of an [EINVAL] error for an invalid value of aiocbp->aio_reqprio is only required if the Prioritized Input and Output option is supported.

Issue 7

Austin Group Interpretation 1003.1-2001 #082 is applied.

The aio_write() function is moved from the Asynchronous Input and Output option to the Base.

POSIX.1-2008, Technical Corrigendum 1, XSH/TC1-2008/0028 [317] is applied.

Issue 8

Austin Group Defect 308 is applied, clarifying the handling of [EFBIG] errors.

Austin Group Defect 1669 is applied, removing XSI shading from part of the [EFBIG] error relating to the file size limit for the process.

End of informative text.

 

return to top of page

UNIX® is a registered Trademark of The Open Group.
POSIX™ is a Trademark of The IEEE.
Copyright © 2001-2024 The IEEE and The Open Group, All Rights Reserved
[ Main Index | XBD | XSH | XCU | XRAT ]