file_system: T:\ is a drive root for file calls; move and copy hold the folder lock (RT-FS-OVERLAY-ROOT-LOCK-LONGPATH) #2534
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2534"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-28T01:11:35Z.
Claimed in the coordination issue as: RT-FS-OVERLAY-ROOT-LOCK-LONGPATH (claim: https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7231487470). Found by @kevincommits, item 2 of https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7231276991. Thanks!
What and why
Three fixes to the
GAME:/T:overlay inruntime/shims/file_system.cpp:T:\slipped past the root checks.parse_console(L"T:\\")gives the scratch folder's parts (.gta6rt-temp,<run>), not an empty list.RemoveDirectoryandMoveFileExalready usedrive_root()for that, but the write-open (write_target),DeleteFileW, the copy destination andSetFileAttributesWonly checkedparts.empty(). SoSetFileAttributesW(T:\)changed the host scratch folder's attributes, and a write-open ofT:\was not refused. All four now usedrive_root()and giveT:\the same error they giveGAME:\(ERROR_INVALID_NAME, orERROR_ACCESS_DENIEDfor attributes).CreateDirectoryholdfolder_lock(parent)from "does the folder exist" to the host call that makes the entry, so a concurrentRemoveDirectoryof that folder comes wholly before or after (the comment atg_folder_locks).MoveFileExandcopy_destination(CopyFileW,CopyFileExW,CopyFile2) did not, so the remove-then-resurrect race stayed open for them. Now:MoveFileExholds the lock from its destination checks to the host move.copy_destinationtakes it before its checks and hands it to the caller, which holds it through the host copy.CopyFileExWwithprogress,CopyFile2withpProgressRoutine) keeps the old behaviour. The routine is the title's code, and nothing that holds a folder lock may call back into the title (the same comment). A routine that touched a folder in the same lock stripe would otherwise deadlock.CreateDirectory. Recreating a removed folder deletes its marker withstd::filesystem::remove(marker(...) / kRemovedDirMarker)and nowin32_io_path(), unlike every other marker access. On a host without long path support, a marker beyondMAX_PATHcannot be removed, and the new folder is rolled back. It now goes throughwin32_io_path().Tested
file_system_test(CPU only, synthetic package and overlay folders, no game data):T:\root cases:SetFileAttributesWis refused and the host folder is not hidden;DeleteFileW, aGENERIC_WRITEopen andCopyFileWontoT:\areERROR_INVALID_NAME. Onmainall 4 fail; with the fix the whole test passes (544 checks, 0 failures).CreateDirectoryWrecreates a removed folder whose marker lies beyondMAX_PATH, and the folder is listed again. It also passes onmainon this machine, because long path support is on here (LongPathsEnabled = 1), so it does not show the bug; it keeps the path covered.RemoveDirectoryto land between the check and the host call, which a test cannot place reliably. The existing move, copy andCopyFile2cases all pass with the lock held.GPUs tested: n/a (CPU test).
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).MoveFileExa few lines above the new lock; whichever lands second needs a small merge there. No other open PR touches these lines.🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T02:01:35Z.
Reviewed at head
11b63a53bon Windows 11 (MSVC 202219.44).Verification
file_system_test.file_system_test: 544/544 checks passed (including the 2,000-round create/remove directory concurrency checks).Notes (non-blocking)
T:\(file_system.cpp:249-266,310-313,531,1136-1139,1389-1390,1563), extended-length marker cleanup (1213-1220), and holding the destination folder lock across ordinary moves and callback-free copies while dropping it around title progress callbacks (1319-1455,1543-1551) all look solid.file_system_test.cpp:939-997,1437-1456): Consider adding the sameRemoveDirectoryWrace test forMoveFileExWand callback-freeCopyFileW/CopyFileExW/CopyFile2against removal of the destination parent to directly pin the new lock scope.file_system.cpp:1297-1335,1394-1411): Renaming an overlay-only source directory only locks the new parent stripe, so a concurrent copy into that directory can still race a rename; noted as pre-existing and outside this PR'sRemoveDirectoryWscope.Approve.
AI-assisted review + local MSVC verification.
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T06:38:37Z.
#2534 | head
11b63a53b0(merged cleanly with main6dfca64280) |ctest --test-dir runtime/build -C RelWithDebInfo -R "^file_system$" --output-on-failure| red on main:file_system_testfails (544 check(s), 4 failure(s):SetFileAttributesW(T:\),DeleteFileW(T:\), write-openCreateFileW(T:\), andCopyFileWontoT:\treatedT:\as its per-process host folder rather than a drive root becausepartswas non-empty) | green on PR+main:1/1CTest passes (file_system544/544checks in17.10s, coveringT:\drive-root refusal, destinationfolder_lockserialization acrossMoveFileExW/CopyFile*, and extended-length> MAX_PATH.leonida_removed_dirmarker cleanup onCreateDirectoryW);check_no_game_data.py0violations | Windows 11, RTX 3090 (610.88), Vulkan SDK 1.4.363.1 | AI-assisted: yesImported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T14:36:29Z.
Review: COMMENTED
Static code audit against PR head
11b63a53bandorigin/mainec740bcc3.runtime/shims/file_system.cpp:1547checks onlypProgressRoutine. A validCopyFile2V2 block can supply onlypProgressRoutineOld, so nativeCopyFile2can call back while the destination stripe is held. A callback that mutates that folder can attempt to reacquire the same non-recursive mutex. Please check both callback fields for V2 and add a native Windows regression for a re-entrant legacy callback. Win32 V2 parameters.runtime/shims/file_system.cpp:1311still mirrors the parent during a case-only package move before taking the new lock. If deletion hides the source andRemoveDirectoryWthen hides the parent after the move's source lookup, copy-up brings the parent back. Extend the destination lock and recheck the parent and source on that branch.The new checks cover canonical
T:\refusals and long-folder recreation. The concurrency fixture covers create/remove. A direct marker absence assertion and move/copy removal cases would pin the other changes.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-28T14:58:03Z.
Review: COMMENTED
Reviewed
11b63a53band testedfile_systemon Windows 11.Verification (Windows 11, MSVC 19.44, Ninja Release):
file_system_test.ctest -R '^file_system$': 1/1 passed (12.27 s).python -I scripts/check_no_game_data.py: passed.Code audit:
drive_root()guards forT:\, thewin32_io_path()marker removal, and holdingfolder_lock(parent_of(dst))acrossmove_file_ex_w/copy_file_w/copy_file_ex_ware solid.@timbot103before approving:runtime/shims/file_system.cpp(copy_file2):calls_backonly checksparameters->pProgressRoutine. In Windows SDK 10.0.26100.0 (winbase.h),COPYFILE2_EXTENDED_PARAMETERS_V2also carriesLPPROGRESS_ROUTINE pProgressRoutineOld(which takes precedence overpProgressRoutine), so a V2 caller setting onlypProgressRoutineOldwould execute guest callback code while holding the non-recursivefolder_lock.runtime/shims/file_system.cpp(move_file_ex_w,same_entry(src, dst)branch): the case-only rename copy-up (create_directories+CopyFileWwhen!from_view.in_overlay) still executes beforestd::lock_guard folder(folder_lock(parent_of(dst))), leaving a window against concurrentRemoveDirectoryW.AI-assisted (Antigravity, Gemini).
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T22:04:23Z.
Verified by OreoFR
c1ecf04ed+ PR head11b63a53b; green run in a merge package of 11 PRs, no new ctest failure vs mainctest -R "^file_system$"AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-28T23:21:45Z.
Tested
11b63a53bmerged (no commit) withmainaa918e5d9. GPUs tested: NVIDIA GeForce RTX 3080, driver 621.40, Windows 11 10.0.26300; MSVC 19.52 (Visual Studio 18), RelWithDebInfo, Ninja.file_systempasses.runtime/shims/file_system.cppback tomain,file_systemfails 4 of its 544 checks, all on theT:\root:SetFileAttributesW(T:\) is refused (ERROR_ACCESS_DENIED) and leaves the host folder aloneDeleteFileW(T:\) is ERROR_INVALID_NAME, as for GAME:\a write-open of T:\ is ERROR_INVALID_NAME, as for GAME:\CopyFileW onto T:\ is ERROR_INVALID_NAME, as onto GAME:\mainfor the move/copy folder-lock half. The race rounds only printNOTEcounts (both succeeded 0onmainhere), so that half is not pinned by a failing test.No blocker from my side. AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T23:24:48Z.
Merged after TheGeogeo's red/green check (check: green with this PR, red with
main's code, no regression over the relinked tests) and a re-check here: no conflict withmaine6bd9943f, same head as checked,no-game-datagreen, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known onmainor Vulkan: vk_xdxr_postbuild_readback vk_bindless_dimensions d3d12_compile_pool xbox_present ). The Python jobs fail onmaintoo.AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.