Skip to main content
The file_system class provides a virtual file system layer that translates Windows paths to host filesystem paths, enabling safe and controlled file access in the emulator.

Overview

This class provides:
  • Windows-to-host path translation
  • Drive letter emulation
  • Path sandboxing to prevent escape attacks
  • Custom path mappings
  • Cross-platform support (Windows and Unix hosts)

Constructor

const std::filesystem::path&
Root directory for the virtual file system. All Windows paths will be resolved relative to this directory.
On Windows hosts, if root is empty, the file system operates in passthrough mode, allowing direct access to the real Windows file system.

Methods

list_drives

Lists available drive letters.
Returns: Set of lowercase drive letters (e.g., ). Behavior:
  • On Windows with empty root: Returns actual system drives via GetLogicalDrives()
  • Otherwise: Returns subdirectories in the root that are single characters

translate

Translates a Windows path to a host filesystem path.
const windows_path&
Windows path to translate (must be absolute)
Returns: Corresponding host filesystem path. Throws: std::runtime_error if the path is not absolute. Translation process:
  1. Check custom mappings first
  2. On Windows with empty root: Return path as-is
  3. Otherwise: Map to <root>/<drive>/<path>
  4. Prevent directory traversal attacks by checking for escape sequences

map

Creates a custom path mapping.
windows_path
Source Windows path
std::filesystem::path
Destination host path
Mappings take precedence over default translation rules. This is useful for:
  • Redirecting system directories
  • Mapping specific files to host locations
  • Creating virtual files or directories

access_mapped_entries

Iterates over mapped entries within a directory.
const windows_path&
Directory path to search
const F&
Callback function invoked for each mapped child entry
The accessor receives a std::pair<const windows_path&, const std::filesystem::path&> for each mapping.

Static Methods

is_escaping_relative_path

Checks if a relative path attempts to escape its parent directory.
const std::filesystem::path&
Path to check
Returns: true if the path is empty or starts with ”..“.

is_subpath

Checks if a path is a subpath of a root directory.
const std::filesystem::path&
Normalized root path
const std::filesystem::path&
Normalized target path to check
Returns: true if normal_target is within normal_root. This method is used internally to prevent directory traversal attacks.

Usage Examples

Basic Usage

Custom Mappings

Windows Host Passthrough

Directory Enumeration with Mappings

Security: Preventing Path Traversal

Directory Structure Example

For a file system rooted at /tmp/windows, the directory structure would be:
Drive letters correspond to single-character subdirectories.

Integration Example

See Also