fix(hle): fix verbatim/UNC/drive-root virtual path translation and GetDiskFreeSpaceW volume roots #3361

Open
reeledMarek wants to merge 3 commits from upstream-pr/3361 into main
reeledMarek commented 2026-11-26 20:25:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-26T20:25:47Z.


Summary

  • When a title passed a \\?\ verbatim virtual-drive path (e.g. \\?\G:\...), translate blindly prepended \\?\ to the mounted host root, producing invalid paths for UNC mounts (\\?\\\server\share\... instead of \\?\UNC\server\share\...), already-verbatim mounts (\\?\\\?\...), and drive-root mounts (\\?\D:\\foo or D:\\foo).
  • Factors verbatim_root and join_host_path so verbatim, UNC, and drive-root mounts join cleanly without duplicate prefixes or doubled backslashes.
  • Extracts volume_root for GetDiskFreeSpaceW so \\?\C:\..., \\?\UNC\server\share\..., and \\server\share\... translated host paths are trimmed to a valid volume root instead of passing a subdirectory.
  • Adds unit tests verbatim_and_drive_root_mounts_join_cleanly and volume_root_handles_drive_verbatim_and_unc_paths.

Verification

  • cargo clippy -p victory-hle --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings
  • cargo test -p xtask --locked
<!-- greyfinch-sync:Marvisak/VIctory:issue:5516696314 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3361). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-26T20:25:47Z. --- ### Summary - When a title passed a `\\?\` verbatim virtual-drive path (e.g. `\\?\G:\...`), `translate` blindly prepended `\\?\` to the mounted host `root`, producing invalid paths for UNC mounts (`\\?\\\server\share\...` instead of `\\?\UNC\server\share\...`), already-verbatim mounts (`\\?\\\?\...`), and drive-root mounts (`\\?\D:\\foo` or `D:\\foo`). - Factors `verbatim_root` and `join_host_path` so verbatim, UNC, and drive-root mounts join cleanly without duplicate prefixes or doubled backslashes. - Extracts `volume_root` for `GetDiskFreeSpaceW` so `\\?\C:\...`, `\\?\UNC\server\share\...`, and `\\server\share\...` translated host paths are trimmed to a valid volume root instead of passing a subdirectory. - Adds unit tests `verbatim_and_drive_root_mounts_join_cleanly` and `volume_root_handles_drive_verbatim_and_unc_paths`. ### Verification - `cargo clippy -p victory-hle --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings` - `cargo test -p xtask --locked`
Dukestar69 commented 2026-11-26 20:27:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T20:27:38Z.

Review: APPROVED


LGTM — verified on Windows against origin/main (63bcca4).

  • Handling verbatim (\\?\), UNC (\\?\UNC\... / \\server\share), and drive-root mounts cleanly in virtual path translation and GetDiskFreeSpaceW volume root extraction is well-tested and avoids malformed path joins.
  • cargo test -p victory-hle --lib modules::files:: -- --test-threads=1: 8 passed, 0 failed (including verbatim_and_drive_root_mounts_join_cleanly and volume_root_handles_drive_verbatim_and_unc_paths).
  • cargo clippy -p victory-hle --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6080153870 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3361#pullrequestreview-6080153870). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T20:27:38Z. **Review:** APPROVED --- LGTM — verified on Windows against `origin/main` (`63bcca4`). - Handling verbatim (`\\?\`), UNC (`\\?\UNC\...` / `\\server\share`), and drive-root mounts cleanly in virtual path translation and `GetDiskFreeSpaceW` volume root extraction is well-tested and avoids malformed path joins. - `cargo test -p victory-hle --lib modules::files:: -- --test-threads=1`: 8 passed, 0 failed (including `verbatim_and_drive_root_mounts_join_cleanly` and `volume_root_handles_drive_verbatim_and_unc_paths`). - `cargo clippy -p victory-hle --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal commented 2026-11-26 20:54:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T20:54:56Z.

Review: APPROVED


