Skip to content

Add support for libretro VFS (and file IO indirection in general). - #2299

Merged
flyinghead merged 3 commits into
flyinghead:devfrom
Clownacy:libretro-vfs
Apr 11, 2026
Merged

flyinghead merged 3 commits into
flyinghead:devfrom
Clownacy:libretro-vfs

Conversation

@Clownacy

@Clownacy Clownacy commented Apr 4, 2026 •

Copy link
Copy Markdown
Contributor

This is enough to get a CHD file of Sonic Adventure to load over SMB in RetroArch. This should allow for loading files via Android's Storage Access Framework in RetroArch as well.

The changes to .zip, .7z, and .png loading need testing. Are these formats only used by texture packs, or is there another way to test them?

Currently, the file indirection only covers files which are opened with hostfs::storage().openFile; files which are opened with nowide::fopen directly are unaffected. If needed, I can look into migrating the remaining file IO to this new system.

I have done what I can to keep the indirect file API similar to the standard C file API, to minimise the impact on the codebase.

In the future, this new API can be expanded upon to streamline file IO, such as closing files automatically using RAII, instead of needing to manually close them with delete (which is the replacement for fclose).

Closes #2100.

@flyinghead

Copy link
Copy Markdown
Owner

Sorry for the delay but I've been busy on other fronts. I'll need some more time to review this.
In the mean time can you target the dev branch instead of master? Thanks

.zip files are used for arcade ROMs of course, but also for internal resources (see oslib/resources.*). And also custom adreno GPU drivers iirc.
png and jpg are used all over the place: ROM box art, save state thumbnails, screenshots, retroachievements images and, of course, custom textures.

@Clownacy
Clownacy changed the base branch from master to dev April 9, 2026 17:27
Clownacy added 3 commits April 9, 2026 18:32
libzip, 7zip, libchdr, and stb_image.

This will allow replacing the C-style file IO in a future commit.
Will be useful for adding support for libretro's Virtual File System.

Currently just a pass-through to C file IO.
Some libretro-common files needed updating, which necessitated
changes in `libretro.cpp`.
@Clownacy

Clownacy commented Apr 9, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on dev.

Box art, save state thumbnails, and RetroAchievement icons all appear correctly, so stb_image appears to be working. Files such as Roboto-Medium.ttf.zip load, so libzip is working also.

@flyinghead
flyinghead merged commit 16345df into flyinghead:dev Apr 11, 2026
19 checks passed
@i30817

i30817 commented May 9, 2026 •

Copy link
Copy Markdown
Contributor

@Clownacy unless the buildbot is not running for android, this is not working with chds running in webdav (the saf path is using rsaf as a file provider and the permissions are correct for the paths and files and other cores with this support work).

There is something missing.

The error message in the logs is:

shell/libretro/libretro.cpp:1293 E[BOOT]: Cannot stat saf://content:%2F%2Fcom.chiller3.rsaf.documents%2Ftree%2Fgameslocal%253A/Sega - Dreamcast/Original/Armada (USA)/Armada (USA).chd
[Environ] SET_MESSAGE: Cannot stat saf://content:%2F%2Fcom.chiller3.rsaf.documents%2Ftree%2Fgameslocal%253A/Sega - Dreamcast/Original/Armada (USA)/Armada (USA).chd

I also checked if the problem was the chd format (I used zstd compression) but the uncompressed cue/bin has the same problem.

@Clownacy

Clownacy commented May 9, 2026 •

Copy link
Copy Markdown
Contributor Author

This isn't on the build-bot yet: that tracks the master branch, but this only exists on the dev branch.

@i30817

i30817 commented May 9, 2026

Copy link
Copy Markdown
Contributor

Well, that's me told. Thanks for the info.

@flyinghead

Copy link
Copy Markdown
Owner

Merged into master

