Skip to content

DS: keep unpacked zips under 2 GB, and Delete, Rename and Storage handle them - #468

Draft
tarikbc wants to merge 6 commits into
mainfrom
ds-cleanup
Draft

tarikbc wants to merge 6 commits into
mainfrom
ds-cleanup

Conversation

@tarikbc

@tarikbc tarikbc commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Asked for on Discord: decompressed ROMs pile up in Roms/Nintendo DS/.dsperate.

What writes .dsperate, and why

The core writes it, not Diatom or the launcher. dsperate-lr sets block_extract, so DSperate gets the zip itself. DSperate maps the ROM from a file instead of holding it in RAM, so it inflates a deflated zip once to .dsperate/<zip stem>.nds (plus a .nds.tag naming the zip) beside the zip, and keeps it so the next launch maps it at once (DSperate's src/core/cart/zip_cache.h). A zip that stores its ROM is mapped in place, and a loose .nds needs nothing.

DSperate's own frontend keeps that folder under 2 GB (cart.cache_mb = 2048), oldest launch first. The libretro wrapper never set NDS::rom_cache_max_bytes, so on ZyperOS there was no cap at all. Delete Game left the copy behind, Rename orphaned it, and Storage counted it under the DS page's Other Files.

Nothing of the player's needs the copy. The save is named after the zip, and a state checks its ROM by the unpacked header and size (NDS::rom_identity), which a copy unpacked again has too. A removed copy only costs the next launch its unpacking.

What changes

  • The core (mk/patches/dsperate-lr-zip-cache.patch): the wrapper sets rom_cache_max_bytes to DSperate's own 2 GB, so the core removes the oldest copies as it unpacks a new one. mk/dsperate-zipcache-check.sh loads a zip beside 2.5 GB of unpacked games in the built core. The build script runs it, and the new sha is pinned. The other DS core checks (clock, extended BGs, v3.0.5 state) still pass.
  • The launcher holds the same rule after each DS game (src/dscache.{h,c}, src/launch_screen.c): 2 GB a .dsperate folder, oldest launch first, never the game just played. It uses DSperate's own count and order. A card that a core without the patch filled comes back under the cap after its next DS game.
  • Delete Game takes a zipped DS game's .nds, .nds.tag and .nds.part, then .dsperate once it is empty (src/gamedel.c). Storage sizes a game by that plan, so the copy now shows on the game's row, not under Other Files.
  • Rename moves the copy and its tag and rewrites the tag's archive line to the new zip's realpath, so DSperate does not unpack the game again (src/gamern.c). A copy already under the new name (a game deleted elsewhere) does not refuse the rename: this copy then stays behind for DSperate to sweep.
  • MENU > Storage: Unpacked DS Games, a third recommendation beside Unused Art and Old Save States (src/storage.c, src/storage_screen.c). It sums every .dsperate, at a system folder's top and in each folder of games, from the walk's own listings. It deletes .nds, .nds.tag and .nds.part there and nothing else, then the folder once it is empty. It never follows a link and never leaves Roms/, so saves and states are out of reach. Its question: "Delete the unpacked copies of zipped DS games? 1.8 GB. Saves and states stay, and each game unpacks again when it starts." A game's size also follows its .dsperate folder's time, so a copy unpacked again is sized again.
  • Diatom logs each retro_load_game's time, as it already does for dlopen and retro_init. That line is how to measure the unpacking on the handheld (below).
  • Strings in all 8 languages. The guide, DESIGN.md 11.31, 11.32 and 11.41, the README Storage picture, THIRD-PARTY-LICENSES and docs/building.md are updated.

You need to rebuild the core

vendor/ is not in git, so your checkout still has the old core. Run sh mk/build-dsperate.sh (about four minutes, in Docker). Until then mk/payload.sh refuses it, through mk/core-stamp.sh: "dsperate_libretro.so is not the build of the patches here ... run sh mk/build-dsperate.sh". The new core's sha256 is 0361a61a571ce61d34d3c8407cc71a6c288cf808c7bd9efc449d6ec03763093b. I built it with the wrapper's own Dockerfile toolchain (GCC 13.3.0-6ubuntu2~24.04.1). The same toolchain without the new patch gives the pinned 5b42bc5c... byte for byte, so the patch is the only difference.

Measured

On this Mac (M-series, arm64 Docker VM, the built core's own open_zip through retro_load_game), on DS-like images of 55% incompressible data, 15% structured data and 0xFF padding, zipped with Deflate level 6:

Card size Zip First launch (unpack) Next launch (copy kept)
128 MB 77 MB 511 ms 14 ms
256 MB 153 MB 945 ms 13 ms
512 MB 307 MB 1981 ms 14 ms

macOS's unzip -p of the 512 MB zip took 2.27 s. The Pixel 2's Cortex-A35 inflates several times slower, and its microSD card writes at tens of MB/s, so I expect seconds to tens of seconds for a large game there. That is why the copies are worth keeping under a cap rather than deleting after each game. I did not measure it on the Pixel 2. To measure it there:

  1. Deploy this branch with the rebuilt core (tools/px2-deploy.sh), and put a zipped DS game in Roms/Nintendo DS/.
  2. ssh root@zyperos.local, then rm -f "/mnt/SDCARD/Roms/Nintendo DS/.dsperate/<zip name>.nds"* so the next start unpacks it.
  3. Start the game from the shelf, wait for its first frame, and quit. Then start and quit it once more.
  4. tools/px2 log | grep "retro_load_game dsperate": the first line is the unpack plus the load, and the second is the load alone. The difference is the unpack. ls -l the copy for its size.

Choices I made

  • 2 GB per .dsperate folder, DSperate's own default, in both the core and the launcher. A folder of games has its own, as in DSperate.
  • "Unpacked DS Games" uses the current confirm panel (store_ask). The confirm-panels branch is not pushed yet. When it lands, this needs a CQ_STORE_DS_COPIES entry in its table, as Unused Art and Old Save States get there.
  • The row shows a size and no count of games: the walk's cached listings have the bytes but not the file names.

Checked

  • make check-dscache: the paths; the cap; Delete Game; Rename (the copy and tag moved, the tag naming the new zip and nothing else in it changed, a copy under the new name not refusing it, a loose .nds taking nothing); Storage (a game's size holds its copy and follows it); and Unpacked DS Games (it measures both .dsperate folders and deletes the copies, tags and .part and nothing else, and a stray file, the zips, the save and the state stay). Without each change it fails: Delete Game 7 times and Rename 4 times. With src/storage.c as on main it does not link (no st_delete_ds_copies); without only the .dsperate time in a game's signature, it fails once.
  • mk/dsperate-zipcache-check.sh: the old core fails "the oldest launch's copy went", and the new one passes all four.
  • diatom/test/coreend.py asserts the new log line on every game's load. It fails 6 times without it.
  • Shots: Storage with the new row, and its question, light and dark, in all 8 languages and the pseudo-locale. German, French and Spanish questions are shortened to fit the panel's four lines.
  • make native, then make -j4 check: all 274 checks pass, check-i18n-shots included.

Confirm panels (#479)

main, with #479, is merged in. Unpacked DS Games asks with the new panel: CQ_STORE_DS_COPIES, the 40th question and the 34th marked as losing something, as Unused Art is. Its heading is the action (storage.ds_heading: "Delete Unpacked DS Games", "Entpackte DS-Spiele löschen", "Supprimer les copies DS", ...), and the question is storage.ds_ask. Storage's shot of it is confirm_preview's, i18n-shots has ask-storage-ds-copies, and check-confirm counts 40 and 34 and lays it out on every handheld in every language: side by side, nothing cut.

Linux

check-linux failed on two things in the DS check, and both are fixed:

  • Ubuntu's GCC with -Werror=format-truncation. Every path in tools/dscache-check.c and tools/dsperate-zipcache-check.c now goes through PATHF, which stops the check and says where when a path would not fit. The launcher files the check links are held to the same rule: a path that would not fit is skipped, not used cut. This covers Storage's states folder, .media and Ports subfolder, Delete Game's NAOMI folder and portinfo.c's GAMEDIR. A port's title is cut at a whole UTF-8 character.
  • glibc's fortified realpath (Ubuntu builds with _FORTIFY_SOURCE=3) aborts on any buffer smaller than PATH_MAX. The check's Rename part, and Storage's Linux-only look at the card's partitions (/sys/dev/block), gave it 1200 bytes. Both use PATH_MAX now.

DSperate reads a zipped DS game itself and, since it maps the ROM from a
file instead of holding it in RAM, inflates it once to
.dsperate/<zip stem>.nds beside the zip and keeps it for the next launch.
Its own frontend keeps that folder under 2 GB (cart.cache_mb), the least
recently launched first. The libretro wrapper never set that cap, so every
zipped DS game I ever played stayed there at its full unpacked size, and
Delete Game left it behind too.

Nothing of the player's needs that copy: the save is named after the zip
and a state knows its ROM by the unpacked header and size, which a copy
unpacked again has too. So the launcher now holds DSperate's own rule after
each DS game (2 GB a .dsperate folder, oldest launch first, never the game
just played), Delete Game takes a game's copy and tag with it, and Storage
counts the copy as the game's and follows it when it is unpacked again.

make check-dscache fails on every part without this.

Asked for on Discord.
…d DS Games

The rest of the .dsperate cleanup.

- The core: mk/patches/dsperate-lr-zip-cache.patch makes the wrapper set
  NDS::rom_cache_max_bytes to DSperate's own 2 GB, so the core removes the
  oldest copies as it unpacks a new one, as the launcher does after each
  game. mk/dsperate-zipcache-check.sh loads a zip beside 2.5 GB of unpacked
  games in the built core; the build runs it. New sha pinned: the same
  toolchain without the patch gives the old sha byte for byte.
- Rename moves the copy and its tag and points the tag's archive line at
  the new zip, so the game is not unpacked again. A copy already under the
  new name does not refuse the rename.
- MENU > Storage: Unpacked DS Games, a third recommendation. It sums every
  .dsperate from the walk's listings and deletes the copies, their tags and
  .part files there and nothing else; saves and states are out of reach.
  Strings in all 8 languages, shots in both themes.
- Diatom logs how long each retro_load_game took, which is how to measure
  the unpacking on the handheld.

Asked for on Discord.
@tarikbc tarikbc changed the title DS: keep the unpacked zips under 2 GB, and delete a game's copy with it DS: keep unpacked zips under 2 GB, and Delete, Rename and Storage handle them Nov 23, 2026
Ubuntu's GCC failed check-linux on tools/dscache-check.c with
-Werror=format-truncation: every path it built went into a buffer the
size of the folder's own. Each path in that check and in the core's
zip-cache check now goes through PATHF, which stops the check and says
where when a path would not fit, instead of testing a cut path.

The launcher files the check links were built with -Werror on Linux for
the first time too, and their paths are held to the same rule now: a
system's states folder, a game's .media and file in Storage, a Ports
folder's subfolder, a NAOMI set's CHD folder in Delete Game and a
GAMEDIR name in portinfo.c are each skipped when they would not fit,
not used cut; a port's title is cut at a whole UTF-8 character. The DS
paths I added (the romdir after a DS game, a game's .dsperate in
Storage's signature, the realpath a renamed tag names) check theirs.
Ubuntu builds with _FORTIFY_SOURCE=3, and glibc's fortified realpath
aborts ("buffer overflow detected") on a buffer smaller than PATH_MAX,
whatever the path. check-dscache's Rename part passed realpath 1200
bytes, and so did Storage's Linux-only look at the card's partitions
(st_measure's /sys/dev/block), which the check's Storage part reaches.
Both are PATH_MAX now.
Unpacked DS Games asks with the new panel: CQ_STORE_DS_COPIES, the 40th
question, the 34th marked as losing something, as Unused Art is. Its
heading is the action in each language (storage.ds_heading); French and
Italian short enough for one line. The question is storage.ds_ask, as
before. Storage's shot of it is confirm_preview's, and check-confirm and
i18n-shots know it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant