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 9d2da3e17b98b5f71814abe9c2635fb0e5d5525f
Author: Xiang Xiao <[email protected]>
AuthorDate: Thu Nov 12 01:04:14 2026 +0800

    fs/tmpfs: return -EISDIR when opening the mountpoint root
    
    tmpfs_open() passes an empty relative path to tmpfs_find_file(), which
    cannot look up a zero-length name and fails with -EINVAL.  The empty
    path is the mountpoint root, which is always a directory, and
    file_vopen() only completes such an open as a directory stream when
    the file system reports -EISDIR.  So open("/tmp", O_RDONLY) on a tmpfs
    mount fails while the same call on any other directory succeeds.
    
    Check for the empty relpath before taking the lock and return -EISDIR.
    
    Signed-off-by: Xiang Xiao <[email protected]>
    Signed-off-by: jingfei <[email protected]>
---
 fs/tmpfs/fs_tmpfs.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c
index 1fa042e6010..d368b479945 100644
--- a/fs/tmpfs/fs_tmpfs.c
+++ b/fs/tmpfs/fs_tmpfs.c
@@ -1684,6 +1684,21 @@ static int tmpfs_open(FAR struct file *filep, FAR const 
char *relpath,
 
   DEBUGASSERT(fs != NULL && fs->tfs_root.tde_object != NULL);
 
+  /* Skip over any leading directory separators (shouldn't be any) */
+
+  for (; *relpath == '/'; relpath++);
+
+  /* An empty relative path refers to the mountpoint root, which is
+   * always a directory.  Report EISDIR so that the VFS open fallback
+   * can complete the open as a directory stream (e.g. for O_PATH or
+   * O_DIRECTORY opens of the mountpoint itself).
+   */
+
+  if (*relpath == '\0')
+    {
+      return -EISDIR;
+    }
+
   /* Get exclusive access to the file system */
 
   ret = tmpfs_lock(fs);

Reply via email to