LGTM — verbatim_root, join_host_path, and volume_root cleanly resolve the \?\, \?\UNC\, and drive-root joining edge cases and extract volume roots for GetDiskFreeSpaceW.

Verified

  • cargo run --locked -p xtask -- policy: 191 files ok.
  • cargo clippy --locked -p victory-hle --all-targets -- -D warnings (default & --all-features): clean.
  • cargo test --locked -p victory-hle --lib modules::files:: -- --test-threads=1: 8 passed, 0 failed (including verbatim_and_drive_root_mounts_join_cleanly and volume_root_handles_drive_verbatim_and_unc_paths).
  • cargo test --locked -p victory-hle --all-targets -- --test-threads=1: 154 lib + 2 integration tests passed, 0 failed.

Minor non-blocking nits

  • crates/victory-hle/src/modules/files.rs:150: if out.last() == Some(&u16::from(b':')) runs after appending parts; guarding it with parts.is_empty() limits the trailing \ strictly to empty-tail drive roots rather than a colon-suffixed guest component.
  • Pre-existing join_host_path behavior (files.rs:164, 179): / -> \ normalization checks !prefix.is_empty() rather than whether out starts with \?\ (so a short non-verbatim guest path on a \?\ mount keeps /), and short non-verbatim paths still rely on Windows path resolution for ...
  • rustfmt --edition 2024 reports one formatting diff in the new test at files.rs:1046.
<!-- greyfinch-sync:Marvisak/VIctory:review:6080387540 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3361#pullrequestreview-6080387540). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T20:54:56Z. **Review:** APPROVED --- LGTM — `verbatim_root`, `join_host_path`, and `volume_root` cleanly resolve the `\?\`, `\?\UNC\`, and drive-root joining edge cases and extract volume roots for `GetDiskFreeSpaceW`. ### Verified - `cargo run --locked -p xtask -- policy`: `191 files ok`. - `cargo clippy --locked -p victory-hle --all-targets -- -D warnings` (default & `--all-features`): clean. - `cargo test --locked -p victory-hle --lib modules::files:: -- --test-threads=1`: **8 passed, 0 failed** (including `verbatim_and_drive_root_mounts_join_cleanly` and `volume_root_handles_drive_verbatim_and_unc_paths`). - `cargo test --locked -p victory-hle --all-targets -- --test-threads=1`: **154 lib + 2 integration tests passed, 0 failed**. ### Minor non-blocking nits - `crates/victory-hle/src/modules/files.rs:150`: `if out.last() == Some(&u16::from(b':'))` runs after appending `parts`; guarding it with `parts.is_empty()` limits the trailing `\` strictly to empty-tail drive roots rather than a colon-suffixed guest component. - Pre-existing `join_host_path` behavior (`files.rs:164, 179`): `/` -> `\` normalization checks `!prefix.is_empty()` rather than whether `out` starts with `\?\` (so a short non-verbatim guest path on a `\?\` mount keeps `/`), and short non-verbatim paths still rely on Windows path resolution for `..`. - `rustfmt --edition 2024` reports one formatting diff in the new test at `files.rs:1046`.
reeledMarek commented 2026-11-26 21:04:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-26T21:04:26Z.


Thanks for the thorough review @fuzeofficlal! Pushed 60296b7 to guard the trailing \ in verbatim() with parts.is_empty() (with a regression test covering both an empty-tail drive root and a colon-suffixed component) and fixed the rustfmt formatting line.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7203362198 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3361#issuecomment-7203362198). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-26T21:04:26Z. --- Thanks for the thorough review @fuzeofficlal! Pushed `60296b7` to guard the trailing `\` in `verbatim()` with `parts.is_empty()` (with a regression test covering both an empty-tail drive root and a colon-suffixed component) and fixed the `rustfmt` formatting line.
passerbyyhx commented 2026-11-26 22:34:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by passerbyyhx on 2026-11-26T22:34:47Z.


