Skip to content

fs/vfs: add CONFIG_DISABLE_DIRECTORY_OPERATIONS - #20868

Merged
acassis merged 1 commit into
apache:masterfrom
jingfei195887:size-reduction-nodir
Oct 22, 2026
Merged

acassis merged 1 commit into
apache:masterfrom
jingfei195887:size-reduction-nodir

Conversation

@jingfei195887

Copy link
Copy Markdown
Contributor

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 a16dbf2.

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.

Many small systems never list a directory, yet every image carries the
directory file layer in fs/vfs/fs_dir.c: the pseudo and mountpoint
readdir and seek paths, the stand-in inode and its file operations.

Add DISABLE_DIRECTORY_OPERATIONS, default DEFAULT_SMALL. When set,
fs_dir.c is not built and dir_allocate() returns -ENOSYS, so opendir()
and open() with O_DIRECTORY fail with ENOSYS. dir_fstat() returns
-ENOTTY, so fstat() keeps using the normal inode path.

stm32f103-minimum:nsh: flash -996 bytes.
Signed-off-by: jingfei <[email protected]>
@github-actions github-actions Bot added Area: File System File System issues Size: S The size of the change in this PR is small labels Oct 21, 2026
@xiaoxiang781216
xiaoxiang781216 marked this pull request as ready for review October 21, 2026 11:37
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

arduino-mega2560

  • flash: .data -49 B, .text -1,908 B, .trampolines -20 B (-3.0%, 63,791 B / 262,144 B, total: 24% used)
  • sram: .data -49 B (-1.8%, 2,685 B / 8,192 B, total: 33% used)

hifive1-revb

  • flash: .data -40 B, .text -1,028 B (-1.3%, 84,020 B / 4,194,304 B, total: 2% used)
  • sram: .data -40 B (-1.0%, 3,924 B / 16,384 B, total: 24% used)

mirtoo

  • kseg0_progmem: .data -40 B, .text -1,380 B (-2.1%, 65,964 B / 131,072 B, total: 50% used)
  • kseg1_datamem: .data -40 B, .sbss +8 B (-1.2%, 2,568 B / 32,256 B, total: 8% used)

stm32-nucleo-f103rb

  • flash: .data -40 B, .text -944 B (-2.8%, 33,612 B / 131,072 B, total: 26% used)
  • sram: .data -40 B (-1.6%, 2,432 B / 20,480 B, total: 12% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@acassis
acassis merged commit 31ab2d6 into apache:master Oct 22, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: File System File System issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants