Skip to content

libretro: read media through the frontend's VFS - #58

Open
WizzardSK wants to merge 1 commit into
libretro:libretrofrom
WizzardSK:vfs-support
Open

libretro: read media through the frontend's VFS#58
WizzardSK wants to merge 1 commit into
libretro:libretrofrom
WizzardSK:vfs-support

Conversation

@WizzardSK

@WizzardSK WizzardSK commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Closes #56.

On Android the frontend hands out Storage Access Framework content:// URIs, and an SMB share is smb://; fopen() can do nothing with either. Plain ROMs already arrive in memory through the content info override, so what was unreachable is everything the core opens by name itself: CD images (cue/toc/iso/chd) and every track file a cue sheet points at, compressed ROMs, and the Sega CD, 32X, Colecovision and LaserActive BIOS.

vfs_file.c talks to RETRO_ENVIRONMENT_GET_VFS_INTERFACE and media_file.h selects it for the libretro build alone; with no interface on offer, or in the standalone emulator, it compiles down to the same stdio calls as before. Two things needed more than a rename: gzip used to come from gzopen(), which takes a filename and cannot be pointed at a VFS handle, so a gzipped file is read through the VFS and inflated in memory (falling back to reading it as-is unless a complete stream comes out); and CHDs go through chd_open_core_file() with a bridge to the same layer instead of chd_open(), which opens the path itself. is_absolute_path() also had to be relaxed for the BIOS lookups — a URI does not look absolute to it, so the path fell through to read_bundled_file(), which in a libretro build never finds anything.

Tested with a harness that offers the core a VFS whose paths carry a scheme nothing else can resolve, so a successful load proves the callbacks were used: ROM, gzipped ROM, cue plus its track file, iso and the BIOS all load through it, an invalid CHD fails cleanly with the existing message, and with the interface withheld everything still loads over stdio. The gzipped and uncompressed ROM produce identical framebuffers after 30 frames. Standalone was checked by type-checking the shared translation units without IS_LIB; system.c, coleco.c and laseractive.c need SDL/GLES headers I don't have here, and their changes are either inside #ifdef IS_LIB or macros expanding to the exact stdio calls that were there before.

Requested in libretro#56: on Android the frontend hands out Storage Access
Framework content:// URIs, and an SMB share is smb://, neither of which
fopen() can do anything with.

Plain ROMs already arrive in memory through the content info override, so
what was left unreachable is everything the core opens by name itself: CD
images (cue/toc/iso/chd) and every track file a cue sheet points at,
compressed ROMs, and the Sega CD, 32X, Colecovision and LaserActive BIOS.

vfs_file.c is that layer, and media_file.h picks it over stdio for the
libretro build alone - with no VFS interface on offer, or in the
standalone emulator, it is the same stdio calls as before. gzip needed
handling of its own: it used to come from gzopen(), which takes a
filename and so cannot be pointed at a VFS handle, so a gzipped file is
now read through the VFS and inflated in memory, falling back to reading
the file as-is unless a complete stream comes out. CHDs go through
chd_open_core_file() with a bridge to the same layer rather than
chd_open(), which would open the path itself.

is_absolute_path() had to be relaxed for the BIOS lookups: a URI does not
look absolute to it, so the BIOS path was falling through to
read_bundled_file(), which in a libretro build never finds anything.

Tested with a harness that offers the core a VFS whose paths carry a
scheme nothing else can resolve, so a successful load proves the callbacks
were used: ROM, gzipped ROM, cue plus its track file, iso, and the BIOS
all load through it, an invalid CHD fails cleanly with the right message,
and with the interface withheld everything still loads over stdio. The
gzipped and uncompressed ROM produce identical framebuffers after 30
frames.
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.

VFS Support

1 participant