Implementation:Google deepmind Mujoco User VFS Header
| Knowledge Sources | |
|---|---|
| Domains | Physics Simulation, Virtual File System |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Declares the VFS (Virtual File System) class that manages resource providers and file operations for MuJoCo.
Description
user_vfs.h defines the mujoco::user::VFS class, which is the underlying implementation for the opaque mjVFS struct. The VFS owns and manages all mjResource instances created via mju_openResource, routing open/read/close operations to the appropriate mjpResourceProvider based on mounted paths. Providers can be mounted explicitly (via mj_mountVFS) or implicitly (via mjp_registerResourceProvider), with a default file-based provider as fallback. The class supports a self-destruct mode for legacy cases where VFS is an optional argument. It provides status codes for operations and is thread-safe through mutex protection.
Usage
Included by resource management code to declare the VFS interface, which is used whenever MuJoCo needs to open, read, or close external file resources.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: src/user/user_vfs.h
- Lines: 1-131
Key Functions
namespace mujoco::user {
class VFS {
public:
explicit VFS(mjVFS* vfs);
~VFS();
mjResource* Open(const char* dir, const char* name);
int Read(mjResource* resource, const void** buffer);
// Close, Mount, SetToSelfDestruct, Upcast, etc.
enum Status {
kSuccess = 0,
kFailedToLoad = -1,
kRepeatedName = 2,
// ...
};
};
} // namespace mujoco::user
Import
#include "user/user_vfs.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| vfs | mjVFS* | Yes | Opaque VFS struct to wrap |
| dir | const char* | No | Base directory for resource path resolution |
| name | const char* | Yes | Resource name to open |
Outputs
| Name | Type | Description |
|---|---|---|
| mjResource* | mjResource* | Opened resource handle, or nullptr on error |
| int | int | Bytes read from resource, or -1 on error |
| Status | enum | Operation result code |