From d33f90b78c2c28a2dff8446fe1cd520e82a1e76e Mon Sep 17 00:00:00 2001 From: guoshichao Date: Fri, 9 Jun 2023 15:48:46 +0800 Subject: [PATCH] libs/libc/aio: fix aio_read compatible bug 1. make the aio_read implementation can pass the ltp/open_posix_testsuite/aio_read testcases 2. the modification are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/aio_read.html Signed-off-by: guoshichao --- fs/aio/aio_read.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/fs/aio/aio_read.c b/fs/aio/aio_read.c index 27c9cfb0a03..468934bf804 100644 --- a/fs/aio/aio_read.c +++ b/fs/aio/aio_read.c @@ -219,6 +219,34 @@ int aio_read(FAR struct aiocb *aiocbp) DEBUGASSERT(aiocbp); + if (aiocbp->aio_reqprio < 0) + { + set_errno(EINVAL); + return ERROR; + } + + if (aiocbp->aio_fildes < 0) + { + /* the EBADF should be collected by aio_error(), we need return OK at + * here + */ + + aiocbp->aio_result = -EBADF; + return OK; + } + + /* for aio_read, the aio_offset should be large or equal than 0 */ + + if (aiocbp->aio_offset < 0) + { + /* the EINVAL should be collected by aio_error(), we need to return OK + * here + */ + + aiocbp->aio_result = -EINVAL; + return OK; + } + /* The result -EINPROGRESS means that the transfer has not yet completed */ sigwork_init(&aiocbp->aio_sigwork);