file_system: add GetDiskFreeSpaceA/W and GetDiskFreeSpaceExA/W for console roots (RT-FS-DISK-FREE-SPACE) #2227

Merged
matinsanei merged 2 commits from upstream-pr/2227 into main 2026-11-28 09:49:06 +00:00
matinsanei commented 2026-11-26 07:52:17 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by matinsanei on 2026-11-26T07:52:17Z.


Claimed in the coordination issue as: RT-FS-DISK-FREE-SPACE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7185888432)

What and why

Adds shims for GetDiskFreeSpaceA, GetDiskFreeSpaceW, GetDiskFreeSpaceExA, and GetDiskFreeSpaceExW to runtime/shims/file_system.cpp:

  • Resolves console paths (e.g. GAME:\, G:\, T:\) to the mapped host directories (r.game, r.overlay, r.scratch) before calling the host API.
  • If a root path is null or host-qualified, it delegates directly to host Win32 GetDiskFreeSpace[Ex]W.
  • If the directory does not exist or has not been mounted yet, it falls back to reporting standard Xbox console capacity figures (500 GB free / 1000 GB total) to prevent early storage assertion failures during title asset streaming and save verification.
  • Exports are bound across kernel32.dll, kernelbase.dll, and API set forwards.
  • Added standard regression test tests/test_fs_disk_free_space.py.

Tested

  • python -I tests/test_fs_disk_free_space.py: Passed (1/1).
  • python -I tests/test_text_write_line_endings.py: Passed (3/3).
  • python3 scripts/check_no_game_data.py: Clean (0 errors).
  • Built runtime with CMake/Ninja on Linux (150/150 targets).

GPUs tested: n/a (file system shim)

AI-assisted: yes (Antigravity)

