fix(libc): report ENOTEMPTY when a host rename onto a non-empty directory fails with EEXIST #27771

Open
shinhop wants to merge 1 commit from upstream-pr/27771 into main
shinhop commented 2026-11-27 09:20:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by shinhop on 2026-11-27T09:20:20Z.


What

On Linux, rename(2) onto a non-empty directory may fail with either ENOTEMPTY or EEXIST; XFS returns EEXIST. RenameNative_nid_no_patch (libc rename) and RenamePath (libkernel_sys renameat) passed the host error through, so on XFS the guest saw EEXIST (17) where the console reports ENOTEMPTY (66). Both now translate a host EEXIST from rename to ENOTEMPTY outside Windows. The Windows paths are unchanged: they already check the destination with is_empty before renaming.

A pre-rename is_empty check on Linux is not used because it needs read access to the destination: renaming onto an empty directory with no permissions succeeds natively and is checked by guest_kernel_sys.

Tested

Fedora 45 (glibc 2.44), Ryzen 9 3900X, build and tests on XFS, this branch is based on main 0156867329.

  • main 21e1e006c3: guest_kernel_sys (GuestKernelSys.cpp:2285), guest_filesystem (GuestFilesystem.cpp:1292) and guest_kernel_rename (GuestKernelRename.cpp:142), the checks that rename a directory onto a non-empty directory, fail 10/10 with guest errno 17 when the working directory is on XFS, and pass with the working directory on tmpfs.
  • This PR: full ctest --test-dir build -j 8, 7119/7119 passed; the three tests above passed 10/10 each with ctest -R "^<test>$" -j 1.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Summary by CodeRabbit

  • Bug Fixes
    • Rename operations on non-Windows platforms now report an existing destination as “directory not empty,” aligning the error with the filesystem condition. Other rename errors remain unchanged.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5524198280 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27771). Originally posted by [shinhop](https://github.com/shinhop) on 2026-11-27T09:20:20Z. --- ### What On Linux, `rename(2)` onto a non-empty directory may fail with either `ENOTEMPTY` or `EEXIST`; XFS returns `EEXIST`. `RenameNative_nid_no_patch` (libc `rename`) and `RenamePath` (libkernel_sys `renameat`) passed the host error through, so on XFS the guest saw `EEXIST` (17) where the console reports `ENOTEMPTY` (66). Both now translate a host `EEXIST` from `rename` to `ENOTEMPTY` outside Windows. The Windows paths are unchanged: they already check the destination with `is_empty` before renaming. A pre-rename `is_empty` check on Linux is not used because it needs read access to the destination: renaming onto an empty directory with no permissions succeeds natively and is checked by `guest_kernel_sys`. ### Tested Fedora 45 (glibc 2.44), Ryzen 9 3900X, build and tests on XFS, this branch is based on `main` `0156867329`. - `main` `21e1e006c3`: `guest_kernel_sys` (`GuestKernelSys.cpp:2285`), `guest_filesystem` (`GuestFilesystem.cpp:1292`) and `guest_kernel_rename` (`GuestKernelRename.cpp:142`), the checks that rename a directory onto a non-empty directory, fail 10/10 with guest errno 17 when the working directory is on XFS, and pass with the working directory on tmpfs. - This PR: full `ctest --test-dir build -j 8`, 7119/7119 passed; the three tests above passed 10/10 each with `ctest -R "^<test>$" -j 1`. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Rename operations on non-Windows platforms now report an existing destination as “directory not empty,” aligning the error with the filesystem condition. Other rename errors remain unchanged. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
MarcZX10 commented 2026-11-27 09:40:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T09:40:53Z.

Review: APPROVED


Reviewed — looks good

The change maps host EEXIST from non-Windows rename operations to guest ENOTEMPTY in both affected paths; the reviewed code supports merging.

What I ran

Reviewed head 96b7e87c1a1edaf0145e8106af26e3229dbb05b. No commands or tests were run; the author reports Fedora 45/XFS test results in the PR description.

Results

Check Result Note
Code review passed Both rename paths inspected
Tests not run Author reports successful tests

Findings

Blocking

None.

Non-blocking

None.

Not verified

Tests and runtime behavior were not independently verified. Read description.md, commits.md, manifest.json, diff.patch, core/libs/prx/libc/src/Rename.cpp, core/libs/prx/libkernel_sys/Export.cpp, and core/libs/prx/libc/src/HostErrno.cpp. All changed files marked reviewed in the manifest were read. files.json was not available in the prepared review folder, so excluded-file status was not verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6086177773 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27771#pullrequestreview-6086177773). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-27T09:40:53Z. **Review:** APPROVED --- # Reviewed — looks good The change maps host `EEXIST` from non-Windows rename operations to guest `ENOTEMPTY` in both affected paths; the reviewed code supports merging. ## What I ran Reviewed head `96b7e87c1a1edaf0145e8106af26e3229dbb05b`. No commands or tests were run; the author reports Fedora 45/XFS test results in the PR description. ## Results | Check | Result | Note | |---|---|---| | Code review | passed | Both rename paths inspected | | Tests | not run | Author reports successful tests | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Tests and runtime behavior were not independently verified. Read `description.md`, `commits.md`, `manifest.json`, `diff.patch`, `core/libs/prx/libc/src/Rename.cpp`, `core/libs/prx/libkernel_sys/Export.cpp`, and `core/libs/prx/libc/src/HostErrno.cpp`. All changed files marked `reviewed` in the manifest were read. `files.json` was not available in the prepared review folder, so excluded-file status was not verified. ## To get this to a good state Nothing is required.
Plyxen commented 2026-11-28 05:06:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-28T05:06:21Z.

Review: APPROVED


Checked head 96b7e87c1a. All on Windows 11 with WinLibs GCC 15.2 (Release), applied to main a163d4b886 together with #27930, #27929, #27926, #27925, #27924, #27923, #27922, #27901, #27828, #27755, #27748, #27682, #27765. tools/check_conventions.py --head and tools/debt_fold.py --check passed and the full build succeeded. Both changes are compiled out on Windows: the first is in the non-Windows #else of RenameNative_nid_no_patch, the second is under #ifndef _WIN32 in RenamePath. So here I could only confirm that the build works and that guest_kernel_rename and guest_rename_dot still pass. The mapping matches POSIX, which allows either EEXIST or ENOTEMPTY when the target is a non-empty directory. In the full CPU suite (5,120 tests) the only failures are unrelated:

  • windows_read_trap_unknown fails on main too (fixed in #28028).
  • frame_capture_minimize, jpeg_external_toolchain and guest_pthread_mutex_contention are timeouts under load; they pass when run on their own.
  • guest_audio_in_capture passes 20/20 on main and with #27922.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6095939291 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27771#pullrequestreview-6095939291). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-11-28T05:06:21Z. **Review:** APPROVED --- Checked head `96b7e87c1a`. All on Windows 11 with WinLibs GCC 15.2 (Release), applied to `main` `a163d4b886` together with #27930, #27929, #27926, #27925, #27924, #27923, #27922, #27901, #27828, #27755, #27748, #27682, #27765. `tools/check_conventions.py --head` and `tools/debt_fold.py --check` passed and the full build succeeded. Both changes are compiled out on Windows: the first is in the non-Windows `#else` of `RenameNative_nid_no_patch`, the second is under `#ifndef _WIN32` in `RenamePath`. So here I could only confirm that the build works and that `guest_kernel_rename` and `guest_rename_dot` still pass. The mapping matches POSIX, which allows either `EEXIST` or `ENOTEMPTY` when the target is a non-empty directory. In the full CPU suite (5,120 tests) the only failures are unrelated: - `windows_read_trap_unknown` fails on `main` too (fixed in #28028). - `frame_capture_minimize`, `jpeg_external_toolchain` and `guest_pthread_mutex_contention` are timeouts under load; they pass when run on their own. - `guest_audio_in_capture` passes 20/20 on `main` and with #27922. AI-assisted: yes (Claude Code)
ligmaSec commented 2026-12-03 09:02:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T09:02:42Z.

Review: COMMENTED


Ran a Linux comparison of RenameNative_nid_no_patch with the exact before and after sources. Renaming onto a real nonempty directory returned ENOTEMPTY in both. With a simulated host EEXIST on that operation, the old code returned EEXIST and the new code returned ENOTEMPTY. Injected EACCES passed through in both versions. I checked the parallel guest-kernel mapping in source.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6166583250 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27771#pullrequestreview-6166583250). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T09:02:42Z. **Review:** COMMENTED --- Ran a Linux comparison of `RenameNative_nid_no_patch` with the exact before and after sources. Renaming onto a real nonempty directory returned ENOTEMPTY in both. With a simulated host EEXIST on that operation, the old code returned EEXIST and the new code returned ENOTEMPTY. Injected EACCES passed through in both versions. I checked the parallel guest-kernel mapping in source. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/27771:upstream-pr/27771'
git switch 'upstream-pr/27771'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/27771'
git switch 'upstream-pr/27771'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/27771'
git switch 'upstream-pr/27771'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/27771'
git switch 'main'
git merge --squash 'upstream-pr/27771'
git switch 'main'
git merge --ff-only 'upstream-pr/27771'
git switch 'main'
git merge 'upstream-pr/27771'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!27771
No description provided.