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

Open
github-bot wants to merge 2 commits from github-bot/gh-2227 into main AGit
Owner

@⁠matinsanei on GitHub · 2026-11-26 07:52 UTC · original
matinsanei:feat/fs-disk-free-space → main · +162 −0 · 2 files · 2 commits · open

Claimed in the coordination issue as: RT-FS-DISK-FREE-SPACE (#1608)

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)
**@⁠matinsanei** on GitHub · 2026-11-26 07:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2227) `matinsanei:feat/fs-disk-free-space` → `main` · +162 −0 · 2 files · 2 commits · open Claimed in the coordination issue as: RT-FS-DISK-FREE-SPACE (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### 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)
Resolve console roots (GAME:\, G:\, T:\) to mapped host paths before
querying host disk geometry and capacity, and provide synthetic Xbox
console storage fallback quotas when unmounted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:22:55 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-26 07:52 UTC · original · reviewed

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.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-26 07:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2227#pullrequestreview-6070291617) · **reviewed** 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.
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 08:47 UTC · original · reviewed

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** on GitHub · 2026-11-26 08:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2227#pullrequestreview-6070941127) · **reviewed** 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.
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 08:47 UTC · original
On runtime/shims/file_system.cpp line 1603 (outdated):

@@ -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.

**@⁠lixonik** on GitHub · 2026-11-26 08:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2227#discussion_r4705794209) On `runtime/shims/file_system.cpp` line 1603 (outdated): ```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.
Author
Owner

@⁠matinsanei on GitHub · 2026-11-26 10:11 UTC · original
On runtime/shims/file_system.cpp line 1603 (outdated):

@@ -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.

**@⁠matinsanei** on GitHub · 2026-11-26 10:11 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2227#discussion_r4706773083) On `runtime/shims/file_system.cpp` line 1603 (outdated): ```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.
When a console root is mounted, resolve the directory path through view()
so non-existent subdirectories correctly return ERROR_PATH_NOT_FOUND to match
Win32 GetDiskFreeSpaceEx behavior.
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 10:32 UTC · original
On runtime/shims/file_system.cpp line 1603 (outdated):

@@ -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.

**@⁠lixonik** on GitHub · 2026-11-26 10:32 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2227#discussion_r4707041086) On `runtime/shims/file_system.cpp` line 1603 (outdated): ```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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2227/head:github-bot/gh-2227'
git switch 'github-bot/gh-2227'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2227'
git switch 'github-bot/gh-2227'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2227'
git switch 'github-bot/gh-2227'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2227'
git switch 'main'
git merge --squash 'github-bot/gh-2227'
git switch 'main'
git merge --ff-only 'github-bot/gh-2227'
git switch 'main'
git merge 'github-bot/gh-2227'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.