diff --git a/fs/aio/aio_write.c b/fs/aio/aio_write.c index 580b2ea3a6..803bbdfa1c 100644 --- a/fs/aio/aio_write.c +++ b/fs/aio/aio_write.c @@ -249,6 +249,40 @@ int aio_write(FAR struct aiocb *aiocbp) DEBUGASSERT(aiocbp); + if (aiocbp->aio_reqprio < 0) + { + set_errno(EINVAL); + return ERROR; + } + + if (aiocbp->aio_offset < 0) + { + aiocbp->aio_result = -EINVAL; + return OK; + } + + if (aiocbp->aio_fildes < 0) + { + /* for EBADF, the aio_write do not return error directly, but using + * aio_error to return this error code + */ + + aiocbp->aio_result = -EBADF; + return OK; + } + + /* the aio_fildes that transferred in may be opened with O_RDONLY, for this + * case, we need to return OK directly, and using the aio_error to collect + * the EBADF error code + */ + + int flags = fcntl(aiocbp->aio_fildes, F_GETFL); + if (!(flags & O_WRONLY)) + { + aiocbp->aio_result = -EBADF; + return OK; + } + /* The result -EINPROGRESS means that the transfer has not yet completed */ sigwork_init(&aiocbp->aio_sigwork);