Skip to content

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

Open
b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:vfs/preserve-whiteout-on-failed-create
Open

b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:vfs/preserve-whiteout-on-failed-create

Conversation

@b3IKK

@b3IKK b3IKK commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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)
@futurepro62

Copy link
Copy Markdown

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.

@pickles976

Copy link
Copy Markdown

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.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

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

Thanks!

@xpatfussy69x

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants