This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit fe98a0f7c53a608f0c7126e444743ff7f6b906f5 Author: Marco Casaroli <[email protected]> AuthorDate: Sat Oct 24 10:38:42 2026 +0200 fs/aio: Read and write a file that cannot seek at its position. The AIO workers read and wrote with file_pread() and file_pwrite() at aio_offset. For a file that cannot seek, a pipe, a FIFO or a socket, POSIX ignores aio_offset. file_pread() and file_pwrite() seek, and once lseek() of a pipe fails with ESPIPE, the request would fail at once instead of reading or writing. Add INODE_IS_NOSEEK() for the inodes that have no file position: pipes, FIFOs and sockets. The AIO workers read and write these with file_read() and file_write() at the current position. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- fs/aio/aio_read.c | 14 ++++++++++++-- fs/aio/aio_write.c | 9 ++++++--- include/nuttx/fs/fs.h | 4 ++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/fs/aio/aio_read.c b/fs/aio/aio_read.c index 28b6f12f1cd..7ef393e4f10 100644 --- a/fs/aio/aio_read.c +++ b/fs/aio/aio_read.c @@ -89,8 +89,18 @@ static void aio_read_worker(FAR void *arg) * aio_offset - File offset */ - nread = file_pread(aioc->aioc_filep, (FAR void *)aiocbp->aio_buf, - aiocbp->aio_nbytes, aiocbp->aio_offset); + if (INODE_IS_NOSEEK(aioc->aioc_filep->f_inode)) + { + /* A pipe, a FIFO or a socket cannot seek: aio_offset is ignored */ + + nread = file_read(aioc->aioc_filep, (FAR void *)aiocbp->aio_buf, + aiocbp->aio_nbytes); + } + else + { + nread = file_pread(aioc->aioc_filep, (FAR void *)aiocbp->aio_buf, + aiocbp->aio_nbytes, aiocbp->aio_offset); + } /* Set the result of the read operation. */ diff --git a/fs/aio/aio_write.c b/fs/aio/aio_write.c index 81fcd37f8b2..ab619cafebe 100644 --- a/fs/aio/aio_write.c +++ b/fs/aio/aio_write.c @@ -102,11 +102,14 @@ static void aio_write_worker(FAR void *arg) * aio_offset - File offset */ - /* Check if O_APPEND is set in the file open flags */ + /* Check if O_APPEND is set in the file open flags. A pipe, a FIFO or a + * socket cannot seek: aio_offset is ignored. + */ - if ((oflags & O_APPEND) != 0) + if ((oflags & O_APPEND) != 0 || + INODE_IS_NOSEEK(aioc->aioc_filep->f_inode)) { - /* Append to the current file position */ + /* Write at the current file position */ nwritten = file_write(aioc->aioc_filep, (FAR const void *)aiocbp->aio_buf, diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index 39a65b7a26f..d115cf4604c 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -166,6 +166,10 @@ #define INODE_IS_NOEXEC(i) (((i)->i_flags & FSNODEFLAG_NOEXEC) != 0) +/* A pipe, a FIFO or a socket has no file position (POSIX: ESPIPE) */ + +#define INODE_IS_NOSEEK(i) (INODE_IS_PIPE(i) || INODE_IS_SOCKET(i)) + /* The status change flags. * These should be or-ed together to figure out what want to change. */
