jingfei195887 opened a new pull request, #21727:
URL: https://github.com/apache/nuttx/pull/21727

   ## Summary
   
   Two fixes for opening the root of a mount as a directory.
   
   - **fs/tmpfs: return -EISDIR when opening the mountpoint root.**
     `tmpfs_open()` passes an empty relative path to `tmpfs_find_file()`,
     which fails with -EINVAL. `file_vopen()` only turns an open into 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.
   - **fs/vfs: do not double the slash in a directory's fd_path.**
     `dir_allocate()` stores `"%s%s/"` of `inode_getpath()` and the
     relative path. `inode_getpath()` already ends a mountpoint, and a
     pseudo directory with children, with '/', so the root of a mount or
     `/dev` is recorded as `/tmp//` or `/dev//`. That is what
     `F_GETPATH` and dirfd-relative lookups then see. The separator is now
     added only when the path does not already end with one.
   
   ## Impact
   
   `open()` of a tmpfs mountpoint without `O_DIRECTORY` now succeeds as a
   directory stream. `F_GETPATH` of the root of a mount or of a pseudo
   directory reports a single trailing slash. Other directories are
   unchanged.
   
   ## Testing
   
   Host: Ubuntu x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0, master 
59cb24ea20 (rebased onto 59cb24ea20; no
   new commit touches these files), `sim:nsh` with `CONFIG_FS_TMPFS`. tmpfs
   is mounted on `/tmpx` with a subdirectory `sub`; a small test program
   opens each directory and reads `fcntl(F_GETPATH)`:
   
   | open | master | this PR |
   |---|---|---|
   | `/tmpx`, `O_RDONLY` | fails, EINVAL | `/tmpx/` |
   | `/tmpx`, `O_RDONLY \| O_DIRECTORY` | `/tmpx//` | `/tmpx/` |
   | `/tmpx/sub`, `O_DIRECTORY` | `/tmpx/sub/` | `/tmpx/sub/` |
   | `/dev`, `O_DIRECTORY` | `/dev//` | `/dev/` |
   
   - `./tools/checkpatch.sh -g master..HEAD`: all checks pass.
   - Make and CMake builds pass; `ostest` exits with status 0.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to