Refactor mjVFS and resource management.

Resource operations (e.g. mju_openResource, mju_readResource, and
mju_closeResource, etc.) are now all handled by a VFS instance. It
is now up to the VFS to determine which provider to use in order to
handle those operations.

This allows us to dynamically add/remove (aka "mount") providers to
a VFS to handle special requests. mj_addFileVFS and mj_addBufferVFS
have been reimplemented as two such use-cases. Moreover, we expose
the mounting behaviour with two new functions: mj_mountVFS and
mj_unmountVFS.

PiperOrigin-RevId: 856166919
Change-Id: Id723d612ffc0bff020705cf19ef95fbf24676840
This commit is contained in:
Haroon Qureshi
2026-01-14 05:18:49 -08:00
committed by Copybara-Service
parent e50e2e9691
commit d387578783
12 changed files with 844 additions and 433 deletions
+19
View File
@@ -1357,6 +1357,25 @@ The VFS must first be allocated using :ref:`mj_defaultVFS` and must be freed wit
Initialize an empty VFS, :ref:`mj_deleteVFS` must be called to deallocate the VFS.
.. _mj_mountVFS:
`mj_mountVFS <#mj_mountVFS>`__
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. mujoco-include:: mj_mountVFS
Mount a ResourceProvider to handle file operations under the given path; return 0: success,
2: repeated name, -1: invalid resource provider.
.. _mj_unmountVFS:
`mj_unmountVFS <#mj_unmountVFS>`__
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. mujoco-include:: mj_unmountVFS
Unmount a previously mounted ResourceProvider; return 0: success, -1: not found in VFS.
.. _mj_addFileVFS:
`mj_addFileVFS <#mj_addFileVFS>`__