fix(libc): keep a trailing slash on paths under a mount alias #4681

Merged
milescoviello merged 1 commit from upstream-pr/4681 into main 2026-10-14 04:25:16 +00:00
milescoviello commented 2026-10-12 18:56:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-12T18:56:31Z.


What

Guest path resolution trimmed the trailing slash of a path under a mount alias (/savedata0, /download0, /app0 and the others), so the host saw file for file/. On main, with a regular file f under an alias:

call on <alias>/f/ main FreeBSD 11.4, and the same path outside an alias
unlink, remove, sceKernelUnlink 0, the file is deleted ENOTDIR
rename("f/", "g") 0, the file is moved ENOTDIR
open(O_RDONLY) a descriptor for the file ENOTDIR
chmod, access 0 ENOTDIR

FreeBSD 11.4 rejects it in lookup() (sys/kern/vfs_lookup.c):

	/*
	 * If we're processing a path with a trailing slash,
	 * check that the end result is a directory.
	 */
	if ((cnp->cn_flags & TRAILINGSLASH) && dp->v_type != VDIR) {
		error = ENOTDIR;
		goto bad2;
	}

#2300 made stat follow this; the other calls still acted on the file because ResolveAlias drops the slash before the host sees it, while a path outside an alias keeps it.

On Linux and macOS a path under an alias now keeps its trailing slash on the host path, exactly as paths outside an alias already do, so the host fails with ENOTDIR for a file while directories with a trailing slash (stat, mkdir, rmdir) keep working. Windows keeps the previous behaviour, since its trailing-separator handling differs (#4513) and I could not test it; an entry in docs/dev/debt/libc.md records that.

Tested

Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on main 1acfa7f7. guest_filesystem gained checks under its parent-test-mount alias: unlink, remove, rename, open and sceKernelUnlink on file/ fail with ENOTDIR and every file is still there, stat of Existing/ reports a directory, and mkdir/rmdir of slash-directory/ work.

  • Red: with main's General.cpp the test fails at the first new check (unlink returns 0 and deletes the file).
  • Green: guest_filesystem passes, also in 30 repeated runs; all guest_* tests except guest_video_out_* pass (310/310, two runs).

Windows: @johnmaia built and ran it on Windows 11 with WinLibs GCC 15.2.0, merged into main 3faa9cb40. The full suite passes 1074 of 1074, guest_filesystem included. The new checks are skipped there, so this shows only that nothing else changes on Windows.

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
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • 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
  • Unblocks: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4833731161 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4681). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-12T18:56:31Z. --- ### What Guest path resolution trimmed the trailing slash of a path under a mount alias (`/savedata0`, `/download0`, `/app0` and the others), so the host saw `file` for `file/`. On `main`, with a regular file `f` under an alias: | call on `<alias>/f/` | `main` | FreeBSD 11.4, and the same path outside an alias | |---|---|---| | `unlink`, `remove`, `sceKernelUnlink` | 0, the file is deleted | `ENOTDIR` | | `rename("f/", "g")` | 0, the file is moved | `ENOTDIR` | | `open(O_RDONLY)` | a descriptor for the file | `ENOTDIR` | | `chmod`, `access` | 0 | `ENOTDIR` | FreeBSD 11.4 rejects it in `lookup()` (`sys/kern/vfs_lookup.c`): ```c /* * If we're processing a path with a trailing slash, * check that the end result is a directory. */ if ((cnp->cn_flags & TRAILINGSLASH) && dp->v_type != VDIR) { error = ENOTDIR; goto bad2; } ``` #2300 made `stat` follow this; the other calls still acted on the file because `ResolveAlias` drops the slash before the host sees it, while a path outside an alias keeps it. On Linux and macOS a path under an alias now keeps its trailing slash on the host path, exactly as paths outside an alias already do, so the host fails with `ENOTDIR` for a file while directories with a trailing slash (`stat`, `mkdir`, `rmdir`) keep working. Windows keeps the previous behaviour, since its trailing-separator handling differs (#4513) and I could not test it; an entry in `docs/dev/debt/libc.md` records that. ### Tested Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on `main` 1acfa7f7. `guest_filesystem` gained checks under its `parent-test-mount` alias: `unlink`, `remove`, `rename`, `open` and `sceKernelUnlink` on `file/` fail with `ENOTDIR` and every file is still there, `stat` of `Existing/` reports a directory, and `mkdir`/`rmdir` of `slash-directory/` work. - Red: with `main`'s `General.cpp` the test fails at the first new check (`unlink` returns 0 and deletes the file). - Green: `guest_filesystem` passes, also in 30 repeated runs; all `guest_*` tests except `guest_video_out_*` pass (310/310, two runs). Windows: @johnmaia [built and ran it](https://github.com/boykopovar/AnyPS5/pull/4681#issuecomment-6146815591) on Windows 11 with WinLibs GCC 15.2.0, merged into `main` 3faa9cb40. The full suite passes 1074 of 1074, `guest_filesystem` included. The new checks are skipped there, so this shows only that nothing else changes on Windows. ### 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) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] Unblocks: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
johnmaia commented 2026-10-13 13:37:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-13T13:37:00Z.


Windows build check. Setup: Windows 11 (26300), WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON, ctest -j4 --timeout 300, RTX 4080. Head 516e90d8d merged into main 3faa9cb40.

It builds, and the full suite passes 1074 of 1074, guest_filesystem included. The new trailing-slash checks are #ifndef _WIN32, so this only shows that nothing else changes on Windows.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6146815591 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4681#issuecomment-6146815591). Originally posted by [johnmaia](https://github.com/johnmaia) on 2026-10-13T13:37:00Z. --- Windows build check. Setup: Windows 11 (26300), WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`, `ctest -j4 --timeout 300`, RTX 4080. Head 516e90d8d merged into `main` 3faa9cb40. It builds, and the full suite passes 1074 of 1074, `guest_filesystem` included. The new trailing-slash checks are `#ifndef _WIN32`, so this only shows that nothing else changes on Windows. AI-assisted: yes (Claude Code)
adriadam10 commented 2026-10-13 14:59:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:59:08Z.


Checked the build and scoped ctest on the PR merged onto main, guest_filesystem repeated 5 times, and that the new checks fail with ResolveAlias reverted to main. The Windows runs by @johnmaia and @xXPBSXx confirm nothing else changes there. Merging after the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148485867 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4681#issuecomment-6148485867). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T14:59:08Z. --- Checked the build and scoped ctest on the PR merged onto main, `guest_filesystem` repeated 5 times, and that the new checks fail with `ResolveAlias` reverted to main. The Windows runs by @johnmaia and @xXPBSXx confirm nothing else changes there. Merging after the full Build is green.
milescoviello commented 2026-10-14 01:34:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-14T01:34:02Z.


Rebased onto main 34355eeea. The only conflict was docs/dev/debt/libc.md, next to the new tzname entry; both entries are kept. After the rebase, the build is clean, guest_filesystem passes 5/5 and all 354 guest_* tests pass (Ubuntu 24.04, GCC 13.3, Release).

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6158897947 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4681#issuecomment-6158897947). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-14T01:34:02Z. --- Rebased onto `main` 34355eeea. The only conflict was `docs/dev/debt/libc.md`, next to the new `tzname` entry; both entries are kept. After the rebase, the build is clean, `guest_filesystem` passes 5/5 and all 354 `guest_*` tests pass (Ubuntu 24.04, GCC 13.3, Release). AI-assisted: yes
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!4681
No description provided.