Skip to content

automount: wait for an expected external card before using internal - #3285

Open
maxengel wants to merge 1 commit into
ROCKNIX:nextfrom
maxengel:pr/automount-card-wait
Open

maxengel wants to merge 1 commit into
ROCKNIX:nextfrom
maxengel:pr/automount-card-wait

Conversation

@maxengel

@maxengel maxengel commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

What

On a device with two microSD cards, automount's find_games scans for the external games card once. When the card has not enumerated yet at that moment (a cold boot, a card slow to come up), the scan finds nothing and the script binds the internal card over /storage/roms. Anything written to /storage/roms during that boot — game saves, a restore — lands on the internal card, where it lingers and later reads as that device's newest data. Observed on an Anbernic RG SP: 101 stale save files on the internal card with both cards inserted the whole time.

Fix

find_games retries the scan when the device expects an external card — system.merged.device is external (it has mounted one before) or system.gamesdevice is pinned. It waits only while a candidate block device is physically present but not yet readable (a non-internal disk over ~8 GB under /sys/block), so:

Situation Added to boot
card present and ready (the normal boot) 0 s
card present, filesystem a moment slow its own lateness
card removed 2 s, then internal
one-card device 0 s
card present but never readable 10 s, then internal

A one-card device has neither signal and never waits. The helper's sed expressions are single-quoted: a double-quoted "s#p[0-9]*$##" had bash expand $#.

Testing

  • The real find_games body run under mocked block devices for the seven situations above (card present, card late, card removed, one-card, unset setting, pinned device with a late card, present-but-unreadable): each falls where the table says.
  • A GENERIC_X64 build and two Anbernic H700 handhelds: the RG SP (two cards) binds its external card at boot with no wait and writes nothing to the internal one; the RG35XX SP (one card) assumes internal without waiting, as before.

No user-facing option or documentation changes.

On a device with two microSD cards, find_games scans for the external
card once. When the card has not enumerated yet at that moment (a cold
boot, a card that is slow to come up), the scan finds nothing and the
script binds the internal card over /storage/roms. Anything written to
/storage/roms during that boot -- a cloud restore of game saves, a
save written by a game -- lands on the internal card, where it lingers
and later reads as that device's newest data. Observed on an RG SP:
101 stale save files on the internal card with both cards inserted the
whole time.

find_games now retries the scan when the device expects an external
card: system.merged.device is external (it has mounted one before) or
system.gamesdevice is pinned. It waits only while a candidate block
device is actually present but not yet readable -- a non-internal disk
over ~8 GB under /sys/block -- so a card that was removed has no node
and boot falls back to internal after a two-second grace; the ceiling
is 10 seconds and is paid only by a card that never becomes readable.
A one-card device has neither signal and does not wait.

Boot cost, verified against the real functions with mocked block
devices: card present and ready 0 s; card present but slow, its own
lateness; card removed 2 s; one-card device 0 s; card present but
never readable 10 s then internal.

The helper's sed expressions are single-quoted: a double-quoted
"s#p[0-9]*$##" had bash expand $# and broke the command.
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