VFS: deleting a game file through a handle only deletes an overlay copy, and the original comes back #998

Open
opened 2026-11-26 04:39:52 +00:00 by github-bot · 2 comments
Owner

@⁠Conrage on GitHub · 2026-11-24 10:07 UTC · original

Deleting a game file by handle doesn't go through the DeleteFileW hook, so no whiteout is added. Two common ways to do that:

  • std::filesystem::remove in the MSVC STL: CreateFile2(DELETE | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT) then SetFileInformationByHandle(FileDispositionInfoEx)
  • CreateFileW(..., FILE_FLAG_DELETE_ON_CLOSE) for temp or lock files

What happens under XCL:

  1. DELETE is in WRITE_ACCESS and FILE_FLAG_DELETE_ON_CLOSE counts as a write, so open_decision_for treats the open as a write. With OPEN_EXISTING it calls prepare_write(rel, keep = true), which copies the whole original into the overlay:
    github.com/ivall/xcl@9aec53d/crates/xcl/src/vfs.rs (L530-L534)
    github.com/ivall/xcl@9aec53d/crates/xcl/src/vfs.rs (L584-L592)
  2. The handle points at that overlay copy. The disposition (or close) deletes the copy.
  3. Nothing hooks SetFileInformationByHandle / NtSetInformationFile, and nothing adds a whiteout on close, so the original is visible again.

Result: the delete reports success, but the next GetFileAttributesW / CreateFileW / FindFirstFileW still sees the original. The title can also wait on a full copy of a large file it only wanted to delete. Folders behave the same way: BACKUP_SEMANTICS creates an empty overlay folder, which is then deleted, and the game folder stays visible.

Related: a rename by handle (SetFileInformationByHandle(FileRenameInfo)) also bypasses the MoveFileExW hook. It renames the overlay copy and leaves the original at its old name, so the file ends up at both names.

Expected: a delete by handle of a game path leaves the file hidden, like DeleteFileW does (whiteout plus removal of any overlay copy), without copying the original first.

Suggested fix: hook SetFileInformationByHandle (FileDispositionInfo/Ex, FileRenameInfo/Ex) for handles that came from a game path, and add the whiteout on delete-on-close. Opens whose only "write" access is DELETE could also skip the content copy.

Not tested: found by reading the code and the MSVC STL filesystem.cpp; not run (no Windows machine).

AI use: found, checked and written up by Claude Code (Claude Opus 5.5) at my request.

**@⁠Conrage** on GitHub · 2026-11-24 10:07 UTC · [original](https://github.com/xcl-dev/xcl/issues/998) Deleting a game file by handle doesn't go through the `DeleteFileW` hook, so no whiteout is added. Two common ways to do that: - `std::filesystem::remove` in the MSVC STL: `CreateFile2(DELETE | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT)` then `SetFileInformationByHandle(FileDispositionInfoEx)` - `CreateFileW(..., FILE_FLAG_DELETE_ON_CLOSE)` for temp or lock files What happens under XCL: 1. `DELETE` is in `WRITE_ACCESS` and `FILE_FLAG_DELETE_ON_CLOSE` counts as a write, so `open_decision_for` treats the open as a write. With `OPEN_EXISTING` it calls `prepare_write(rel, keep = true)`, which copies the whole original into the overlay: https://github.com/ivall/xcl/blob/9aec53d/crates/xcl/src/vfs.rs#L530-L534 https://github.com/ivall/xcl/blob/9aec53d/crates/xcl/src/vfs.rs#L584-L592 2. The handle points at that overlay copy. The disposition (or close) deletes the copy. 3. Nothing hooks `SetFileInformationByHandle` / `NtSetInformationFile`, and nothing adds a whiteout on close, so the original is visible again. Result: the delete reports success, but the next `GetFileAttributesW` / `CreateFileW` / `FindFirstFileW` still sees the original. The title can also wait on a full copy of a large file it only wanted to delete. Folders behave the same way: `BACKUP_SEMANTICS` creates an empty overlay folder, which is then deleted, and the game folder stays visible. **Related:** a rename by handle (`SetFileInformationByHandle(FileRenameInfo)`) also bypasses the `MoveFileExW` hook. It renames the overlay copy and leaves the original at its old name, so the file ends up at both names. **Expected:** a delete by handle of a game path leaves the file hidden, like `DeleteFileW` does (whiteout plus removal of any overlay copy), without copying the original first. **Suggested fix:** hook `SetFileInformationByHandle` (FileDispositionInfo/Ex, FileRenameInfo/Ex) for handles that came from a game path, and add the whiteout on delete-on-close. Opens whose only "write" access is `DELETE` could also skip the content copy. **Not tested:** found by reading the code and the MSVC STL `filesystem.cpp`; not run (no Windows machine). **AI use:** found, checked and written up by Claude Code (Claude Opus 5.5) at my request.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:39:52 +00:00
Author
Owner

@⁠CharlyRien on GitHub · 2026-11-24 10:34 UTC · original

I'm taking the delete-by-handle part: a hook on SetFileInformationByHandle that, for FileDispositionInfo / FileDispositionInfoEx on a handle to the overlay copy of a game file, adds the whiteout once the delete succeeds (through the existing commit_overlay_removal). With a unit test that fails on main.

Not in this PR: FILE_FLAG_DELETE_ON_CLOSE, rename by handle, and skipping the content copy for a DELETE-only open. Each can be its own PR.

AI use: Claude Code with Claude Fable 5.2.

**@⁠CharlyRien** on GitHub · 2026-11-24 10:34 UTC · [original](https://github.com/xcl-dev/xcl/issues/998#issuecomment-7128953655) I'm taking the delete-by-handle part: a hook on `SetFileInformationByHandle` that, for `FileDispositionInfo` / `FileDispositionInfoEx` on a handle to the overlay copy of a game file, adds the whiteout once the delete succeeds (through the existing `commit_overlay_removal`). With a unit test that fails on `main`. Not in this PR: `FILE_FLAG_DELETE_ON_CLOSE`, rename by handle, and skipping the content copy for a `DELETE`-only open. Each can be its own PR. AI use: Claude Code with Claude Fable 5.2.
Author
Owner

@⁠vladbondarenko97 on GitHub · 2026-11-24 14:01 UTC · original

I'm taking the rename-by-handle part: SetFileInformationByHandle(FileRenameInfo / FileRenameInfoEx) on a handle to a game path is routed through the same overlay move as the MoveFileExW hook, so the original is whited out and the file ends up only at the new name. It will be stacked on #1054 (it reuses that hook), with a unit test that fails on main. Retail regression runs on an RTX 3080 Ti.

Not in it: delete-on-close (#1038) and the copy-skip for DELETE-only opens.

AI use: Claude Code (Claude Opus 5.5 plans and reviews, Claude Sonnet 5.5 implements).

**@⁠vladbondarenko97** on GitHub · 2026-11-24 14:01 UTC · [original](https://github.com/xcl-dev/xcl/issues/998#issuecomment-7133708163) I'm taking the **rename-by-handle** part: `SetFileInformationByHandle(FileRenameInfo / FileRenameInfoEx)` on a handle to a game path is routed through the same overlay move as the `MoveFileExW` hook, so the original is whited out and the file ends up only at the new name. It will be stacked on #1054 (it reuses that hook), with a unit test that fails on `main`. Retail regression runs on an RTX 3080 Ti. Not in it: delete-on-close (#1038) and the copy-skip for `DELETE`-only opens. AI use: Claude Code (Claude Opus 5.5 plans and reviews, Claude Sonnet 5.5 implements).
This discussion has been locked. Commenting is limited to contributors.
No description provided.