Skip to content

VFS: a delete through a handle hides the game file (#998) - #1054

Open
CharlyRien wants to merge 1 commit into
xcl-dev:mainfrom
CharlyRien:vfs/delete-by-handle
Open

CharlyRien wants to merge 1 commit into
xcl-dev:mainfrom
CharlyRien:vfs/delete-by-handle

Conversation

@CharlyRien

@CharlyRien CharlyRien commented Nov 24, 2026 •

Copy link
Copy Markdown

A game file deleted through a handle came back: SetFileInformationByHandle was not hooked, so the delete removed only the overlay copy the handle points at and no whiteout was recorded. MSVC's std::filesystem::remove deletes this way. Part of #998 (the delete-by-handle case for files).

What is in it

  • crates/xcl/src/vfs_hooks.rs: a hook on SetFileInformationByHandle. After a successful FileDispositionInfo / FileDispositionInfoEx delete on a file inside the overlay, the whiteout is recorded through the existing commit_overlay_removal; a disposition that takes the delete back removes it. Everything else is passed through unchanged: other information classes, handles outside the overlay, failed calls.
  • Two unit tests in the same file: delete_by_handle_hides_the_game_file and set_file_info_by_handle_passes_everything_else_through.

Tested

  • NVIDIA GeForce RTX 3090, driver 616.56 (32.0.16.1656); AMD Ryzen 9 5950X, 32 GB; Windows 11 Pro 23H2 build 22631.6199; Rust 1.100.0 stable-x86_64-pc-windows-msvc; release; DXC 1.9.2602.17
  • cargo test --workspace --release --no-fail-fast -- --test-threads=4 on this PR's head: 729 passed, 0 failed, 41 ignored (main at 02bfd1d: 727 passed, 0 failed, 41 ignored)
  • SKIPPED GPU tests printed: 2, both no wave64 (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware). With --nocapture, main shows 3 more on this machine (no reserved cube with mips on this adapter; no D3D12 debug layer installed, twice); that run was not repeated on the PR.
  • delete_by_handle_hides_the_game_file fails without the new logic (with set_file_info_vfs returning the original call's result at once: 11 passed, 1 failed in cargo test -p xcl --release --lib vfs_hooks, at the whiteout assertion).

Regression run

main:

xcl-smoke v1
commit: 02bfd1d6c0659a5102abde6d73babba8afd9fce9
gpu: NVIDIA GeForce RTX 3090
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 1629 (PresentX 1629)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14484 MB

PR:

xcl-smoke v1
commit: 7ecc08f8a9434315b6ebc1214433eaac9cfa6767
gpu: NVIDIA GeForce RTX 3090
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 1625 (PresentX 1626)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14607 MB

Not tested

  • The retail run does not reach the changed code path as far as I can tell: it stays on the title's first screens for 60 s with no input, and I saw no delete through a handle of a game file. It is a regression check only.
  • No title is known to use this path. The retail title of the regression run cannot reach it through its imports: dumpbin -imports shows no SetFileInformationByHandle in its exe, msvcp140.dll, XCurl.dll or libHttpClient.GDK.dll, and its msvcp140.dll exports no __std_fs_* function. For files the exe imports DeleteFileW, RemoveDirectoryW, MoveFileExW, CreateFileW, CreateDirectoryW, FindFirstFileW and the CRT's remove. A call through GetProcAddress is not ruled out. The run's report.json has an empty vfs section (no redirected writes, no whiteouts). So this fixes a case found by reading the code, not one seen in a game; other titles were not checked.
  • Whether a real title's std::filesystem::remove reaches the kernelbase SetFileInformationByHandle export (only the unit tests and pls_quota, which installs the hooks, cover it).
  • Directories: a directory deleted through a handle is passed through as before (the game directory stays visible). Left out because it overlaps VFS: RemoveDirectoryW on a non-empty game folder succeeds and hides the folder in every later run #997 / VFS: reject removal of non-empty virtual directories #1016.
  • Not in this PR, as said on VFS: deleting a game file through a handle only deletes an overlay copy, and the original comes back #998: FILE_FLAG_DELETE_ON_CLOSE (and FILE_DISPOSITION_FLAG_ON_CLOSE, passed through), rename by handle, skipping the content copy for a DELETE-only open.
  • A write-open of the same path between the disposition and the last close removes the whiteout again (existing prepare_write behaviour); not tested.
  • vfs::tests::truncate_existing_validation_errors fails when only the vfs tests are run (cargo test -p xcl --release --lib vfs: 21 passed, 1 failed, 3 runs of 3, last error 127 where 5 is expected) and passes in the whole suite. Seen with this PR; reported by the tool as the same without it, which I did not rerun myself. Not touched here.
  • AMD and Intel GPUs, Windows 10, Wine, debug build.

AI use

  • Claude Code with Claude Fable 5.2 wrote the code, the tests and this description, and ran the tests and the smoke runs on my machine.

🤖 Generated with Claude Code

A title that deletes a game file through a handle (MSVC's
std::filesystem::remove: CreateFile2 with DELETE, then
SetFileInformationByHandle with FileDispositionInfoEx or
FileDispositionInfo) holds a handle to the overlay copy. The delete
removed only that copy and no whiteout was recorded, so the original
was visible again.

SetFileInformationByHandle is hooked now. After a successful delete
disposition on a file inside the overlay the whiteout is recorded
through commit_overlay_removal; a disposition that takes the delete
back removes it again. Directories, FILE_DISPOSITION_FLAG_ON_CLOSE,
other information classes and handles outside the overlay are passed
through unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@CharlyRien
CharlyRien marked this pull request as ready for review November 24, 2026 11:05
@dcastell1

Copy link
Copy Markdown

Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on main@384f7f7 (baseline 737 passed, 0 failed, 41 ignored on this box):

patch -p1 < this PR            # clean, no fuzz
cargo test --workspace -- --test-threads=4
739 passed; 0 failed; 41 ignored   (exit 0)

Two more passing tests than the baseline, and the e2e that #1038 leaves red on this base passes here — the whiteout the title's delete-through-a-handle writes is in the list. Worth cross-checking with #1038's author, since both are after the same behaviour.

Tree restored afterwards (full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.

@pvfreis pvfreis left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 7ecc08f against its merge base 02bfd1d, by reading the code; nothing was built or run here (no script of my own either; the only commands were read-only gh and git, including two git merge-tree trial merges, which run no code). I found no defect in this PR on its own. The hook is narrow: only the two disposition classes are looked at, the name is taken from the handle at the time of the call, the whiteout is written only after the real call returns success, and the last error is kept on both paths. One thing has to be settled with #1038 before both are in, and one smaller note follows.

  1. CONFIRMED in the code of the two heads read together (Windows' part is from its documentation and from the run #1038's author reports, not from a run here): with #1038 merged, a FALSE disposition brings the game file back. This was found by the author of #1038 (gloger2003, in that PR's description); I traced it and agree. #1038 at 7f93905 records the whiteout when a game file is opened with FILE_FLAG_DELETE_ON_CLOSE (open_file in vfs_hooks.rs). Here, a successful FileDispositionInfo { DeleteFile: FALSE } (or FileDispositionInfoEx without the delete flag) on a handle to an overlay copy calls commit_write, which removes the whiteout (crates/xcl/src/vfs_hooks.rs:612-614, crates/xcl/src/vfs.rs:497-500). Windows documents that FALSE has no effect on a handle opened with FILE_FLAG_DELETE_ON_CLOSE: the call succeeds and the copy is still deleted at close. Scenario: open G:\data\x with delete-on-close, call SetFileInformationByHandle(FileDispositionInfo, FALSE), close: the copy is gone, the whiteout is gone, the original is visible again. On this PR alone nothing is lost (there is no whiteout to remove, and delete-on-close is listed under Not tested). Otherwise the two PRs agree: both go through commit_overlay_removal, add_whiteout is a set insert (vfs.rs:390-395), so a file that gets both a delete-on-close open and an explicit delete is recorded once; and the two heads merge as text without conflicts (git merge-tree).

  2. CONFIRMED (minor, test coverage): the "only after success" branch is not tested for a handle that is inside the overlay. The failed call in the test uses INVALID_HANDLE_VALUE (vfs_hooks.rs:1888-1890), for which overlay_file_rel is already None, so the test would pass even if the whiteout were written before the call. A read-only game file gives the real case: its overlay copy is read-only, the disposition fails with access denied, and no whiteout may appear. Also untested: FileDispositionInfoEx with no delete flag, and FILE_DISPOSITION_FLAG_ON_CLOSE being passed through (vfs_hooks.rs:595-598). The FileDispositionInfoEx case accepts either result (vfs_hooks.rs:1849-1856), which is honest for file systems without the class.

Checked without a finding: the class numbers and flag values (4, 21, 0x1, 0x8); a handle outside the overlay, a directory, and a path that only shares the overlay's prefix all return None (vfs_hooks.rs:566, :582-586); a path-based rename before the delete is handled because the name is read from the handle at delete time (:604); XCL's own std::fs::remove_file inside delete_file runs under the hook guard and is passed through (:624), so DeleteFileW is not handled twice; an overlay file with no game file behind it gets no whiteout (vfs.rs:504). Merged 47efa2e (non-empty directory removal) does not overlap: it changes remove_dir only, this PR passes directories through, and the head merges into main at 47efa2e without conflicts (git merge-tree). A directory deleted through a handle still reports success and stays visible, as the description says, which now differs from RemoveDirectoryW on main returning "not empty".

Against CONTRIBUTING: Tested, Regression run (both blocks, the PR's names this head), Not tested and AI use are all there. From the two blocks, by arithmetic and not measured here: frames 1625 / 1629 = 99.8 %, peak commit 14607 / 14484 = 100.8 %. The PR adds two unit tests and no e2e case.

Verdict: fine to merge on its own from reading; decide with #1038 which of the two changes the FALSE branch (finding 1) before the second one goes in, and a test of a failing delete on an overlay handle (finding 2) would be a cheap addition.

Review by Claude Code (written by Claude Fable 5.2, checked with Claude Opus 5.5); each point checked by a person before posting.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

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.

4 participants