Windows 11 check at 60296b7 against 63bcca4 using a synthetic file on a real D: volume. I mounted a subdirectory and the drive root, both with and without the host verbatim prefix, then exercised all four guest prefix/separator forms through the HLE file and volume entry points.

  • HLE GetDiskFreeSpaceW improved from 10/16 to 16/16. All four outputs matched both adjacent native calls on the root returned by GetVolumePathNameW.
  • HLE CreateFileW/ReadFile improved from 10/16 to 14/16. Both auto-verbatim long paths succeeded on both revisions.
  • The two remaining file cases used ordinary guest X:/... with an already-verbatim host mount. The folder case produced \\?\D:\...\nested/probe.bin and returned 123. The drive-root case produced \\?\D:/... and returned 2. The same targets both opened through the guest verbatim \\?\X:/... form, and both ordinary-slash disk queries succeeded on head.

The focused files suite passed 7/7 on the parent and 9/9 on head. Live network shares were outside this run. Synthetic fixture

AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7204804109 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3361#issuecomment-7204804109). Originally posted by [passerbyyhx](https://github.com/passerbyyhx) on 2026-11-26T22:34:47Z. --- Windows 11 check at `60296b7` against `63bcca4` using a synthetic file on a real D: volume. I mounted a subdirectory and the drive root, both with and without the host verbatim prefix, then exercised all four guest prefix/separator forms through the HLE file and volume entry points. - HLE `GetDiskFreeSpaceW` improved from 10/16 to 16/16. All four outputs matched both adjacent native calls on the root returned by `GetVolumePathNameW`. - HLE `CreateFileW`/`ReadFile` improved from 10/16 to 14/16. Both auto-verbatim long paths succeeded on both revisions. - The two remaining file cases used ordinary guest `X:/...` with an already-verbatim host mount. The folder case produced `\\?\D:\...\nested/probe.bin` and returned 123. The drive-root case produced `\\?\D:/...` and returned 2. The same targets both opened through the guest verbatim `\\?\X:/...` form, and both ordinary-slash disk queries succeeded on head. The focused files suite passed 7/7 on the parent and 9/9 on head. Live network shares were outside this run. [Synthetic fixture](https://github.com/passerbyyhx/VIctory/commit/c4d1da5034a5c82474e60803d724faf00a58bf00) AI-assisted with Codex.
passerbyyhx commented 2026-11-27 09:12:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by passerbyyhx on 2026-11-27T09:12:13Z.


I sent a small fix against this PR's branch for the two ordinary slash paths on verbatim host mounts. On the same Windows matrix, the file reads now pass 16/16 (previously 14/16), with 16/16 volume queries and both long paths passing. AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7214400400 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3361#issuecomment-7214400400). Originally posted by [passerbyyhx](https://github.com/passerbyyhx) on 2026-11-27T09:12:13Z. --- I sent a [small fix against this PR's branch](https://github.com/reeledMarek/VIctory/pull/1) for the two ordinary slash paths on verbatim host mounts. On the same Windows matrix, the file reads now pass 16/16 (previously 14/16), with 16/16 volume queries and both long paths passing. AI-assisted with Codex.
reeledMarek commented 2026-11-27 17:13:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-27T17:13:30Z.


Thanks for testing the full Windows matrix and sending the fix @passerbyyhx! Merged reeledMarek/VIctory#1 into this branch.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7224167372 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3361#issuecomment-7224167372). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-27T17:13:30Z. --- Thanks for testing the full Windows matrix and sending the fix @passerbyyhx! Merged `reeledMarek/VIctory#1` into this branch.
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/3361:upstream-pr/3361'
git switch 'upstream-pr/3361'

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/3361'
git switch 'upstream-pr/3361'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3361'
git switch 'upstream-pr/3361'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3361'
git switch 'main'
git merge --squash 'upstream-pr/3361'
git switch 'main'
git merge --ff-only 'upstream-pr/3361'
git switch 'main'
git merge 'upstream-pr/3361'
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
Marvisak/VIctory!3361
No description provided.