Skip to content

fs/tmpfs: Return ENOTEMPTY from rmdir of a non-empty directory. - #21450

Merged
acassis merged 1 commit into
apache:masterfrom
casaroli:tmpfs-rmdir-notempty-up
Nov 4, 2026
Merged

acassis merged 1 commit into
apache:masterfrom
casaroli:tmpfs-rmdir-notempty-up

Conversation

@casaroli

@casaroli casaroli commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Summary

rmdir() of a tmpfs directory that is not empty fails with EBUSY. POSIX specifies ENOTEMPTY or EEXIST. tmpfs_rmdir() now returns -ENOTEMPTY for a directory with entries. An empty directory that is open still gives EBUSY.

Impact

  • All build modes and architectures: the change is in common tmpfs code.
  • A program that removes a non-empty tmpfs directory now gets ENOTEMPTY, not EBUSY. This is a change of an error code that flat-build programs can see. remove() gives the same error.
  • FAT, SmartFS, littlefs, mnemofs, xipfs and the pseudo file system return ENOTEMPTY. The rename path of tmpfs already returns ENOTEMPTY first and then EBUSY, in the same order.
  • Nothing in nuttx or nuttx-apps tests for EBUSY from rmdir(). examples/mount expects ENOTEMPTY. The caller in fs_rename.c does not test the error code.
  • No documentation change: Documentation/ does not list the error codes of rmdir().

Testing

Test program rmdirbusy.c, 6 checks on a new tmpfs mount:

check master this PR
rmdir(), the directory has a directory FAIL EBUSY PASS ENOTEMPTY
remove(), the directory has a directory FAIL EBUSY PASS ENOTEMPTY
rmdir(), the directory has a file FAIL EBUSY PASS ENOTEMPTY
rmdir(), the directory has a file and is open FAIL EBUSY PASS ENOTEMPTY
rmdir(), the directory is empty and open PASS EBUSY PASS EBUSY
rmdir(), the directory is empty and closed PASS PASS

The results are the same on qemu-armv8a:knsh (kernel, arm64, QEMU with HVF) and qemu-armv8a:nsh (flat, arm64, HVF): master 2 PASS, 4 FAIL; this PR 6 PASS.

ostest exits with status 0 on master and with this PR: qemu-armv8a:knsh, qemu-armv8a:nsh, and the flat qemu-armv8a:nsh build with the test. All have CONFIG_FS_TMPFS.

No test in CI checks this error code: the cmocka test rmdir02 asks for ENOTEMPTY in its table, but it checks only that rmdir() fails.

Builds with EXTRAFLAGS="-Wno-cpp -Werror", each OK: qemu-armv8a:knsh and qemu-armv8a:nsh (with CONFIG_FS_TMPFS), sim:nsh (macOS host; the only warnings come from the host linker, -ld_classic).

The tests ran on master 39a1f27; the branch is rebased on 3d57048 (no change in the touched files).

tools/checkpatch.sh -c -u -m -g passes.

tmpfs_rmdir() returned EBUSY for a directory with entries.  POSIX
specifies ENOTEMPTY or EEXIST.  FAT, SmartFS, littlefs and the rename
path of tmpfs return ENOTEMPTY.

An empty directory that is open still gives EBUSY.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
@casaroli casaroli added the Area: OS Components OS Components issues label Nov 4, 2026
@casaroli casaroli added the Area: OS Components OS Components issues label Nov 4, 2026
@github-actions github-actions Bot added Area: File System File System issues Size: S The size of the change in this PR is small and removed Area: OS Components OS Components issues labels Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

qemu-armv8a

  • Code: .text.tmpfs_rmdir +8 B (+0.0%, 360,200 B)

No memory changes detected for:


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

@acassis
acassis merged commit 5ea5bec into apache:master Nov 4, 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