VFS: preserve whiteouts when CreateFile fails on a deleted game file #1362

Open
github-bot wants to merge 1 commit from github-bot/gh-1362 into main AGit
Owner

@⁠b3IKK on GitHub · 2026-11-24 15:12 UTC · original
b3IKK:vfs/preserve-whiteout-on-failed-create → main · +133 −27 · 2 files · 1 commits · open

open_decision_for called prepare_write before CreateFileW / CreateFileA / CreateFile2 ran, eagerly clearing any whiteout on the target path. If the underlying CreateFile* call then failed (e.g. sharing violation, invalid flags/attributes, or ERROR_ACCESS_DENIED), no overlay file was created yet the whiteout was already gone—resurrecting the deleted original game file.

This adds prepare_write_staged and open_decision_staged / open_decision_staged_for (following the existing stage_write / commit_write pattern from d903a80) and has apply_open_decision call commit_write only after CreateFile* returns a valid handle, while saving and restoring GetLastError() across commit_write's whiteout persistence I/O so statuses like ERROR_ALREADY_EXISTS are not clobbered.

What is in it

  • crates/xcl/src/vfs.rs: split prepare_write_staged out of prepare_write and open_decision_staged_for / open_decision_staged out of open_decision_for so callers can defer commit_write until the file open succeeds.
  • crates/xcl/src/vfs_hooks.rs: pass staged decisions from hk_create_file_w, hk_create_file_a, and hk_create_file_2 into apply_open_decision, committing only on handle != INVALID_HANDLE_VALUE while preserving GetLastError(); add unit test failed_create_file_preserves_whiteout_and_last_error.

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 752 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 no wave64 — gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)
  • cargo test -p xcl --lib vfs: 23 passed, 0 failed

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1226 (PresentX 1226)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15341 MB

PR:

xcl-smoke v1
commit: b69731e6588009fb25c840a76594469b129ea3fd
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1643 (PresentX 1643)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14597 MB

Not tested

  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Gemini 4 Neon: audited vfs.rs and vfs_hooks.rs, wrote the staged open fix and unit test, ran the test suite and scripts/smoke.ps1 regression runs, and drafted this PR description.
