jingfei195887 opened a new pull request, #21756:
URL: https://github.com/apache/nuttx/pull/21756
## Summary
`littlefs_ioctl()` builds the `FIOC_FILEPATH` result with `lfs_file_path()`,
which walks the metadata tree back to the root. Once a directory grows past
one metadata block, `lfs_fs_parent()` finds no entry pointing at the
continuation block and the walk fails with -ENOENT, so `F_GETPATH` fails for
most files in a large directory. The walk also reads the disk on every
`close()`, where notify and the path cache ask for the path.
Keep the relative path given to `open()` in `littlefs_file_s` and report
that instead. A `dup()`'ed descriptor shares the same `littlefs_file_s`.
## Impact
`F_GETPATH` on a littlefs file no longer reads the disk. It reports the path
the file was opened with; if an open file is renamed afterwards, the old path
is reported (on master the walk fails in that case). `fstat()`/`fchstat()`
still use `lfs_file_path()`.
## Testing
Host: Ubuntu x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0, master
72c45233a0 (rebased onto 53e46f4b2f; no new
commit touches fs/littlefs), `sim:nsh` with `CONFIG_RAMMTD` and
`CONFIG_FS_LITTLEFS`. A small test program formats littlefs on a 256 KB RAM
MTD, creates 300 files in one directory and compares `fcntl(F_GETPATH)` of
each with its path:
| | master | this PR |
|---|---|---|
| files whose `F_GETPATH` is wrong (of 300) | 283 (first at file017: ENOENT)
| 0 |
| `F_GETPATH` of an open file after `rename()` | -1 | 0, old path |
- `./tools/checkpatch.sh -g master..HEAD`: all checks pass.
- Make and CMake builds pass with no warnings in the changed file;
`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]