Respect the persistent local storage quota in GetDiskFreeSpaceEx #228

Merged
ZekkJJ merged 2 commits from upstream-pr/231 into main 2026-11-23 21:29:52 +00:00
ZekkJJ commented 2026-11-23 21:25:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ZekkJJ on 2026-11-23T21:25:23Z.


Refs #106 (persistent local storage reporting).

XPersistentLocalStorageGetPath exposes the title’s PLS folder through S:\ by default. The GetDiskFreeSpaceExW/A hooks resolve that mount to the host directory, where Windows reports capacity for the entire volume. A title can therefore see the host’s capacity even when its PLS quota is nearly full.

For a translated PLS path, cap the reported total at the smaller of the configured quota and the Windows caller-visible total. Subtract the logical sizes of existing PLS files from the configured quota, then cap caller-available and volume-free bytes independently using their native values. Count files from the PLS root even when the query names a child directory. The hooks use the same quota conversion and usage traversal as XPersistentLocalStorageGetSpaceInfo.

The translated directory still goes through the native Win32 query. The hooks preserve native failure codes and optional outputs. The ANSI hook uses Windows’ active file code page. Ordinary host paths keep their native capacity figures. Queries that omit both free-space outputs skip the usage walk.

Regression evidence

The synthetic fixture resolves a 1 MiB MicrosoftGame.Config quota and writes 579 bytes of files across two directories.

Measurement Before on 956a476 After
Total bytes 1,021,821,579,264 1,048,576
Caller-available bytes 172,265,959,424 1,047,997
Volume-free bytes 172,265,959,424 1,047,997

The final regression exercises both detours, including a Unicode child directory and an OEM-encoded ANSI path on code page 437. It also checks an alias mount, an exhausted quota, ordinary host paths, null arguments, and a missing directory. A separate unit test checks the zero-config fallback, saturating conversion of oversized quotas, and independent host limits for caller-available and volume-free bytes.

Verification on Windows with Rust 1.95.0

Validated against main at eaa36b6.

  • cargo +1.95.0 build --locked --workspace passed.
  • cargo +1.95.0 test --locked -p xcl --test pls_quota -- --nocapture passed.
  • cargo +1.95.0 test --locked --workspace -- --test-threads=4 --nocapture reported 586 passed, 0 failed, and 39 ignored. Two wave64 cases reported runtime skips. The opt-in retail sample variables were unset.
  • cargo +1.95.0 clippy --locked --workspace --all-targets passed with the same diagnostics as clean main.
  • cargo +1.95.0 fmt --all --check reported existing formatting differences on both clean main and the patch. Rustfmt was applied to the changed lines. git diff --check passed.

After merging main at af20b4b, all 10 VFS hook unit tests and the native PLS regression passed again. The contribution diff is identical to the reviewed commit.

<!-- greyfinch-sync:ivall/xcl:issue:6569147037 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/231). Originally posted by [ZekkJJ](https://github.com/ZekkJJ) on 2026-11-23T21:25:23Z. --- Refs #106 (persistent local storage reporting). `XPersistentLocalStorageGetPath` exposes the title’s PLS folder through `S:\` by default. The `GetDiskFreeSpaceExW/A` hooks resolve that mount to the host directory, where Windows reports capacity for the entire volume. A title can therefore see the host’s capacity even when its PLS quota is nearly full. For a translated PLS path, cap the reported total at the smaller of the configured quota and the Windows caller-visible total. Subtract the logical sizes of existing PLS files from the configured quota, then cap caller-available and volume-free bytes independently using their native values. Count files from the PLS root even when the query names a child directory. The hooks use the same quota conversion and usage traversal as `XPersistentLocalStorageGetSpaceInfo`. The translated directory still goes through the native Win32 query. The hooks preserve native failure codes and optional outputs. The ANSI hook uses Windows’ active file code page. Ordinary host paths keep their native capacity figures. Queries that omit both free-space outputs skip the usage walk. ## Regression evidence The synthetic fixture resolves a 1 MiB `MicrosoftGame.Config` quota and writes 579 bytes of files across two directories. | Measurement | Before on `956a476` | After | | --- | ---: | ---: | | Total bytes | 1,021,821,579,264 | 1,048,576 | | Caller-available bytes | 172,265,959,424 | 1,047,997 | | Volume-free bytes | 172,265,959,424 | 1,047,997 | The final regression exercises both detours, including a Unicode child directory and an OEM-encoded ANSI path on code page 437. It also checks an alias mount, an exhausted quota, ordinary host paths, null arguments, and a missing directory. A separate unit test checks the zero-config fallback, saturating conversion of oversized quotas, and independent host limits for caller-available and volume-free bytes. ## Verification on Windows with Rust 1.95.0 Validated against `main` at `eaa36b6`. - `cargo +1.95.0 build --locked --workspace` passed. - `cargo +1.95.0 test --locked -p xcl --test pls_quota -- --nocapture` passed. - `cargo +1.95.0 test --locked --workspace -- --test-threads=4 --nocapture` reported 586 passed, 0 failed, and 39 ignored. Two wave64 cases reported runtime skips. The opt-in retail sample variables were unset. - `cargo +1.95.0 clippy --locked --workspace --all-targets` passed with the same diagnostics as clean `main`. - `cargo +1.95.0 fmt --all --check` reported existing formatting differences on both clean `main` and the patch. Rustfmt was applied to the changed lines. `git diff --check` passed. After merging `main` at `af20b4b`, all 10 VFS hook unit tests and the native PLS regression passed again. The contribution diff is identical to the reviewed commit.
upstream-sync closed this pull request 2026-11-24 06:57:45 +00:00
ivall commented 2026-11-24 07:04:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ivall on 2026-11-23T21:29:56Z.


Merged (main 0f34407). Checked on an RX 9070 (RDNA4) with 6 PRs merged together on main d4f17ca: cargo build --workspace && cargo test --workspace -- --test-threads=4 - 611 unit tests passed, 0 failed (20 ignored), the integration and e2e tests passed; and the retail game still reaches its first menu at 30 fps.

<!-- greyfinch-sync:ivall/xcl:comment:7114540445 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/231#issuecomment-7114540445). Originally posted by [ivall](https://github.com/ivall) on 2026-11-23T21:29:56Z. --- Merged (main 0f34407). Checked on an RX 9070 (RDNA4) with 6 PRs merged together on main d4f17ca: `cargo build --workspace && cargo test --workspace -- --test-threads=4` - 611 unit tests passed, 0 failed (20 ignored), the integration and e2e tests passed; and the retail game still reaches its first menu at 30 fps.
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
xcl-dev/xcl!228
No description provided.