Immersion95 added a commit to Immersion95/flycast that referenced this pull request May 9, 2026
* added in-ram savestates (flyinghead#2252)

* readme: add packaging status (flyinghead#2266)

[ci skip]

* android: update project

* Touch screen emulation for Fish Life

Issue flyinghead#2234

* rend: Detect game FPS and adjust gl/dx swap interval

Detect games running at 30 FPS and double the opengl or directx 9/11
swap interval.
Issue flyinghead#520

* i18n: update pot

* missing localizable string

* i18n: update pot

* ui: make game filter match both filename and game title

* no swap interval support in dx9. Fix rounding of refresh rate on windows

DX9 windowed mode only supports a swap interval of one (and immediate).
Windows reports a refresh rate of 59.94 Hz or 119.98 Hz, which is
rounded down by SDL. This causes the calculated swap interval for 30 FPS
to be less than 2 (for 60 Hz).
Issue flyinghead#520

* sdl: test code leftover

[ci skip]

* Crowdin Translations (flyinghead#2273)

* android: google auto backup support

When enabled, all .cfg and all files in data except savestates are
backed up. Only the direct children of data are considered so boxart,
wwwcache, texdump, etc. are excluded.

* http: allow req and resp headers with GET. 30 s timeout. linux tests

Add http::get function with request and response header params.
Set a 30 s connection timeout for all http requests (except on macOS).
Linux tests with postb.in

* cheat: segfault accessing config db in destructor

* don't allocate memory when logging

Can lead to deadlock if crash happens in malloc/free

* win32 build fix

* modem: proper support of V.42 RNR

[ci skip]

* New translations strings.xml (Turkish)
New translations for {languageName}

* Language Picker

* emu: add locale change event. Simplify i18n UI

* ui: handle language change for Controls tab

lua update

* ui: don't call i18n in static init. msvc utf-8 source option

Don't call i18n::T in static init to avoid potential static init order
issue. Tentative fix for Issue flyinghead#2285
Call i18n::init() in i18n::reloadLanguage()

Set source files to utf-8 for MSVC

* Update imgui backends

* Load font based on locale priorities: CJK > User Locale > Other Locale, remove all glyph ranges

* Font weight/size tuning

* imgui: upgrade to 1.92.6

* Add freetype lib

* refactor font loading system to support weights, better CJK fallback, dynamic font file path from fontconfig for linux

* Replace `largeFont` with `uiLargeFontSize()` and/or `boldFont`

* Android: 32-bit unicode support

* Reject COLRv1 fonts (latest Fedora and possibly some Androids)

* gui_font.cpp

* Temp fix for C++17 and C++/CX

* i18n: update flycast.pot

* more robust elf loading

Fixes MINIDUMP-8G9 MINIDUMP-8NH

* rend: clamp config::PerPixelLayers to avoid shader compile errors

Make sure shaders/pipelines are reset when config changes.
Fixes MINIDUMP-8SY

* naomi: hide implementation details. no functional change

* pvr: avoid crash on invalid poly params

Fixes MINIDUMP-8PX

* ui: replace NULL by nullptr. No functional change

* clubk: set correct node type (disabled/master/slave) and car#

* dx11 build fix

* dricas auth bypass cheat for Rune Jade

[ci skip]

* Crowdin Translations (flyinghead#2291)

[ci skip]

* macOS: Use MAP_JIT from now on

* i18n: protect tinygettext log info set with mutex

Log functions can be called concurrently by multiple threads (game
loader, main, ...)
Fixes MINIDUMP-8WR

* generic dricas auth bypass for WinCE games

Intercept the GetProcAddress call and replace the function with an empty
but successful stub.
[ci skip]

* Crowdin Translations: Spanish, Swedish

* add Pause feature

[ci skip]

* macOS: support vanilla macOS bootstrap and update Vulkan SDK install

* deps: update Vulkan-Headers and VulkanMemoryAllocator

* Fetch translations & Recreate libretro_core_options_intl.h

* Add support for libretro VFS (and file IO indirection in general). (flyinghead#2299)

* Use custom file IO callbacks for libraries: libzip, 7zip, libchdr, and stb_image.
* Add file IO indirection.
* Add libretro VFS implementation.

---------

Co-authored-by: Clownacy <[email protected]>

* imgui: g.Font used instead of g.FontBaked

Fixes MINIDUMP-8WK

* Force PAL for Evil Twin - Cyprien's Chronicles

Issue flyinghead#2048

* samba: round/clamp/bias analog axis values as needed by the game

Issue flyinghead#2282

* chd: fix use-after-free crash when chd_open_file fails

chd_open_file (almost) always closes the passed file even in case of
error.
Fixes MINIDUMP-8ZK

* input: close all gamepads/keyboards/mice when terminating

Failure to do so may cause a static deinit order error on exit.
android: use AKEYCODE_ and AMOTION_EVENT_ system constants

* rend: make transform_matrix.cpp

* Windows: support vanilla bootstrap (flyinghead#2316)

[ci skip]

* docs: clarify download channels and desktop build scripts

* fix explicit template instantiations

* dx9 build fix

* rend: fix clipping with vscale>1. Get rid of scissor matrix

Fix framebuffer clipping when scale>1 (Stretched PAL). Issue flyinghead#728
Get rid of ScissorMatrix.
Don't scale framebuffer clipping rect in full FB emu.
Refactor rend_context. Use Rect and ivec2.

* Fetch translations & Recreate libretro_core_options_intl.h

* UI: Add option to discard video and animated textures during dump (flyinghead#2318)

ui: add option to discard video and animated textures during dump
Implement a filter to prevent flooding the texture dump directory with
thousands of redundant frames from FMVs or procedural effects.
- Add a single 'Discard Video and Animated Textures' option (enabled by default).
- Filter logic: skip dumping if the texture was already updated (Updates > 1)
  or if it uses the YUV format (video).
- Update UI in Advanced settings, French translations, and i18n template.

* macOS: allow building without vulkan

* win32: init winsock in main()

* rend: simplify scissor/dimensions handling. reduce code duplication

Fix regression with split-screen multi render in Quake 3. Caused by
aef3d2d.
Move duplicated code into transform_matrix. Handle framebuffer
dimensions/clipping scaling depending on render mode (Full FB emu, copy
RTT to vram).
Handle RTT and screen render similarly when possible.
[ci skip]

* Crowdin Translations (flyinghead#2319)

* Fetch translations & Recreate libretro_core_options_intl.h

* force real BIOS for MIL-CDs

Issue flyinghead#2321

* i18n: update flycast.pot

[ci skip]

* Crowdin Translations (Turkish)

* Fetch translations & Recreate libretro_core_options_intl.h

* Fetch translations & Recreate libretro_core_options_intl.h

* Crowdin Translations (flyinghead#2329)

[ci skip]

* android: update project

* flash: fix netmask for bomberman BBA

* dricas auth cheat for Nettou Golf. various minor changes

---------

Co-authored-by: eadmaster <[email protected]>
Co-authored-by: scribam <[email protected]>
Co-authored-by: Flyinghead <[email protected]>
Co-authored-by: flyinghead <[email protected]>
Co-authored-by: Edward Li <[email protected]>
Co-authored-by: vkedwardli <[email protected]>
Co-authored-by: github-actions[bot] <[email protected]>
Co-authored-by: Clownacy <[email protected]>
Co-authored-by: Clownacy <[email protected]>
Co-authored-by: Marc Gardent <[email protected]>
flyinghead pushed a commit that referenced this pull request Oct 12, 2026
)

Since the switch to hostfs::File (#2299), MD5Sum::add(hostfs::File *)
resolved to the generic add(const T&) template, which hashes the pointer
value. The resulting digests depend on the heap address, so they differ
between peers and between runs. This breaks GGPO peer verification when
a .state.net savestate is used (stateMD5), and with CDI, GDI and CUE
images (gameMD5).

Add an MD5Sum::add(hostfs::File *) overload that hashes the whole file
content, like the std::FILE overload, and reject pointer types in the
template with a static_assert so this cannot happen again silently.

Co-authored-by: unjordi <[email protected]>
[ci skip]
JoeMatt added a commit to Provenance-Emu/flycast that referenced this pull request Oct 22, 2026
Third and last chunk of the resync (v2.5 -> v2.6 -> master). 378
upstream commits; 81 files conflicted (17 vendored), 131 non-vendored
hunks. This chunk is mostly three upstream rewrites that our
iFly-only code (Metal renderer, app bridge) had to be ported onto,
plus the usual conflicts.

Upstream rewrites and how ours was ported:
- 31d5ddb scissor/dimensions: core/rend/tileclip.h deleted, clipping
  moved into transform_matrix. Metal renderer + OIT drawer ported the
  same way as upstream's Vulkan drawer: pvrrc -> rendContext member,
  getTileClip(val, Rect&), getBaseScissor(), RTT via framebufferWidth/
  Height + CalcMatrices + getPvrFramebufferSize, WriteTextureToVRam /
  WriteFramebuffer with Rect clips, globClip + getWriteFBToVramParams
  for the framebuffer write. OIT, two-volume, HDR, DbgSkipList and
  DbgSortedTrDump behaviour kept. TexCache: our NEON writeFramebuffer
  paths converted to the Rect clip.
- 08c63bd non-static graphics contexts: MetalContext now heap-created
  via MetalContext::Create(window, display) (throws FlycastException on
  init failure), deleted by GraphicsContext::Term(); typed
  contextInstance kept in sync so MetalContext::Instance() is null when
  the live context is not Metal. switcher.cpp takes upstream's try/catch
  chain with a Metal branch before the GL fallback, keeps our
  extern "C" initRenderApi export and the restore-original-renderer
  logic. libretro.cpp's Metal path moved to createMetalContext /
  termMetalContext / hasMetalContext wrappers; retro_unload_game now
  calls GraphicsContext::Term() (upstream shape).
- config subsystem: cfg* globals became namespace config (loadInt...),
  ConfigFile became IniFile. Ported IniFile::deleteEntryAllSections and
  config::deleteEntryAllSections (our per-game default migration), and
  added inline global cfg* forwarders at the end of core/cfg/cfg.h so the
  iFly app bridge (29 call sites) builds unchanged against old and new.
- libretro VFS (flyinghead#2299): naomi_cart_GetDecryptedPlatform and
  core/imgread/cdi_bridge.cpp (our .cdi import bridge) converted from
  FILE* to hostfs::File.
- Carbon MacTypes' Rect clashes with upstream's new global struct Rect
  in every ObjC++ TU (our Metal renderer, and the iFly app bridge, which
  imports UIKit as a module first, so no macro trick can help). Renamed
  flycast's Rect -> RendRect and pvr_regs' RGBColor -> PvrRGBColor
  (72 + 3 sites, mechanical; re-run the sed on future merges).
- maple: upstream made the MIE implementation file-local and
  getMieDevice() returns the public MIE type; added Pipe *serialPipe to
  it so NetworkSerialBridge.mm keeps compiling.

Other resolutions (both merge messages before this one list the
conventions): CMake follows upstream's per-directory layout, with a new
core/rend/metal/CMakeLists.txt, our NEON Vulkan sources and switcher.mm
re-added, DreamLink still excluded on tvOS; savestate enum auto-merged
(IflySh4CtxReorder stays 850, V57-V59 appended, Current = V59);
emulator.cpp takes upstream's ThreadRunner (runner.init/try +
execTasks at vblank) around our DbgSimulateBootHang gate and
host-paced dispatch; nullDC keeps our SH4 park/quiesce and gains
dc_savestateAllowed + fmemopen quicksave; input keeps our host-app
overrides with upstream's ctor/i18n (menu falls back to
gui_togglePause); GUI keeps imgui-1.92.8 API forms while taking
upstream's i18n labels, gui_loadFonts and gameImageButton;
http_client.mm keeps our NSURLSession async client and gains upstream's
headers overload on top of it (the content-type overload now lives in
http_client.cpp); our env-var TMU trace is dropped (never allowed by
the debug-toggle rule; the DOA2 question it served is closed); cheats
take upstream's generic WinCE dricas bypass; RFID reader moved to
maple_jvs per upstream; wsi headers take upstream with TARGET_TVOS
added wherever TARGET_IPHONE was tested.

Also found by the gates, not by conflicts:
- CDI images failed to load: cdipsr read 4 bytes into an 8-byte local
  `unsigned long temp_value` (our 6435a77 made it a local; upstream's
  new virtual read changed the stack contents so the top half was no
  longer zero). Now uint32_t = 0. Verified: four real iPad states load
  identically to the v2.5 control build.
- freetype (new submodule) has its own BUILD_FRAMEWORK option; ours is
  now hidden around its add_subdirectory (dev lane uses Ninja).
- imgui_cjk.cpp needs BuildLoadGlyphGetAdvanceOrFallback non-static;
  applied upstream's one-line patch to our imgui_draw.cpp.
- tests/test.sh now runs from the build dir so the golden save-state
  fixture resolves (it had been silently skipped).
- Our env-var TMU trace hooks removed everywhere (traced_* handlers).
- MAX_PAGE_SIZE is a literal on Apple arm64: ObjC++ TUs pull in
  <mach/vm_param.h> after stdclass.h, which redefines PAGE_SIZE as the
  runtime vm_page_size and broke the Sh4RCB static_assert.

App bridge: FlycastWrapper.mm and NetworkSerialBridge.mm syntax-compile
clean against this tree with -fmodules; no app change needed. The
symbols the app objects still reference from the old core are now
inline forwarders, a const rename, or gained a defaulted parameter, so
they resolve on the next app compile.

Gates: macOS libretro dylib and ios-simulator dev lane build clean,
tests/test.sh 37/37, four real pre-merge iPad states load identically
to the v2.5 control build.

Submodules: +freetype, +gamesdk, +tinygettext; -libusb-cmake; bumps to
DreamPicoPort-API, Vulkan-Headers, VulkanMemoryAllocator.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
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.

libretro vfs

3 participants