fix(filesystem): remove unreadable empty dirs #23799

Merged
DonRyuzaki merged 1 commit from upstream-pr/23799 into main 2026-11-21 20:02:24 +00:00
DonRyuzaki commented 2026-11-19 17:20:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DonRyuzaki on 2026-11-19T17:20:23Z.


What

Let POSIX rmdir decide whether an empty directory can be removed through both the direct rmdir export and directory-relative unlinkat(..., AT_REMOVEDIR). A nonroot caller can remove an empty mode-000 directory from a writable parent, but the old directory-read prechecks returned guest ENOTEMPTY. Windows retains its upstream empty-directory prechecks and the POSIX paths preserve host errno mapping.

This is a generic filesystem correction. No title or console behavior is claimed.

Tested

  • Ubuntu 24.04 WSL2, GCC 13.3, Release, nonroot: rebuilt guest_kernel_sys_tests and guest_filesystem_tests on the rebased tree; both CTest cases passed. The native rmdir control plus direct and directory-relative guest regression run in guest_kernel_sys. The original-head negative control, with production code reverted and the regression kept, failed with guest errno 66 (ENOTEMPTY).
  • Windows, WinLibs GCC 15.2, Release: rebuilt guest_kernel_sys_tests and guest_filesystem_tests after rebasing; both CTest cases passed with host filesystem access. The restricted shell blocked unrelated hard-link and junction fixtures, so those runs are not counted.
  • Rebased onto current upstream main after #24114, #24130, and #24149 merged. Resolved their adjacent GuestKernelSys.cpp and libkernel_sys/Export.cpp changes by preserving the Windows tests and empty-directory guard. tools/check_conventions.py, git diff --check, and git merge-tree --write-tree upstream/main HEAD passed.
  • tools/debt_fold.py --check reports two pre-existing, duplicate libkernel clock fragments on current main (fix-libkernel-clock-id-15.md and docs-libkernel-clock-gettime-1360-divergence.md). This PR changes no debt fragments.
  • Full tools/pr_overlap.py --branch scan fetched 2,278 open heads and probed 2,277 other PRs. No confirmed same-function implementation. The tool could not auto-compare 12 stale branches that already conflict with main; their shared-file patches were manually read. #18190 wraps rmdir without changing removal behavior, and newly opened #24641 changes futimes in the same file. The other patches concern separate functions or tests.

