fix(libc): match guest path components case-insensitively on Linux #1079

Closed
johnhumphrys wants to merge 1 commit from upstream-pr/1079 into main
johnhumphrys commented 2026-10-07 09:41:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by johnhumphrys on 2026-10-07T09:41:09Z.


What

Closes #1047. On Linux, ResolvePath now resolves each guest path component against the host directory case-insensitively when the exact name does not exist. Exact names stay on the fast path, and two names that differ only in case fail as before (an exact name is still preferred). Windows is unchanged.

Adds guest_path_case (core/libs/tests/GuestPathCase.cpp): mixed-case files and directories, backslash separators, a Dup.txt/dup.txt pair, and paths that do not exist yet.

Deliberate choices: no directory-listing cache (a stale listing could hide files created later; the cost is one directory scan per exact-name miss, e.g. when creating a file), ASCII-only case folding, and aliased mounts such as /savedata0 are not matched.

Tested

  • Linux (gcc 14, arm64, in a container): GuestPathCase.cpp and General.cpp compiled standalone. The test passes with the change and aborts without it.
  • Not tested: the full CMake/ctest build, x86-64 Linux, Windows, or Demon's Souls itself. guest_working_directory was not run through ctest.

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; no silent stubs
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4770804964 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1079). Originally posted by [johnhumphrys](https://github.com/johnhumphrys) on 2026-10-07T09:41:09Z. --- ### What Closes #1047. On Linux, `ResolvePath` now resolves each guest path component against the host directory case-insensitively when the exact name does not exist. Exact names stay on the fast path, and two names that differ only in case fail as before (an exact name is still preferred). Windows is unchanged. Adds `guest_path_case` (`core/libs/tests/GuestPathCase.cpp`): mixed-case files and directories, backslash separators, a `Dup.txt`/`dup.txt` pair, and paths that do not exist yet. Deliberate choices: no directory-listing cache (a stale listing could hide files created later; the cost is one directory scan per exact-name miss, e.g. when creating a file), ASCII-only case folding, and aliased mounts such as `/savedata0` are not matched. ### Tested - Linux (gcc 14, arm64, in a container): `GuestPathCase.cpp` and `General.cpp` compiled standalone. The test passes with the change and aborts without it. - Not tested: the full CMake/ctest build, x86-64 Linux, Windows, or Demon's Souls itself. `guest_working_directory` was not run through ctest. ### Checklist - [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 - [x] Unimplemented paths throw; no silent stubs - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-07 12:09:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T12:09:41Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#1093 core/libs/prx/libc/src/General.cpp L9, L70-71
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6037597804 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1079#issuecomment-6037597804). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-07T12:09:41Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #1093 | `core/libs/prx/libc/src/General.cpp` [L9](https://github.com/boykopovar/AnyPS5/blob/df16c4c256be3c44e03eb9149a6ce5f8e8a038b2/core/libs/prx/libc/src/General.cpp#L9), [L70-71](https://github.com/boykopovar/AnyPS5/blob/df16c4c256be3c44e03eb9149a6ce5f8e8a038b2/core/libs/prx/libc/src/General.cpp#L70-L71) | | |
fisherjoey commented 2026-10-07 21:09:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-07T21:09:41Z.


I filed #1047 from Demon's Souls (PPSA01341 v1.07), so I can test this where it matters: x86-64 Linux, full CMake/ctest build, and the title itself, which you list as untested. I'll post the results here.

I have a version of the same fix locally (it got the title past the black screen in #1025). Two differences that may be worth discussing:

  • Aliased mounts. Mine resolves the alias first and then matches the remaining components under its host base, so /savedata0/... and other mounted paths are covered too. Demon's Souls only needed /app0, so I can't point to a title that depends on this yet.
  • Listing cache. I cache each directory's listing and revalidate it against the directory's mtime, which covers the stale-listing case you mention. Whether the scan cost matters depends on how often a title misses the exact name. I'll count those misses during the Demon's Souls boot so there's a number to go on.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6046908476 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1079#issuecomment-6046908476). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-07T21:09:41Z. --- I filed #1047 from Demon's Souls (PPSA01341 v1.07), so I can test this where it matters: x86-64 Linux, full CMake/ctest build, and the title itself, which you list as untested. I'll post the results here. I have a version of the same fix locally (it got the title past the black screen in #1025). Two differences that may be worth discussing: - Aliased mounts. Mine resolves the alias first and then matches the remaining components under its host base, so `/savedata0/...` and other mounted paths are covered too. Demon's Souls only needed `/app0`, so I can't point to a title that depends on this yet. - Listing cache. I cache each directory's listing and revalidate it against the directory's mtime, which covers the stale-listing case you mention. Whether the scan cost matters depends on how often a title misses the exact name. I'll count those misses during the Demon's Souls boot so there's a number to go on.
oneandonlydean commented 2026-10-08 05:12:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T05:12:42Z.


guest_path_case aborts on the Windows runner (Exit code 0xc0000409): the case matching is Linux-only, but libc/CMakeLists.txt:142-150 registers the test on every platform. Please register it on Linux only.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6052798692 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1079#issuecomment-6052798692). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-08T05:12:42Z. --- `guest_path_case` aborts on the Windows runner (`Exit code 0xc0000409`): the case matching is Linux-only, but `libc/CMakeLists.txt:142-150` registers the test on every platform. Please register it on Linux only.
blawesom commented 2026-10-08 12:30:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-08T12:30:43Z.

Review: CHANGES_REQUESTED


Verified the implementation against the source and against #1047's design. The ambiguity rule matches what the issue proposed (exact spelling preferred via exists(), ambiguous falls back to the guest spelling and fails at open as before), and the test covers the fixed/relative, mixed-separator, ambiguous and new-file cases. Three things before this can go in; the first two have been raised already and I can confirm them in the code, the third is new.

1. Windows CI is red, and it is a test-semantics problem, not just registration. guest_path_case aborts with 0xc0000409 because on Windows Resolve returns the guest's spelling (the matching is #ifdef __linux__), and the mixed-case assertions compare std::filesystem::path lexically, so e.g. MEDIA/movies/Main_Menu.bk2 can never equal Media/Movies/main_menu.bk2 there. Registering the test on Linux only, as @oneandonlydean suggested, is the right fix — note the Dup.txt/dup.txt fixture also cannot exist on NTFS (the second Touch opens the first file), so making the test cross-platform would need more than an #ifdef around the assertions.

2. Aliased mounts bypass the matching (confirming @fisherjoey, with the line). ResolveAlias returns early (General.cpp:89), and its result joins the guest's remaining components verbatim, so every path under a mounted prefix keeps the old case-sensitive behaviour on Linux. If the fix stays out of ResolveAlias, at least the limitation should be stated in the PR description so nobody spends an evening on a /savedata0 case mismatch.

3. New: the Linux fast path regressed from zero filesystem syscalls to O(depth) stats per resolve — and deep working directories multiply it. MatchHostCase calls exists(result / *component) for every component, including when the guest's spelling is exactly right, which is the overwhelmingly common case. Before this change, Resolve was pure string manipulation. Worse, Resolve builds guest from the whole cwd chain (state.current.lexically_relative(state.root)), so a title running with a deep working directory pays the full walk from state.root on every relative-path resolve, not just per input component.

A single upfront check restores the fast path:

std::error_code error;
if (std::filesystem::exists(base / relative, error)) return base / relative;

as the first line of MatchHostCase. One stat when the spelling is right (which the eventual open would pay anyway), and the per-component walk only runs for actual case misses. It is also compatible with the exact-match preference: exists on the full path is exactly the "exact spelling" case that should win.

Beyond that, two smaller notes:

  • The per-miss directory scan is uncached (fisherjoey's listing-cache point). Whether that matters depends on how often titles probe with wrong case — the upfront check above keeps that off the common path either way.
  • FoldCase is ASCII-only. That matches the console's apparent behaviour for these titles, but it means non-ASCII names won't match across case variants; fine, just worth a line in the description.

And mechanically: the head conflicts with current main (General.cpp has moved ~123 lines since the merge base), so this needs a rebase and a CI rerun before it can be judged.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5456580332 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1079#pullrequestreview-5456580332). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-08T12:30:43Z. **Review:** CHANGES_REQUESTED --- Verified the implementation against the source and against #1047's design. The ambiguity rule matches what the issue proposed (exact spelling preferred via `exists()`, ambiguous falls back to the guest spelling and fails at open as before), and the test covers the fixed/relative, mixed-separator, ambiguous and new-file cases. Three things before this can go in; the first two have been raised already and I can confirm them in the code, the third is new. **1. Windows CI is red, and it is a test-semantics problem, not just registration.** `guest_path_case` aborts with `0xc0000409` because on Windows `Resolve` returns the *guest's* spelling (the matching is `#ifdef __linux__`), and the mixed-case assertions compare `std::filesystem::path` lexically, so e.g. `MEDIA/movies/Main_Menu.bk2` can never equal `Media/Movies/main_menu.bk2` there. Registering the test on Linux only, as @oneandonlydean suggested, is the right fix — note the `Dup.txt`/`dup.txt` fixture also cannot exist on NTFS (the second `Touch` opens the first file), so making the test cross-platform would need more than an `#ifdef` around the assertions. **2. Aliased mounts bypass the matching (confirming @fisherjoey, with the line).** `ResolveAlias` returns early (`General.cpp:89`), and its result joins the guest's remaining components verbatim, so every path under a mounted prefix keeps the old case-sensitive behaviour on Linux. If the fix stays out of `ResolveAlias`, at least the limitation should be stated in the PR description so nobody spends an evening on a `/savedata0` case mismatch. **3. New: the Linux fast path regressed from zero filesystem syscalls to O(depth) stats per resolve — and deep working directories multiply it.** `MatchHostCase` calls `exists(result / *component)` for **every** component, including when the guest's spelling is exactly right, which is the overwhelmingly common case. Before this change, `Resolve` was pure string manipulation. Worse, `Resolve` builds `guest` from the whole cwd chain (`state.current.lexically_relative(state.root)`), so a title running with a deep working directory pays the full walk from `state.root` on *every relative-path resolve*, not just per input component. A single upfront check restores the fast path: ```cpp std::error_code error; if (std::filesystem::exists(base / relative, error)) return base / relative; ``` as the first line of `MatchHostCase`. One stat when the spelling is right (which the eventual `open` would pay anyway), and the per-component walk only runs for actual case misses. It is also compatible with the exact-match preference: `exists` on the full path is exactly the "exact spelling" case that should win. Beyond that, two smaller notes: - The per-miss directory scan is uncached (fisherjoey's listing-cache point). Whether that matters depends on how often titles probe with wrong case — the upfront check above keeps that off the common path either way. - `FoldCase` is ASCII-only. That matches the console's apparent behaviour for these titles, but it means non-ASCII names won't match across case variants; fine, just worth a line in the description. And mechanically: the head conflicts with current `main` (`General.cpp` has moved ~123 lines since the merge base), so this needs a rebase and a CI rerun before it can be judged.
adriadam10 commented 2026-10-08 12:37:59 +00:00 (Migrated from github.com)

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


Closing in favour of #1321, which covers the same case-insensitive path resolution (same function and test file) on both Linux and Windows, prefers exact matches and rejects ambiguous names. Thanks for the work here; if something this PR handled is missing from #1321, please say so there.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6060033420 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1079#issuecomment-6060033420). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T12:37:59Z. --- Closing in favour of #1321, which covers the same case-insensitive path resolution (same function and test file) on both Linux and Windows, prefers exact matches and rejects ambiguous names. Thanks for the work here; if something this PR handled is missing from #1321, please say so there.
fisherjoey commented 2026-10-08 14:40:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T14:40:07Z.


These are the results I said I'd post. This PR was closed in favour of #1321 while they were running, so they're mostly for the record.

Setup: Nobara (Fedora 44) x86-64, RTX 5070 Ti, NVIDIA 595.91.07, gcc 16.2.1. This PR (7be744b2) merged onto main df16c4c2 without conflicts.

ctest, run serially (-j1 --timeout 60) in the same build directory for both:

main main + this PR
as is 307/408 308/409
with the dma-buf probe off on NVIDIA (#1329) 407/408 408/409

The 101 failures are the dma-buf import probe from #943 poisoning the device on this driver; #1329 has since fixed that on main. With it, the only failure on both builds is guest_force_tls_destructor, which predates this PR, and guest_path_case passes.

Demon's Souls (PPSA01341 v1.07), with my local case fix removed and this PR applied: the title opens /app0/packagecmdlineargs.txt, the PR finds PackageCmdLineArgs.txt, and the boot gets past the black screen from #1025. The logo and attract movie play until I stopped it at 250 s. Of 33,091 host opens under app0, none failed. A mixed-case /app0\Movies\Main_Menu.bk2 resolves to movies/main_menu.bk2.

Over a full boot through the new-game intro, the exact name misses once (the args file), plus once for the new log file under /hostapp/logs. On an existing path the per-component check costs about 4 stats per lookup (~100 us on my NTFS fuse mount, ~1.3 us on main), which adds up to a few ms per boot. I don't think a directory listing cache is worth it for this title, so I've dropped mine.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6062319825 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1079#issuecomment-6062319825). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-08T14:40:07Z. --- These are the results I said I'd post. This PR was closed in favour of #1321 while they were running, so they're mostly for the record. Setup: Nobara (Fedora 44) x86-64, RTX 5070 Ti, NVIDIA 595.91.07, gcc 16.2.1. This PR (7be744b2) merged onto `main` df16c4c2 without conflicts. ctest, run serially (`-j1 --timeout 60`) in the same build directory for both: | | main | main + this PR | |---|---|---| | as is | 307/408 | 308/409 | | with the dma-buf probe off on NVIDIA (#1329) | 407/408 | 408/409 | The 101 failures are the dma-buf import probe from #943 poisoning the device on this driver; #1329 has since fixed that on `main`. With it, the only failure on both builds is `guest_force_tls_destructor`, which predates this PR, and `guest_path_case` passes. Demon's Souls (PPSA01341 v1.07), with my local case fix removed and this PR applied: the title opens `/app0/packagecmdlineargs.txt`, the PR finds `PackageCmdLineArgs.txt`, and the boot gets past the black screen from #1025. The logo and attract movie play until I stopped it at 250 s. Of 33,091 host opens under `app0`, none failed. A mixed-case `/app0\Movies\Main_Menu.bk2` resolves to `movies/main_menu.bk2`. Over a full boot through the new-game intro, the exact name misses once (the args file), plus once for the new log file under `/hostapp/logs`. On an existing path the per-component check costs about 4 stats per lookup (~100 us on my NTFS fuse mount, ~1.3 us on `main`), which adds up to a few ms per boot. I don't think a directory listing cache is worth it for this title, so I've dropped mine. AI-assisted: yes

Pull request closed

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!1079
No description provided.