Module fs

Source
Expand description

Virtual File System (VFS) module.

This module provides a flexible Virtual File System implementation that supports per-task isolated filesystems, containerization, and bind mount functionality.

§Architecture Overview

The VFS architecture has evolved to support containerization, process isolation, and advanced mount operations including bind mounts:

§VfsManager Distribution

  • Per-Task VfsManager: Each task can have its own isolated VfsManager instance stored as Option<Arc<VfsManager>> in the task structure
  • Shared Filesystems: Multiple VfsManager instances can share underlying filesystem objects while maintaining independent mount points
  • Bind Mounts: Support for mounting directories from one location to another, including cross-VFS bind mounting for container orchestration

§Key Components

  • VfsManager: Main VFS management structure supporting both isolation and sharing
  • FileSystemDriverManager: Global singleton for filesystem driver registration
  • VirtualFileSystem: Trait combining filesystem and file operation interfaces
  • MountPoint: Associates filesystem instances with mount paths
  • MountTree: Hierarchical mount tree structure supporting bind mounts

§Bind Mount Functionality

The VFS provides comprehensive bind mount support for flexible directory mapping:

§Basic Bind Mounts

let mut vfs = VfsManager::new();
// Mount a directory at another location
vfs.bind_mount("/source/dir", "/target/dir", false)?;

§Read-Only Bind Mounts

// Create read-only bind mount for security
vfs.bind_mount("/source/dir", "/readonly/dir", true)?;

§Cross-VFS Bind Mounts

// Share directories between isolated VFS instances
let host_vfs = Arc::new(vfs_manager);
container_vfs.bind_mount_from(&host_vfs, "/host/data", "/container/data", false)?;

§Thread-Safe Access

Bind mount operations are thread-safe and can be called from system call context:

// Use shared reference method for system calls
vfs_arc.bind_mount_shared_ref("/source", "/target", false)?;

§Usage Patterns

§Container Isolation with Bind Mounts

// Create isolated VfsManager for container
let mut container_vfs = VfsManager::new();
container_vfs.mount(fs_id, "/");
 
// Bind mount host resources into container
let host_vfs = Arc::new(host_vfs_manager);
container_vfs.bind_mount_from(&host_vfs, "/host/shared", "/shared", true)?;
 
// Assign to task
task.vfs = Some(Arc::new(container_vfs));

§Shared Filesystem Access

The VFS supports two distinct patterns for sharing filesystem resources:

§VFS Sharing via Arc
// Share entire VfsManager instance including mount points
let shared_vfs = Arc::new(original_vfs);
let task_vfs = Arc::clone(&shared_vfs);
 
// All mount operations affect the shared mount tree
shared_vfs.mount(tmpfs_id, "/tmp")?;  // Visible to all references
 
// Useful for:
// - Fork-like behavior where child inherits parent's full filesystem view
// - Thread-like sharing where all threads see the same mount points
// - System-wide mount operations

The design enables flexible deployment scenarios from simple shared filesystems to complete filesystem isolation with selective resource sharing for containerized applications through bind mounts.

Modules§

drivers
helper
mount_tree
Mount Tree Implementation
params
Filesystem Parameter System
syscall
tmpfs
TmpFS - Temporary File System (RAM-only)

Structs§

DeviceFileInfo
Information about device files in the filesystem
Directory
Structure representing a directory
DirectoryEntry
Structure representing a directory entry
File
FileMetadata
FilePermission
FileSystemDriverManager
Global filesystem driver manager singleton
FileSystemError
GenericFileSystem
Template for a basic block device-based file system implementation
VfsManager
VFS manager for per-task or shared filesystem management.

Enums§

FileSystemErrorKind
FileSystemType
Enum defining the type of file system
FileType
ManagerRef
SeekFrom

Constants§

MAX_PATH_LENGTH

Statics§

FS_DRIVER_MANAGER 🔒

Traits§

FileHandle
Trait for file handlers
FileOperations
Trait defining file operations
FileSystem
Trait defining basic file system operations
FileSystemDriver
Trait for file system drivers
VirtualFileSystem
Trait combining the complete VFS interface

Functions§

get_fs_driver_manager
Global filesystem driver manager singleton

Type Aliases§

FileSystemRef
Result
Result type for file system operations