Checklist

  • Based on current main; no other open PR implements the same function fix
  • 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
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none measured
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5399662662 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23799). Originally posted by [DonRyuzaki](https://github.com/DonRyuzaki) on 2026-11-19T17:20:23Z. --- ### What Let POSIX `rmdir` decide whether an empty directory can be removed through both the direct `rmdir` export and directory-relative `unlinkat(..., AT_REMOVEDIR)`. A nonroot caller can remove an empty mode-000 directory from a writable parent, but the old directory-read prechecks returned guest `ENOTEMPTY`. Windows retains its upstream empty-directory prechecks and the POSIX paths preserve host errno mapping. This is a generic filesystem correction. No title or console behavior is claimed. ### Tested - Ubuntu 24.04 WSL2, GCC 13.3, Release, nonroot: rebuilt `guest_kernel_sys_tests` and `guest_filesystem_tests` on the rebased tree; both CTest cases passed. The native `rmdir` control plus direct and directory-relative guest regression run in `guest_kernel_sys`. The original-head negative control, with production code reverted and the regression kept, failed with guest errno 66 (`ENOTEMPTY`). - Windows, WinLibs GCC 15.2, Release: rebuilt `guest_kernel_sys_tests` and `guest_filesystem_tests` after rebasing; both CTest cases passed with host filesystem access. The restricted shell blocked unrelated hard-link and junction fixtures, so those runs are not counted. - Rebased onto current upstream main after #24114, #24130, and #24149 merged. Resolved their adjacent `GuestKernelSys.cpp` and `libkernel_sys/Export.cpp` changes by preserving the Windows tests and empty-directory guard. `tools/check_conventions.py`, `git diff --check`, and `git merge-tree --write-tree upstream/main HEAD` passed. - `tools/debt_fold.py --check` reports two pre-existing, duplicate libkernel clock fragments on current `main` (`fix-libkernel-clock-id-15.md` and `docs-libkernel-clock-gettime-1360-divergence.md`). This PR changes no debt fragments. - Full `tools/pr_overlap.py --branch` scan fetched 2,278 open heads and probed 2,277 other PRs. No confirmed same-function implementation. The tool could not auto-compare 12 stale branches that already conflict with main; their shared-file patches were manually read. #18190 wraps `rmdir` without changing removal behavior, and newly opened #24641 changes `futimes` in the same file. The other patches concern separate functions or tests. ### Checklist - [x] Based on current `main`; no other open PR implements the same function fix - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt 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 file - [x] No notes, investigation `.md` files or images added to the repository - [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 measured - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-19 17:47:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-19T17:47:05Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 712153d5b7:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_kernel_sys_tests built cleanly.
  • CTest (guest_kernel_sys):
    1/1 Test #944: guest_kernel_sys .................   Passed    0.12 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libkernel/File/src/Stdio.cpp, core/libs/prx/libkernel_sys/Export.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #944: guest_kernel_sys .................Subprocess aborted***Exception:   0.60 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • core/libs/prx/libkernel/File/src/Stdio.cpp: verified sceKernelRmdir now invokes NativeRmdir directly on POSIX and maps host errno via SceErrorFromErrno(errno), while keeping IsDirectoryEmpty precheck and RemoveEmptyDirectory on Windows.
    • core/libs/prx/libkernel_sys/Export.cpp: verified unlinkat_nid_postfix delegates directory emptiness and removal to POSIX rmdir/unlinkat semantics on POSIX platforms, gating std::filesystem::is_empty behind #ifdef _WIN32.
    • core/libs/tests/GuestKernelSys.cpp: verified CheckUnreadableEmptyRmdir tests permission perms::none on empty directory for native rmdir, direct rmdir_nid_postfix, and directory-relative unlinkat_nid_postfix(..., 0x800).
    • Error handling and AGENTS.md rules: verified no banned comments added, conventional commit format adhered to, and no title-specific workarounds or stubs introduced.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5980336963 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23799#pullrequestreview-5980336963). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-19T17:47:05Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `712153d5b7`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_kernel_sys_tests` built cleanly. - **CTest** (`guest_kernel_sys`): ``` 1/1 Test #944: guest_kernel_sys ................. Passed 0.12 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libkernel/File/src/Stdio.cpp`, `core/libs/prx/libkernel_sys/Export.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #944: guest_kernel_sys .................Subprocess aborted***Exception: 0.60 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - core/libs/prx/libkernel/File/src/Stdio.cpp: verified sceKernelRmdir now invokes NativeRmdir directly on POSIX and maps host errno via SceErrorFromErrno(errno), while keeping IsDirectoryEmpty precheck and RemoveEmptyDirectory on Windows. - core/libs/prx/libkernel_sys/Export.cpp: verified unlinkat_nid_postfix delegates directory emptiness and removal to POSIX rmdir/unlinkat semantics on POSIX platforms, gating std::filesystem::is_empty behind #ifdef _WIN32. - core/libs/tests/GuestKernelSys.cpp: verified CheckUnreadableEmptyRmdir tests permission perms::none on empty directory for native rmdir, direct rmdir_nid_postfix, and directory-relative unlinkat_nid_postfix(..., 0x800). - Error handling and AGENTS.md rules: verified no banned comments added, conventional commit format adhered to, and no title-specific workarounds or stubs introduced. Looks Good To Me
MarcZX10 commented 2026-11-20 22:28:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T22:28:12Z.

Review: APPROVED


Reviewed — looks good

The reviewed change is sound at head 712153d5b72aeecd5179a03dd11815520d22faf8; the available evidence supports merging.

What I ran

No commands were run. I read the prepared review bundle and the relevant source ranges through repo_read.py at the pinned head. The author reports passing Linux tests and convention checks, plus a Windows compile; those results were not independently run here.

Results

Check Result Note
Code review passed All changed files read
Tests and builds not run Author-reported results only

Findings

Blocking

None.

Non-blocking

None.

Sources

The POSIX direct rmdir path now delegates removal and errno mapping to the host call (core/libs/prx/libkernel/File/src/Stdio.cpp:2041). The directory-relative unlinkat(..., AT_REMOVEDIR) path likewise calls host rmdir, preserving its existing guest error conversion (core/libs/prx/libkernel_sys/Export.cpp:1190). The added regression covers native, direct, and directory-relative removal of unreadable empty directories (core/libs/tests/GuestKernelSys.cpp:1437).

Not verified

I did not run tests or builds and did not independently verify the author-reported outcomes. The review bundle contained no excluded changed files; all three changed files in the manifest were read. files.json was not available as a review document; the changed-file inventory came from manifest.json and the review-folder listing.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6000226769 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23799#pullrequestreview-6000226769). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T22:28:12Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed change is sound at head `712153d5b72aeecd5179a03dd11815520d22faf8`; the available evidence supports merging. ## What I ran No commands were run. I read the prepared review bundle and the relevant source ranges through `repo_read.py` at the pinned head. The author reports passing Linux tests and convention checks, plus a Windows compile; those results were not independently run here. ## Results | Check | Result | Note | |---|---|---| | Code review | passed | All changed files read | | Tests and builds | not run | Author-reported results only | ## Findings ### Blocking None. ### Non-blocking None. ## Sources The POSIX direct `rmdir` path now delegates removal and errno mapping to the host call (`core/libs/prx/libkernel/File/src/Stdio.cpp:2041`). The directory-relative `unlinkat(..., AT_REMOVEDIR)` path likewise calls host `rmdir`, preserving its existing guest error conversion (`core/libs/prx/libkernel_sys/Export.cpp:1190`). The added regression covers native, direct, and directory-relative removal of unreadable empty directories (`core/libs/tests/GuestKernelSys.cpp:1437`). ## Not verified I did not run tests or builds and did not independently verify the author-reported outcomes. The review bundle contained no excluded changed files; all three changed files in the manifest were read. `files.json` was not available as a review document; the changed-file inventory came from `manifest.json` and the review-folder listing. ## To get this to a good state Nothing is required.
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!23799
No description provided.