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 <marco.casaroli@gmail.com>
This commit is contained in:
Marco Casaroli 2026-10-08 21:57:33 +02:00 • committed by Alan C. Assis
parent 97fc2b0c56
commit 3619c557a6
2 changed files with 12 additions and 1 deletions

View file

@ -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;
}

View file

@ -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;
}