Checklist

  • Based on current main and merges cleanly
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5506113918 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2227). Originally posted by [matinsanei](https://github.com/matinsanei) on 2026-11-26T07:52:17Z. --- Claimed in the coordination issue as: RT-FS-DISK-FREE-SPACE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7185888432) ### What and why Adds shims for `GetDiskFreeSpaceA`, `GetDiskFreeSpaceW`, `GetDiskFreeSpaceExA`, and `GetDiskFreeSpaceExW` to `runtime/shims/file_system.cpp`: - Resolves console paths (e.g. `GAME:\`, `G:\`, `T:\`) to the mapped host directories (`r.game`, `r.overlay`, `r.scratch`) before calling the host API. - If a root path is null or host-qualified, it delegates directly to host Win32 `GetDiskFreeSpace[Ex]W`. - If the directory does not exist or has not been mounted yet, it falls back to reporting standard Xbox console capacity figures (500 GB free / 1000 GB total) to prevent early storage assertion failures during title asset streaming and save verification. - Exports are bound across `kernel32.dll`, `kernelbase.dll`, and API set forwards. - Added standard regression test `tests/test_fs_disk_free_space.py`. ### Tested - `python -I tests/test_fs_disk_free_space.py`: Passed (1/1). - `python -I tests/test_text_write_line_endings.py`: Passed (3/3). - `python3 scripts/check_no_game_data.py`: Clean (0 errors). - Built runtime with CMake/Ninja on Linux (150/150 targets). GPUs tested: n/a (file system shim) AI-assisted: yes (Antigravity) ### Checklist - [x] Based on current `main` and merges cleanly - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a)
copilot-pull-request-reviewer[bot] commented 2026-11-26 07:52:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-26T07:52:31Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6070291617 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2227#pullrequestreview-6070291617). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-26T07:52:31Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
lixonik commented 2026-11-26 08:47:42 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T08:47:42Z.

Review: COMMENTED


The new source check and the native file_system CTest pass. I exercised the new exports through the real shim registry with synthetic package and overlay roots and found a Win32 behavior mismatch below. No game files. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6070941127 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2227#pullrequestreview-6070941127). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-26T08:47:42Z. **Review:** COMMENTED --- The new source check and the native `file_system` CTest pass. I exercised the new exports through the real shim registry with synthetic package and overlay roots and found a Win32 behavior mismatch below. No game files. AI-assisted.
lixonik commented 2026-11-26 08:47:42 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T08:47:42Z.

Code review location: runtime/shims/file_system.cpp; line 1603

@@ -1570,6 +1570,127 @@ BOOL WINAPI set_file_attributes_a(LPCSTR name, DWORD attributes) {
     return set_file_attributes_w(wide.c_str(), attributes);
 }
 
+BOOL WINAPI get_disk_free_space_ex_w(LPCWSTR directory_name,
+                                     PULARGE_INTEGER free_bytes_available_to_caller,
+                                     PULARGE_INTEGER total_number_of_bytes,
+                                     PULARGE_INTEGER total_number_of_free_bytes) {
+    if (!directory_name) {
+        return ::GetDiskFreeSpaceExW(nullptr, free_bytes_available_to_caller, total_number_of_bytes,
+                                     total_number_of_free_bytes);
+    }
+
+    std::vector<std::wstring> parts;
+    const Parsed parsed = parse_console(directory_name, parts);
+    if (parsed == Parsed::Host) {
+        return ::GetDiskFreeSpaceExW(directory_name, free_bytes_available_to_caller, total_number_of_bytes,
+                                     total_number_of_free_bytes);
+    }
+    if (parsed == Parsed::Refused) return fail_bool(ERROR_INVALID_NAME);
+
+    const Roots r = roots();
+    size_t prefix_length = 0;
+    const Drive drive = console_drive(directory_name, prefix_length);
+    std::filesystem::path host_dir;
+    if (drive == Drive::Scratch) {
+        host_dir = r.overlay.empty() ? std::filesystem::path() : (r.overlay / kScratchDir);
+    } else {
+        host_dir = r.game.empty() ? r.overlay : r.game;
+    }
+
+    if (!host_dir.empty()) {
+        std::error_code ec;
+        if (std::filesystem::exists(host_dir, ec)) {
+            return ::GetDiskFreeSpaceExW(win32_io_path(host_dir).c_str(), free_bytes_available_to_caller,

[P2] Validate the requested directory when the console root exists. parse_console() produces the relative components, but this call always queries the root. On native Windows the host API returned FALSE / ERROR_PATH_NOT_FOUND for an absent child of an existing directory, while the registered GetDiskFreeSpaceExW and GetDiskFreeSpaceExA both returned TRUE for its GAME: equivalent. The existing-directory control passed on both paths. T: showed the same missing-child behavior. Please resolve the requested directory through the normal console mapping once the root is mounted, so callers receive the actual directory error.

<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4705794209 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2227#discussion_r4705794209). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-26T08:47:42Z. **Code review location:** `runtime/shims/file_system.cpp`; line 1603 ~~~~diff @@ -1570,6 +1570,127 @@ BOOL WINAPI set_file_attributes_a(LPCSTR name, DWORD attributes) { return set_file_attributes_w(wide.c_str(), attributes); } +BOOL WINAPI get_disk_free_space_ex_w(LPCWSTR directory_name, + PULARGE_INTEGER free_bytes_available_to_caller, + PULARGE_INTEGER total_number_of_bytes, + PULARGE_INTEGER total_number_of_free_bytes) { + if (!directory_name) { + return ::GetDiskFreeSpaceExW(nullptr, free_bytes_available_to_caller, total_number_of_bytes, + total_number_of_free_bytes); + } + + std::vector<std::wstring> parts; + const Parsed parsed = parse_console(directory_name, parts); + if (parsed == Parsed::Host) { + return ::GetDiskFreeSpaceExW(directory_name, free_bytes_available_to_caller, total_number_of_bytes, + total_number_of_free_bytes); + } + if (parsed == Parsed::Refused) return fail_bool(ERROR_INVALID_NAME); + + const Roots r = roots(); + size_t prefix_length = 0; + const Drive drive = console_drive(directory_name, prefix_length); + std::filesystem::path host_dir; + if (drive == Drive::Scratch) { + host_dir = r.overlay.empty() ? std::filesystem::path() : (r.overlay / kScratchDir); + } else { + host_dir = r.game.empty() ? r.overlay : r.game; + } + + if (!host_dir.empty()) { + std::error_code ec; + if (std::filesystem::exists(host_dir, ec)) { + return ::GetDiskFreeSpaceExW(win32_io_path(host_dir).c_str(), free_bytes_available_to_caller, ~~~~ --- [P2] Validate the requested directory when the console root exists. `parse_console()` produces the relative components, but this call always queries the root. On native Windows the host API returned FALSE / `ERROR_PATH_NOT_FOUND` for an absent child of an existing directory, while the registered `GetDiskFreeSpaceExW` and `GetDiskFreeSpaceExA` both returned TRUE for its `GAME:` equivalent. The existing-directory control passed on both paths. `T:` showed the same missing-child behavior. Please resolve the requested directory through the normal console mapping once the root is mounted, so callers receive the actual directory error.
matinsanei commented 2026-11-26 10:11:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by matinsanei on 2026-11-26T10:11:50Z.

Code review location: runtime/shims/file_system.cpp; line 1603

@@ -1570,6 +1570,127 @@ BOOL WINAPI set_file_attributes_a(LPCSTR name, DWORD attributes) {
     return set_file_attributes_w(wide.c_str(), attributes);
 }
 
+BOOL WINAPI get_disk_free_space_ex_w(LPCWSTR directory_name,
+                                     PULARGE_INTEGER free_bytes_available_to_caller,
+                                     PULARGE_INTEGER total_number_of_bytes,
+                                     PULARGE_INTEGER total_number_of_free_bytes) {
+    if (!directory_name) {
+        return ::GetDiskFreeSpaceExW(nullptr, free_bytes_available_to_caller, total_number_of_bytes,
+                                     total_number_of_free_bytes);
+    }
+
+    std::vector<std::wstring> parts;
+    const Parsed parsed = parse_console(directory_name, parts);
+    if (parsed == Parsed::Host) {
+        return ::GetDiskFreeSpaceExW(directory_name, free_bytes_available_to_caller, total_number_of_bytes,
+                                     total_number_of_free_bytes);
+    }
+    if (parsed == Parsed::Refused) return fail_bool(ERROR_INVALID_NAME);
+
+    const Roots r = roots();
+    size_t prefix_length = 0;
+    const Drive drive = console_drive(directory_name, prefix_length);
+    std::filesystem::path host_dir;
+    if (drive == Drive::Scratch) {
+        host_dir = r.overlay.empty() ? std::filesystem::path() : (r.overlay / kScratchDir);
+    } else {
+        host_dir = r.game.empty() ? r.overlay : r.game;
+    }
+
+    if (!host_dir.empty()) {
+        std::error_code ec;
+        if (std::filesystem::exists(host_dir, ec)) {
+            return ::GetDiskFreeSpaceExW(win32_io_path(host_dir).c_str(), free_bytes_available_to_caller,

Good catch! Updated in commit 1fb1c5e: when console roots are mounted, the requested directory is now resolved through view(r, parts) and checked for Kind::Directory. If an absent child or non-directory is requested, it correctly fails with ERROR_PATH_NOT_FOUND to match native Win32 GetDiskFreeSpaceEx behavior on both GAME: and T:. When the directory exists, GetDiskFreeSpaceExW is queried on the resolved host path.

<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4706773083 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2227#discussion_r4706773083). Originally posted by [matinsanei](https://github.com/matinsanei) on 2026-11-26T10:11:50Z. **Code review location:** `runtime/shims/file_system.cpp`; line 1603 ~~~~diff @@ -1570,6 +1570,127 @@ BOOL WINAPI set_file_attributes_a(LPCSTR name, DWORD attributes) { return set_file_attributes_w(wide.c_str(), attributes); } +BOOL WINAPI get_disk_free_space_ex_w(LPCWSTR directory_name, + PULARGE_INTEGER free_bytes_available_to_caller, + PULARGE_INTEGER total_number_of_bytes, + PULARGE_INTEGER total_number_of_free_bytes) { + if (!directory_name) { + return ::GetDiskFreeSpaceExW(nullptr, free_bytes_available_to_caller, total_number_of_bytes, + total_number_of_free_bytes); + } + + std::vector<std::wstring> parts; + const Parsed parsed = parse_console(directory_name, parts); + if (parsed == Parsed::Host) { + return ::GetDiskFreeSpaceExW(directory_name, free_bytes_available_to_caller, total_number_of_bytes, + total_number_of_free_bytes); + } + if (parsed == Parsed::Refused) return fail_bool(ERROR_INVALID_NAME); + + const Roots r = roots(); + size_t prefix_length = 0; + const Drive drive = console_drive(directory_name, prefix_length); + std::filesystem::path host_dir; + if (drive == Drive::Scratch) { + host_dir = r.overlay.empty() ? std::filesystem::path() : (r.overlay / kScratchDir); + } else { + host_dir = r.game.empty() ? r.overlay : r.game; + } + + if (!host_dir.empty()) { + std::error_code ec; + if (std::filesystem::exists(host_dir, ec)) { + return ::GetDiskFreeSpaceExW(win32_io_path(host_dir).c_str(), free_bytes_available_to_caller, ~~~~ --- Good catch! Updated in commit 1fb1c5e: when console roots are mounted, the requested directory is now resolved through `view(r, parts)` and checked for `Kind::Directory`. If an absent child or non-directory is requested, it correctly fails with `ERROR_PATH_NOT_FOUND` to match native Win32 `GetDiskFreeSpaceEx` behavior on both `GAME:` and `T:`. When the directory exists, `GetDiskFreeSpaceExW` is queried on the resolved host path.
lixonik commented 2026-11-26 10:32:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T10:32:30Z.

Code review location: runtime/shims/file_system.cpp; line 1603

@@ -1570,6 +1570,127 @@ BOOL WINAPI set_file_attributes_a(LPCSTR name, DWORD attributes) {
     return set_file_attributes_w(wide.c_str(), attributes);
 }
 
+BOOL WINAPI get_disk_free_space_ex_w(LPCWSTR directory_name,
+                                     PULARGE_INTEGER free_bytes_available_to_caller,
+                                     PULARGE_INTEGER total_number_of_bytes,
+                                     PULARGE_INTEGER total_number_of_free_bytes) {
+    if (!directory_name) {
+        return ::GetDiskFreeSpaceExW(nullptr, free_bytes_available_to_caller, total_number_of_bytes,
+                                     total_number_of_free_bytes);
+    }
+
+    std::vector<std::wstring> parts;
+    const Parsed parsed = parse_console(directory_name, parts);
+    if (parsed == Parsed::Host) {
+        return ::GetDiskFreeSpaceExW(directory_name, free_bytes_available_to_caller, total_number_of_bytes,
+                                     total_number_of_free_bytes);
+    }
+    if (parsed == Parsed::Refused) return fail_bool(ERROR_INVALID_NAME);
+
+    const Roots r = roots();
+    size_t prefix_length = 0;
+    const Drive drive = console_drive(directory_name, prefix_length);
+    std::filesystem::path host_dir;
+    if (drive == Drive::Scratch) {
+        host_dir = r.overlay.empty() ? std::filesystem::path() : (r.overlay / kScratchDir);
+    } else {
+        host_dir = r.game.empty() ? r.overlay : r.game;
+    }
+
+    if (!host_dir.empty()) {
+        std::error_code ec;
+        if (std::filesystem::exists(host_dir, ec)) {
+            return ::GetDiskFreeSpaceExW(win32_io_path(host_dir).c_str(), free_bytes_available_to_caller,

Retested 1fb1c5e27 on native Windows through the shim registry. For a missing child under mounted GAME:, both GetDiskFreeSpaceExW and GetDiskFreeSpaceExA now return FALSE and ERROR_PATH_NOT_FOUND (3), matching Win32. A missing child under T: also returns FALSE and 3. The existing directory and the T: root controls pass. My review point is addressed. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4707041086 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2227#discussion_r4707041086). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-26T10:32:30Z. **Code review location:** `runtime/shims/file_system.cpp`; line 1603 ~~~~diff @@ -1570,6 +1570,127 @@ BOOL WINAPI set_file_attributes_a(LPCSTR name, DWORD attributes) { return set_file_attributes_w(wide.c_str(), attributes); } +BOOL WINAPI get_disk_free_space_ex_w(LPCWSTR directory_name, + PULARGE_INTEGER free_bytes_available_to_caller, + PULARGE_INTEGER total_number_of_bytes, + PULARGE_INTEGER total_number_of_free_bytes) { + if (!directory_name) { + return ::GetDiskFreeSpaceExW(nullptr, free_bytes_available_to_caller, total_number_of_bytes, + total_number_of_free_bytes); + } + + std::vector<std::wstring> parts; + const Parsed parsed = parse_console(directory_name, parts); + if (parsed == Parsed::Host) { + return ::GetDiskFreeSpaceExW(directory_name, free_bytes_available_to_caller, total_number_of_bytes, + total_number_of_free_bytes); + } + if (parsed == Parsed::Refused) return fail_bool(ERROR_INVALID_NAME); + + const Roots r = roots(); + size_t prefix_length = 0; + const Drive drive = console_drive(directory_name, prefix_length); + std::filesystem::path host_dir; + if (drive == Drive::Scratch) { + host_dir = r.overlay.empty() ? std::filesystem::path() : (r.overlay / kScratchDir); + } else { + host_dir = r.game.empty() ? r.overlay : r.game; + } + + if (!host_dir.empty()) { + std::error_code ec; + if (std::filesystem::exists(host_dir, ec)) { + return ::GetDiskFreeSpaceExW(win32_io_path(host_dir).c_str(), free_bytes_available_to_caller, ~~~~ --- Retested `1fb1c5e27` on native Windows through the shim registry. For a missing child under mounted `GAME:`, both `GetDiskFreeSpaceExW` and `GetDiskFreeSpaceExA` now return FALSE and `ERROR_PATH_NOT_FOUND` (3), matching Win32. A missing child under `T:` also returns FALSE and 3. The existing directory and the `T:` root controls pass. My review point is addressed. AI-assisted.
MoonEyes commented 2026-11-28 09:48:58 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T09:48:58Z.


Red/green: tests/test_fs_disk_free_space.py fails on main (1 failed) and passes with this PR (1 passed).
Runtime batch of 20 PRs tested by OreoFR (full build, ctest without the game, Python suite, translator): same results as main 09c153948, RTX 4070 Laptop / Windows 11.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237484714 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2227#issuecomment-7237484714). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T09:48:58Z. --- Red/green: tests/test_fs_disk_free_space.py fails on main (1 failed) and passes with this PR (1 passed). Runtime batch of 20 PRs tested by OreoFR (full build, ctest without the game, Python suite, translator): same results as main 09c153948, RTX 4070 Laptop / Windows 11. AI-assisted (Claude Code, Claude Opus 5.5)
OreoFR commented 2026-11-28 22:00:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T22:00:15Z.


Verified by OreoFR

  • Base: main 09c153948 + PR head 1fb1c5e27; integration package 1 of 6 (20 PRs, merged without conflict)
  • Test: full runtime build; ctest -j 6 without the 28 tests that launch gta6rt; full Python suite; translator suite
  • Red on main: n/a (integration test; main baseline: xbox_present and d3d12_set_descriptor_heaps)
  • Green with the PR: ctest: only xbox_present and d3d12_set_descriptor_heaps fail, as on main; Python: the same 7 failing files as main, the PRs' 11 test files pass; translator: 0 failures
  • Verdict: CLEAN PACKAGE (no new failure vs main)
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246426821 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2227#issuecomment-7246426821). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T22:00:15Z. --- **Verified by OreoFR** - Base: main `09c153948` + PR head `1fb1c5e27`; integration package 1 of 6 (20 PRs, merged without conflict) - Test: full runtime build; ctest -j 6 without the 28 tests that launch gta6rt; full Python suite; translator suite - Red on main: n/a (integration test; main baseline: xbox_present and d3d12_set_descriptor_heaps) - Green with the PR: ctest: only xbox_present and d3d12_set_descriptor_heaps fail, as on main; Python: the same 7 failing files as main, the PRs' 11 test files pass; translator: 0 failures - Verdict: CLEAN PACKAGE (no new failure vs main) - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2227
No description provided.