Skip to content

vfs: fix TRUNCATE_EXISTING on un-overlaid game files - #88

Merged
ivall merged 1 commit into
xcl-dev:mainfrom
certified-retart:fix/vfs-truncate-existing
Nov 23, 2026
Merged

ivall merged 1 commit into
xcl-dev:mainfrom
certified-retart:fix/vfs-truncate-existing

Conversation

@certified-retart

Copy link
Copy Markdown
Contributor

Summary

Fixes TRUNCATE_EXISTING opens of un-overlaid read-only game files in vfs and vfs_hooks:

  • Problem: When a title opens an un-overlaid game file (in_orig == true, in_ov == false) with TRUNCATE_EXISTING (5), Vfs::open_decision_for called prepare_write(&rel, false) (which creates only the parent directory in the overlay, not the file) and returned Decision::Use(ov). The CreateFileW / CreateFileA / CreateFile2 hooks then forwarded ov to Windows with TRUNCATE_EXISTING, which failed with ERROR_FILE_NOT_FOUND because ov does not yet exist on disk.
  • Fix:
    • Added Decision::UseWithDisposition(String, u32) and wired it through hk_create_file_w, hk_create_file_a, and hk_create_file_2.
    • For an un-overlaid game file opened with TRUNCATE_EXISTING (and no existing overlay entry / dangling symlink), open_decision_for rewrites the disposition to CREATE_ALWAYS in the overlay instead of publishing a 0-byte placeholder file ahead of the native call. That way Windows atomically creates the truncated overlay copy only if the native CreateFile* succeeds, leaving the original file untouched and avoiding empty placeholder files on failed opens.
    • Added native Win32 pre-validation for TRUNCATE_EXISTING:
      • Requires GENERIC_WRITE (0x4000_0000) before checking existence, returning ERROR_INVALID_PARAMETER otherwise (matching Win32 CreateFileW, which also rejects GENERIC_READ, FILE_WRITE_DATA, and GENERIC_ALL without GENERIC_WRITE).
      • Rejects visible directories (honoring FILE_FLAG_OPEN_REPARSE_POINT) without creating overlay entries, returning ERROR_INVALID_PARAMETER when FILE_FLAG_BACKUP_SEMANTICS is set and ERROR_ACCESS_DENIED otherwise (matching native Win32 CreateFileW).
    • Existing overlaid files continue to use Decision::Use(ov) with the original TRUNCATE_EXISTING disposition.

Verification

  • cargo test -p xcl --lib vfs -- --test-threads=2: 7 passed; 0 failed
    • Added truncate_existing_rewrites_unoverlaid_disposition_and_opens_with_win32 (verifies zero placeholder file prior to native open, real Win32 CreateFileW creation/truncation for both un-overlaid and already-overlaid files, and untouched original game file).
    • Added truncate_existing_validation_errors (verifies GENERIC_WRITE enforcement, missing/whited-out files, and native Win32 parity for directory errors with and without FILE_FLAG_BACKUP_SEMANTICS).

@ivall
ivall merged commit 83199a9 into xcl-dev:main Nov 23, 2026
@ivall

ivall commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Merged. Tested on Windows 11 with an RX 9070 (RDNA4): cargo test --workspace green with the retail samples (shader pack, console DLLs, texture archive), lib tests also with XCL_SPLIT_WAVE64=1; Unicorn Overlord and XDefiant run with this round merged. Thanks!

Michael-Glaser added a commit to Michael-Glaser/xcl that referenced this pull request Nov 24, 2026
…cl-dev#104)

On newer GDK runtimes (QUEUE_SHIFTED), 20 command list console methods shift up by +2 via NEWER_LIST_SLOTS, leaving 11 older slots (xcl-dev#59, xcl-dev#60, xcl-dev#68, xcl-dev#69, xcl-dev#78, xcl-dev#81, xcl-dev#84, xcl-dev#88, xcl-dev#89, xcl-dev#93, xcl-dev#94) without another shifted method taking their old index. Those slots remained wired directly to the older layout's handlers, so a newer-layout call hit the wrong method.

Wrap those orphaned slots in make_layout_split so newer-layout title calls go to a logged stub while older-layout titles keep the handler and non-title callers keep their PC target (including cl_execute_indirect at xcl-dev#59 and the original base-table stub for slots >= scanned). Slot xcl-dev#10 (Reset) stays Reset on both layouts and is not orphaned.

Assisted-by: Antigravity (Gemini 4 Neon)
Michael-Glaser added a commit to Michael-Glaser/xcl that referenced this pull request Nov 24, 2026
…vall#104)

On newer GDK runtimes (QUEUE_SHIFTED), 20 command list console methods shift up by +2 via NEWER_LIST_SLOTS, leaving 11 older slots (ivall#59, ivall#60, ivall#68, ivall#69, ivall#78, ivall#81, ivall#84, ivall#88, ivall#89, ivall#93, ivall#94) without another shifted method taking their old index. Those slots remained wired directly to the older layout's handlers, so a newer-layout call hit the wrong method.

Wrap those orphaned slots in make_layout_split so newer-layout title calls go to a logged stub while older-layout titles keep the handler and non-title callers keep their PC target (including cl_execute_indirect at ivall#59 and the original base-table stub for slots >= scanned). Slot ivall#10 (Reset) stays Reset on both layouts and is not orphaned.

Assisted-by: Antigravity (Gemini 4 Neon)
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.

2 participants