fix(libSceSaveData.native): report a directory's own block count and free blocks #5173

Closed
Mouad-Scriptz-0 wants to merge 1 commit from upstream-pr/5173 into main
Mouad-Scriptz-0 commented 2026-10-13 13:50:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouad-Scriptz-0 on 2026-10-13T13:50:57Z.


What

sceSaveDataGetMountInfo and sceSaveDataDirNameSearch reported every directory as 32768 blocks with 32768 free. A mount that creates a directory now records the block count it asked for in a .blocks file next to the directory's .param file, and both calls report that count with the free blocks reduced by the directory's files in 32 KiB blocks. sceSaveDataDelete removes the record with the directory. A directory with no record (made before this change, or by hand) reports its files rounded up to the 96-block minimum as its allocation; opening one does not record the opening mount's count, which is not the creation size.

Minecraft (PPSA17221) sums the allocations of its save directories (the search's blocks, taken as 64 KiB each) against a 9 GiB budget and sets its low-storage state when less than 100 MiB is left (full below 10 MiB): five directories at the 32768-block maximum summed to 10 GiB, so it showed "You are almost out of data storage space" and refused to open or create worlds (read out of the title with gdb: used 10 GiB, total 9 GiB, available 0). With the recorded sizes (80 blocks for its settings, 1535 for its level cache) the sum is a few hundred blocks, worlds open and create, and the world list shows a world's real size (1.4 MB where it showed 0.01 MB).

Tested

Fedora 44 (kernel 7.2.8, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON), worktree on main 5d50886ee: new guest_savedata_blocks (a created directory reports its requested blocks, free blocks drop with files rounded up to 32 KiB blocks, the search agrees with the mount info, reopening with another count keeps the created size, delete removes the record, opening a directory without a record records nothing); a directory without a record reports its files rounded up to the minimum and grows with them; guest_savedata_search and guest_savedata_delete still pass; tools/check_conventions.py --base origin/main and git diff --check pass. Minecraft: worlds open and create again, and the world list shows a world's real size (1.4 MB where it showed 0.01 MB); the dialog stayed away through a play session. Not tested on Windows.

Checklist

  • Follows docs/dev/CONVENTIONS.md
  • Tests added or updated
  • No new technical debt without an entry
  • Unblocks: PPSA17221 (no Game bring-up discussion yet)
  • AI-assisted: yes (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4844267567 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5173). Originally posted by [Mouad-Scriptz-0](https://github.com/Mouad-Scriptz-0) on 2026-10-13T13:50:57Z. --- ### What `sceSaveDataGetMountInfo` and `sceSaveDataDirNameSearch` reported every directory as 32768 blocks with 32768 free. A mount that creates a directory now records the block count it asked for in a `.blocks` file next to the directory's `.param` file, and both calls report that count with the free blocks reduced by the directory's files in 32 KiB blocks. `sceSaveDataDelete` removes the record with the directory. A directory with no record (made before this change, or by hand) reports its files rounded up to the 96-block minimum as its allocation; opening one does not record the opening mount's count, which is not the creation size. Minecraft (PPSA17221) sums the allocations of its save directories (the search's `blocks`, taken as 64 KiB each) against a 9 GiB budget and sets its low-storage state when less than 100 MiB is left (full below 10 MiB): five directories at the 32768-block maximum summed to 10 GiB, so it showed "You are almost out of data storage space" and refused to open or create worlds (read out of the title with gdb: used 10 GiB, total 9 GiB, available 0). With the recorded sizes (80 blocks for its settings, 1535 for its level cache) the sum is a few hundred blocks, worlds open and create, and the world list shows a world's real size (1.4 MB where it showed 0.01 MB). ### Tested Fedora 44 (kernel 7.2.8, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`), worktree on `main` 5d50886ee: new `guest_savedata_blocks` (a created directory reports its requested blocks, free blocks drop with files rounded up to 32 KiB blocks, the search agrees with the mount info, reopening with another count keeps the created size, delete removes the record, opening a directory without a record records nothing); a directory without a record reports its files rounded up to the minimum and grows with them; `guest_savedata_search` and `guest_savedata_delete` still pass; `tools/check_conventions.py --base origin/main` and `git diff --check` pass. Minecraft: worlds open and create again, and the world list shows a world's real size (1.4 MB where it showed 0.01 MB); the dialog stayed away through a play session. Not tested on Windows. ### Checklist - [x] Follows `docs/dev/CONVENTIONS.md` - [x] Tests added or updated - [x] No new technical debt without an entry - [x] Unblocks: PPSA17221 (no Game bring-up discussion yet) - [x] AI-assisted: yes (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
johnmaia commented 2026-10-13 14:46:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-13T14:46:30Z.


Windows run, since the description says Windows is untested. Setup: Windows 11 (26300), WinLibs GCC 15.2.0 r7, Python 3.12, Git for Windows, Release, BUILD_TESTING=ON, ctest -j4 --timeout 300, RTX 4080. Head e8d947d31 merged into main 69b4ca5d9.

  • guest_savedata_blocks, guest_savedata_search and guest_savedata_delete pass.
  • The full suite passes 1082 of 1082.

Not tested: a negative control on Windows, and a title.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148229052 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5173#issuecomment-6148229052). Originally posted by [johnmaia](https://github.com/johnmaia) on 2026-10-13T14:46:30Z. --- Windows run, since the description says Windows is untested. Setup: Windows 11 (26300), WinLibs GCC 15.2.0 r7, Python 3.12, Git for Windows, Release, `BUILD_TESTING=ON`, `ctest -j4 --timeout 300`, RTX 4080. Head e8d947d31 merged into `main` 69b4ca5d9. - `guest_savedata_blocks`, `guest_savedata_search` and `guest_savedata_delete` pass. - The full suite passes 1082 of 1082. Not tested: a negative control on Windows, and a title. AI-assisted: yes (Claude Code)
Zenodeon commented 2026-10-14 08:20:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Zenodeon on 2026-10-14T08:20:26Z.


Windows validation of the submitted head e8d947d31cfdde0d8e27b4563e2a73a416fdad25:

  • Native Windows x86-64 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja Release, Python 3.12.14, BUILD_TESTING=ON, pinned submodules.
  • Configured the normal runtime project and built the save-data targets with the actual libc/libkernel/save-data/dialog libraries.
  • All 8 selected tests passed: guest_savedata_blocks, guest_savedata_search, guest_savedata_delete, guest_savedata_convert, guest_savedata_mount_status, guest_savedata_ps4, guest_savedata_cancel, and guest_savedata_dialog (0.21 s total, 30 s per-test limit).

An additional compatibility probe found a problem with allocation records produced by current main. Reproduction through the actual library:

  1. Mount a new save with CREATE2|RDWR and 80 blocks.
  2. Replace its adjacent .blocks file with the binary bytes 80\r\n.
  3. Call sceSaveDataGetMountInfo.

On this PR, the process terminates with:

SaveData: blocks file _sd/NEWLINE.blocks is not a number

Exit code: 0xC0000409. The same probe executable against rebuilt main 31bfc4e86 succeeds and reports blocks=80 free_blocks=80. Main's keep_save_blocks writes the number followed by a newline using a text-mode stream, producing this CRLF format on Windows; this PR's directory_blocks rejects every non-digit byte.

Main has also merged #5094, which already records allocations, calculates free blocks, and deletes the sidecar. This PR currently conflicts in Export.cpp. The legacy-save behavior still differs: this PR infers a minimum 96-block allocation from usage, whereas main reports the maximum until a mount supplies an allocation. That difference needs to be reconciled separately from the newline compatibility fix.

For comparison, main's 7 corresponding save-data/dialog tests passed (0.57 s total); it does not register guest_savedata_blocks. This is targeted native Windows validation, not a complete runtime suite or Minecraft/title validation.

AI-assisted: yes (OpenAI Codex).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6164069077 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5173#issuecomment-6164069077). Originally posted by [Zenodeon](https://github.com/Zenodeon) on 2026-10-14T08:20:26Z. --- Windows validation of the submitted head `e8d947d31cfdde0d8e27b4563e2a73a416fdad25`: - Native Windows x86-64 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja Release, Python 3.12.14, `BUILD_TESTING=ON`, pinned submodules. - Configured the normal runtime project and built the save-data targets with the actual libc/libkernel/save-data/dialog libraries. - All 8 selected tests passed: `guest_savedata_blocks`, `guest_savedata_search`, `guest_savedata_delete`, `guest_savedata_convert`, `guest_savedata_mount_status`, `guest_savedata_ps4`, `guest_savedata_cancel`, and `guest_savedata_dialog` (0.21 s total, 30 s per-test limit). An additional compatibility probe found a problem with allocation records produced by current main. Reproduction through the actual library: 1. Mount a new save with CREATE2|RDWR and 80 blocks. 2. Replace its adjacent `.blocks` file with the binary bytes `80\r\n`. 3. Call `sceSaveDataGetMountInfo`. On this PR, the process terminates with: ```text SaveData: blocks file _sd/NEWLINE.blocks is not a number ``` Exit code: `0xC0000409`. The same probe executable against rebuilt main `31bfc4e86` succeeds and reports `blocks=80 free_blocks=80`. Main's `keep_save_blocks` writes the number followed by a newline using a text-mode stream, producing this CRLF format on Windows; this PR's `directory_blocks` rejects every non-digit byte. Main has also merged #5094, which already records allocations, calculates free blocks, and deletes the sidecar. This PR currently conflicts in `Export.cpp`. The legacy-save behavior still differs: this PR infers a minimum 96-block allocation from usage, whereas main reports the maximum until a mount supplies an allocation. That difference needs to be reconciled separately from the newline compatibility fix. For comparison, main's 7 corresponding save-data/dialog tests passed (0.57 s total); it does not register `guest_savedata_blocks`. This is targeted native Windows validation, not a complete runtime suite or Minecraft/title validation. AI-assisted: yes (OpenAI Codex).
adriadam10 commented 2026-10-14 17:59:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T17:59:24Z.


Closing: #5094 (merged today) already records the creating mount's block count in the same <dir>.blocks file and reports it from both sceSaveDataGetMountInfo and sceSaveDataDirNameSearch (save_blocks/search_info in Export.cpp), so this PR now conflicts with main in Export.cpp and duplicates that mechanism.

What is not on main is the fallback for a directory with no .blocks record (its files rounded up to the 96-block minimum instead of 32768) and create2 && !exists when recording. If you still want those, please reopen or send a small PR on top of current main with just that part, reusing the existing search_info helpers and a test that fails without it. The Conventions check on the current head is also red, so please check it when you rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6174879016 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5173#issuecomment-6174879016). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T17:59:24Z. --- Closing: #5094 (merged today) already records the creating mount's block count in the same `<dir>.blocks` file and reports it from both `sceSaveDataGetMountInfo` and `sceSaveDataDirNameSearch` (`save_blocks`/`search_info` in `Export.cpp`), so this PR now conflicts with main in `Export.cpp` and duplicates that mechanism. What is not on main is the fallback for a directory with no `.blocks` record (its files rounded up to the 96-block minimum instead of 32768) and `create2 && !exists` when recording. If you still want those, please reopen or send a small PR on top of current main with just that part, reusing the existing `search_info` helpers and a test that fails without it. The Conventions check on the current head is also red, so please check it when you rebase.

Pull request closed

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
boykopovar/AnyPS5!5173
No description provided.