**@⁠b3IKK** on GitHub · 2026-11-24 15:12 UTC · [original](https://github.com/xcl-dev/xcl/pull/1362) `b3IKK:vfs/preserve-whiteout-on-failed-create` → `main` · +133 −27 · 2 files · 1 commits · open `open_decision_for` called `prepare_write` before `CreateFileW` / `CreateFileA` / `CreateFile2` ran, eagerly clearing any whiteout on the target path. If the underlying `CreateFile*` call then failed (e.g. sharing violation, invalid flags/attributes, or `ERROR_ACCESS_DENIED`), no overlay file was created yet the whiteout was already gone—resurrecting the deleted original game file. This adds `prepare_write_staged` and `open_decision_staged` / `open_decision_staged_for` (following the existing `stage_write` / `commit_write` pattern from `d903a80`) and has `apply_open_decision` call `commit_write` only after `CreateFile*` returns a valid handle, while saving and restoring `GetLastError()` across `commit_write`'s whiteout persistence I/O so statuses like `ERROR_ALREADY_EXISTS` are not clobbered. **What is in it** - `crates/xcl/src/vfs.rs`: split `prepare_write_staged` out of `prepare_write` and `open_decision_staged_for` / `open_decision_staged` out of `open_decision_for` so callers can defer `commit_write` until the file open succeeds. - `crates/xcl/src/vfs_hooks.rs`: pass staged decisions from `hk_create_file_w`, `hk_create_file_a`, and `hk_create_file_2` into `apply_open_decision`, committing only on `handle != INVALID_HANDLE_VALUE` while preserving `GetLastError()`; add unit test `failed_create_file_preserves_whiteout_and_last_error`. **Tested** - hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`), DXC 1.9.2609.5, debug (`scripts/test.ps1`) and release (`scripts/smoke.ps1`) - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`): 752 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 `no wave64` — `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware`) - `cargo test -p xcl --lib vfs`: 23 passed, 0 failed **Regression run** main: ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1226 (PresentX 1226) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15341 MB ``` PR: ``` xcl-smoke v1 commit: b69731e6588009fb25c840a76594469b129ea3fd gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1643 (PresentX 1643) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14597 MB ``` **Not tested** - AMD GPUs and native wave64 hardware - other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine **AI use** - OpenCode, Gemini 4 Neon: audited `vfs.rs` and `vfs_hooks.rs`, wrote the staged open fix and unit test, ran the test suite and `scripts/smoke.ps1` regression runs, and drafted this PR description.
open_decision_for called prepare_write before CreateFileW/CreateFileA/
CreateFile2 ran, eagerly clearing any whiteout on the target path. If
the underlying CreateFile call then failed (e.g. sharing violation,
invalid flags/attributes, or access denied), no overlay file was
created yet the whiteout was gone — resurrecting the deleted original
game file.

Add prepare_write_staged and open_decision_staged / open_decision_staged_for
(matching the existing stage_write / commit_write split), and have
apply_open_decision call commit_write only after CreateFile returns a
valid handle, saving and restoring GetLastError across commit_write's
whiteout persistence I/O so statuses like ERROR_ALREADY_EXISTS are not
clobbered.

Assisted-by: OpenCode (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:51:59 +00:00
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 15:17 UTC · original

Full-suite run, since this PR has no test report yet. Tested exact head b69731e (on its base 930e8b4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 752 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: failed_create_file_preserves_whiteout_and_last_error.

Not tested

  • AMD, a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-24 15:17 UTC · [original](https://github.com/xcl-dev/xcl/pull/1362#issuecomment-7135766011) Full-suite run, since this PR has no test report yet. Tested exact head `b69731e` (on its base `930e8b4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4`: **752 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `failed_create_file_preserves_whiteout_and_last_error`. **Not tested** - AMD, a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠pickles976 on GitHub · 2026-11-24 15:20 UTC · original

Review from the #1259 author — your fix and mine are complementary halves of the same third-party #577 audit, and we should sequence deliberately: you close failed-open resurrection (staging no longer removes whiteouts before the open succeeds); #1259 closes missing-parent conjuring (a guard at the top of prepare_write returning ERROR_PATH_NOT_FOUND, plus tests that a whited-out parent stays whited out and a game-only parent still stages fine). Semantic interaction is one line: my guard belongs at the top of what you rename to prepare_write_staged — happy to rebase onto whichever lands first, and your test suite plus my three cases form the joint acceptance set. Flagging it so the reviewer does not have to rediscover the overlap.

**@⁠pickles976** on GitHub · 2026-11-24 15:20 UTC · [original](https://github.com/xcl-dev/xcl/pull/1362#issuecomment-7135862726) Review from the #1259 author — your fix and mine are complementary halves of the same third-party #577 audit, and we should sequence deliberately: you close **failed-open resurrection** (staging no longer removes whiteouts before the open succeeds); #1259 closes **missing-parent conjuring** (a guard at the top of `prepare_write` returning `ERROR_PATH_NOT_FOUND`, plus tests that a whited-out parent stays whited out and a game-only parent still stages fine). Semantic interaction is one line: my guard belongs at the top of what you rename to `prepare_write_staged` — happy to rebase onto whichever lands first, and your test suite plus my three cases form the joint acceptance set. Flagging it so the reviewer does not have to rediscover the overlap.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 16:28 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored.

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 16:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/1362#issuecomment-7137715252) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~21 ignored. Thanks!
Author
Owner

@⁠xpatfussy69x on GitHub · 2026-11-25 11:59 UTC · original

Test report for head b69731e as pushed (not merged onto current main) – NVIDIA, wave32.

Tested

  • NVIDIA GeForce RTX 3060 12 GB (Ampere, 32-lane waves only), driver 32.0.16.2124; AMD Ryzen 5 7500F; 32 GB RAM; Windows NT 10.0.26300; Rust 1.100.0 (stable-x86_64-pc-windows-msvc); debug; DXC 1.9.2609.5
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 752 passed, 0 failed, 41 ignored
  • SKIPPED GPU tests on this adapter: 2 (no wave64)
  • this PR's test failed_create_file_preserves_whiteout_and_last_error ran and passed
  • no XCL_SAMPLE_* data set (game-data tests not run)

Not tested

  • a title deleting and reopening its files; AMD / native wave64; release build; the head merged onto current main

AI use

  • Claude (Claude Opus 5.5) wrote the script that ran the suite on my PC, read the log and wrote and posted this report with my approval; the run is mine.
**@⁠xpatfussy69x** on GitHub · 2026-11-25 11:59 UTC · [original](https://github.com/xcl-dev/xcl/pull/1362#issuecomment-7161770875) Test report for head `b69731e` as pushed (not merged onto current `main`) – NVIDIA, wave32. **Tested** - NVIDIA GeForce RTX 3060 12 GB (Ampere, 32-lane waves only), driver 32.0.16.2124; AMD Ryzen 5 7500F; 32 GB RAM; Windows NT 10.0.26300; Rust 1.100.0 (stable-x86_64-pc-windows-msvc); debug; DXC 1.9.2609.5 - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`): 752 passed, 0 failed, 41 ignored - SKIPPED GPU tests on this adapter: 2 (no wave64) - this PR's test `failed_create_file_preserves_whiteout_and_last_error` ran and passed - no `XCL_SAMPLE_*` data set (game-data tests not run) **Not tested** - a title deleting and reopening its files; AMD / native wave64; release build; the head merged onto current `main` **AI use** - Claude (Claude Opus 5.5) wrote the script that ran the suite on my PC, read the log and wrote and posted this report with my approval; the run is mine.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1362/head:github-bot/gh-1362'
git switch 'github-bot/gh-1362'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1362'
git switch 'github-bot/gh-1362'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1362'
git switch 'github-bot/gh-1362'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1362'
git switch 'main'
git merge --squash 'github-bot/gh-1362'
git switch 'main'
git merge --ff-only 'github-bot/gh-1362'
git switch 'main'
git merge 'github-bot/gh-1362'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.