This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 3619c557a68d30a41abfc8561407129f2ac4e6fe
Author: Marco Casaroli <[email protected]>
AuthorDate: Thu Oct 8 21:57:33 2026 +0200

    fs/v9fs: Report the end of a directory as the end, not as an error.
    
    At the end of a directory the 9P server returns no entries.
    v9fs_client_convertdir() then failed with -EIO, so readdir() returned
    NULL with errno set to EIO at the end of every directory.  A program
    that checks errno after readdir() reports an I/O error.
    
    Return -ENOENT when the server returns no entries.  The VFS turns that
    into a clean end of directory.  Also check the space for the fixed part
    of an entry against the bytes left after head, not against the whole
    buffer.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 fs/v9fs/client.c |  3 ++-
 fs/v9fs/v9fs.c   | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/fs/v9fs/client.c b/fs/v9fs/client.c
index e00fdc7cee1..ab5589b5721 100644
--- a/fs/v9fs/client.c
+++ b/fs/v9fs/client.c
@@ -1024,7 +1024,8 @@ ssize_t v9fs_client_convertdir(FAR const uint8_t *buffer, 
size_t bufsize,
    * (qid, offset, type, name_len)
    */
 
-  if (bufsize < V9FS_QIDSZ + V9FS_BIT64SZ + V9FS_BIT8SZ + V9FS_BIT16SZ)
+  if (bufsize - head < V9FS_QIDSZ + V9FS_BIT64SZ + V9FS_BIT8SZ +
+                       V9FS_BIT16SZ)
     {
       return -EIO;
     }
diff --git a/fs/v9fs/v9fs.c b/fs/v9fs/v9fs.c
index b039008e99f..f6777035612 100644
--- a/fs/v9fs/v9fs.c
+++ b/fs/v9fs/v9fs.c
@@ -627,6 +627,16 @@ static int v9fs_vfs_readdir(FAR struct inode *mountpt,
               break;
             }
 
+          /* The server returns no entries at the end of the directory.
+           * -ENOENT tells the VFS that this is the end, not an error.
+           */
+
+          if (ret == 0)
+            {
+              ret = -ENOENT;
+              break;
+            }
+
           fsdir->head = 0;
           fsdir->size = ret;
         }

Reply via email to