jingfei195887 opened a new pull request, #20868:
URL: https://github.com/apache/nuttx/pull/20868
## Summary
Related to the footprint discussion in #20414.
Many small systems never list a directory, yet every image carries the
directory file layer in `fs/vfs/fs_dir.c` (pseudo and mountpoint readdir
and seek paths, the stand-in inode and its file operations).
This adds `CONFIG_DISABLE_DIRECTORY_OPERATIONS`. When it is set:
- `fs_dir.c` is not built at all (Make and CMake).
- `dir_allocate()` becomes an inline stub returning `-ENOSYS`, so
`opendir()` and `open()` with `O_DIRECTORY` fail with `ENOSYS`, and
`readdir()`/`seekdir()` cannot be reached.
- `dir_fstat()` becomes an inline stub returning `-ENOTTY`, so `fstat()`
keeps using the normal inode path.
The two callers (`fs_open.c`, `fs_fstat.c`) are unchanged.
## Impact
- **Behavior change for `DEFAULT_SMALL` builds.** The option defaults to
`DEFAULT_SMALL`, following `DISABLE_PSEUDOFS_OPERATIONS`. On the
136 in-tree defconfigs with `CONFIG_DEFAULT_SMALL=y`, `opendir()` now
fails, so for example NSH `ls` reports `opendir failed: 38`. Boards
that need directory listing can set
`CONFIG_DISABLE_DIRECTORY_OPERATIONS=n`. Happy to switch the default to
`n` if reviewers prefer not to change existing small boards.
- No change when the option is off.
## Testing
Host: Ubuntu x86_64, arm-none-eabi-gcc 10.3.1 20210621, master a16dbf2100.
| build | master | this PR | delta |
|---|---:|---:|---:|
| `stm32f103-minimum:nsh` (`DEFAULT_SMALL=y`, option on), flash | 51639 |
50643 | **-996** |
| same with option off | 51639 | 51639 | 0 |
With the option on, no `fs_dir.c` symbol is left in the image. Make and
CMake builds both pass.
Runtime on `qemu-armv7a:nsh`:
- Option on: `ls /`, `ls /dev`, `ls /proc` report `opendir failed: 38`
(ENOSYS). `cat /proc/version`, writing to `/dev/null` and the `hello`
builtin work normally.
- Option off: `ls /`, `ls /dev` and `ls /proc` list their contents as
before.
Other checks: `sim:nsh` and `sim:ostest` build with the option on.
`./tools/checkpatch.sh -g master..HEAD`: all checks pass.
`cmake-format --check`: clean.
Not tested on hardware.
--
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]