VfsManager

Struct VfsManager 

Source
pub struct VfsManager {
    pub id: VfsManagerId,
    pub mount_tree: MountTree,
    pub cwd: RwLock<Option<(Arc<VfsEntry>, Arc<MountPoint>)>>,
    pub mounted_filesystems: RwLock<Vec<Arc<dyn FileSystemOperations>>>,
}
Expand description

VFS Manager v2 - Enhanced VFS architecture implementation

This manager provides advanced VFS functionality with proper mount tree management, enhanced caching, and better support for containerization.

Fields§

§id: VfsManagerId

Unique identifier for this VfsManager instance

§mount_tree: MountTree

Mount tree for hierarchical mount point management

§cwd: RwLock<Option<(Arc<VfsEntry>, Arc<MountPoint>)>>

Current working directory: (VfsEntry, MountPoint) pair

§mounted_filesystems: RwLock<Vec<Arc<dyn FileSystemOperations>>>

Strong references to all currently mounted filesystems

Implementations§

Source§

impl VfsManager

Source

pub fn new() -> Self

Create a new VFS manager instance with a dummy root

Source

pub fn new_with_root(root_fs: Arc<dyn FileSystemOperations>) -> Self

Create a new VFS manager instance with a specified root filesystem

Source

pub fn mount( &self, filesystem: Arc<dyn FileSystemOperations>, mount_point_str: &str, flags: u32, ) -> Result<(), FileSystemError>

Mount a filesystem at the specified path

This will mount the given filesystem at the specified mount point. If the mount point is “/”, it will replace the root filesystem.

§Arguments
  • filesystem - The filesystem to mount.
  • mount_point_str - The path where the filesystem should be mounted.
  • flags - Flags for the mount operation (e.g., read-only).
§Errors

Returns an error if the mount point is invalid, the filesystem cannot be mounted, or if the mount operation fails.

Source

pub fn unmount(&self, mount_point_str: &str) -> Result<(), FileSystemError>

Unmount a mount point at the specified path

This will remove the mount point from the mount tree and clean up any associated resources.

§Arguments
  • mount_point_str - The path of the mount point to unmount.
§Errors

Returns an error if the mount point is not valid or if the unmount operation fails.

Source

pub fn bind_mount( &self, source_path: &str, target_path: &str, ) -> Result<(), FileSystemError>

Bind mount a directory from source_path to target_path

This will create a bind mount where the source directory is mounted at the target path.

§Arguments
  • source_path - The path of the source directory to bind mount.
  • target_path - The path where the source directory should be mounted.
§Errors

Returns an error if the source is not a directory, the target is already a mount point, or if the source is not a valid directory.

Source

pub fn bind_mount_from( &self, source_vfs: &Arc<VfsManager>, source_path: &str, target_path: &str, ) -> Result<(), FileSystemError>

Bind mount a directory from another VFS instance

This will create a bind mount where the source directory from another VFS is mounted at the target path in this VFS.

§Arguments
  • source_vfs - The source VFS instance containing the directory to bind
  • source_path - The path of the source directory in the source VFS.
  • target_path - The path where the source directory should be mounted in this VFS.
§Errors

Returns an error if the source path does not exist, the target is already a mount point, or if the source is not a valid directory.

Source

pub(crate) fn bind_mount_from_entry( &self, source_entry: Arc<VfsEntry>, source_mount_point: Arc<MountPoint>, target_path: &str, ) -> Result<(), FileSystemError>

Source

pub fn clone_mount_namespace_deep( source: &Arc<VfsManager>, ) -> Result<Arc<VfsManager>, FileSystemError>

Create a new VFS manager that starts with the same mount tree as source, but does not share mount tree structures (deep copy of mount topology).

Notes:

  • Underlying filesystem objects may still be shared (same backing FS), but mount/unmount/bind mount operations will be isolated between namespaces.
  • This intentionally reconstructs mounts by replaying mount/bind-mount operations.
Source

fn bind_mount_entry( &self, source_entry: Arc<VfsEntry>, source_mount_point: Arc<MountPoint>, target_entry: Arc<VfsEntry>, target_mount_point: Arc<MountPoint>, ) -> Result<(), FileSystemError>

Create a bind mount from source_entry to target_entry

Source

pub fn open( &self, path: &str, flags: u32, ) -> Result<KernelObject, FileSystemError>

Open a file at the specified path

This will resolve the path using the MountTreeV2 and open the file using the filesystem associated with the resolved VfsEntry.

§Arguments
  • path - The path of the file to open.
  • flags - Flags for opening the file (e.g., read, write
  • O_CREAT, etc.).
§Errors

Returns an error if the path does not exist, is not a file, or if the filesystem cannot be resolved.

Source

pub fn create_file( &self, path: &str, file_type: FileType, ) -> Result<(), FileSystemError>

Create a file at the specified path

This will create a new file in the filesystem at the given path.

§Arguments
  • path - The path where the file should be created.
  • file_type - The type of file to create (e.g., regular file, directory, etc.).
§Errors

Returns an error if the parent directory does not exist, the filesystem cannot be resolved, or if the file cannot be created.

Source

pub fn create_dir(&self, path: &str) -> Result<(), FileSystemError>

Create a directory at the specified path

This will create a new directory in the filesystem at the given path.

§Arguments
  • path - The path where the directory should be created.
§Errors

Returns an error if the parent directory does not exist, the filesystem cannot be resolved, or if the directory cannot be created.

Create a symbolic link at the specified path

This will create a new symbolic link in the filesystem at the given path, pointing to the specified target path.

§Arguments
  • path - The path where the symbolic link should be created.
  • target_path - The path that the symbolic link should point to.
§Errors

Returns an error if the parent directory does not exist, the filesystem cannot be resolved, or if the symbolic link cannot be created.

Source

pub fn remove(&self, path: &str) -> Result<(), FileSystemError>

Remove a file at the specified path

This will remove the file from the filesystem and update the mount tree.

§Arguments
  • path - The path of the file to remove.
§Errors

Returns an error if the path does not exist, is not a file, or if the filesystem cannot be resolved.

Source

pub fn metadata(&self, path: &str) -> Result<FileMetadata, FileSystemError>

Get metadata for a file at the specified path

This will resolve the path using the MountTreeV2 and return the metadata for the file represented by the resolved VfsEntry.

§Arguments
  • path - The path of the file to get metadata for.
§Errors

Returns an error if the path does not exist, is not a file, or if the filesystem cannot be resolved.

Source

pub fn readdir( &self, path: &str, ) -> Result<Vec<DirectoryEntryInternal>, FileSystemError>

Read directory entries at the specified path

This will resolve the path using the MountTreeV2 and return a list of directory entries for the directory represented by the resolved VfsEntry.

§Arguments
  • path - The path of the directory to read.
§Errors

Returns an error if the path does not exist, is not a directory, or if the filesystem cannot be resolved.

Source

pub fn set_cwd_by_path(&self, path: &str) -> Result<(), FileSystemError>

Set current working directory by path

This will change the current working directory to the specified path.

§Arguments
  • path - The path to set as the current working directory.
§Errors

Returns an error if the path does not exist, is not a directory, or if the filesystem cannot be resolved.

Source

pub fn set_cwd(&self, entry: Arc<VfsEntry>, mount_point: Arc<MountPoint>)

Set current working directory

This sets the current working directory to the specified VfsEntry and MountPoint. The entry must be a directory.

§Arguments
  • entry - The VfsEntry representing the directory
  • mount_point - The MountPoint where the directory is mounted
Source

pub fn get_cwd(&self) -> Option<(Arc<VfsEntry>, Arc<MountPoint>)>

Get current working directory

This returns the current working directory as an Arc<VfsEntry>.

If the current working directory is not set, it returns None.

§Returns

An Option<Arc<VfsEntry>> containing the current working directory entry, or None if the current working directory is not set.

Source

pub fn get_cwd_path(&self) -> String

Get current working directory as path string

This returns the current working directory as a path string. If the current working directory is not set, it returns “/”.

§Returns

A String containing the current working directory path.

Source

pub fn build_absolute_path( &self, entry: &Arc<VfsEntry>, mount_point: &Arc<MountPoint>, ) -> String

Build absolute path from VfsEntry and MountPoint

This safely constructs the absolute path for a given VfsEntry by using MountPoint information, avoiding potential issues with Weak references.

§Arguments
  • entry - The VfsEntry to build the path for
  • mount_point - The MountPoint containing this entry
§Returns

A String containing the absolute path

Source

pub fn create_device_file( &self, path: &str, device_info: DeviceFileInfo, ) -> Result<(), FileSystemError>

Create a device file

This will create a new device file in the filesystem at the given path.

§Arguments
  • path - The path where the device file should be created.
  • device_info - Information about the device file to create (e.g., device type, major/minor numbers, etc.).
§Errors

Returns an error if the parent directory does not exist, the filesystem cannot be resolved, or if the device file cannot be created.

Source

pub fn resolve_path( &self, path: &str, ) -> Result<(Arc<VfsEntry>, Arc<MountPoint>), FileSystemError>

Resolve a path to both VfsEntry and MountPoint

Automatically handles both absolute paths (starting with ‘/’) and relative paths (resolved from current working directory). This is the main path resolution API.

Returns both VfsEntry and MountPoint for consistency with other resolution APIs.

Source

pub fn resolve_path_with_options( &self, path: &str, options: &PathResolutionOptions, ) -> Result<(Arc<VfsEntry>, Arc<MountPoint>), FileSystemError>

Resolve a path with specified options

Source

pub fn resolve_path_from( &self, base_entry: &Arc<VfsEntry>, base_mount: &Arc<MountPoint>, path: &str, ) -> Result<(Arc<VfsEntry>, Arc<MountPoint>), FileSystemError>

Resolve a path from a specific base directory (for *at system calls)

This method resolves a path starting from the specified base directory. It’s specifically designed for *at system calls (openat, fstatat, etc.).

Returns both VfsEntry and MountPoint for efficient use.

Source

pub fn resolve_path_from_with_options( &self, base_entry: &Arc<VfsEntry>, base_mount: &Arc<MountPoint>, path: &str, options: &PathResolutionOptions, ) -> Result<(Arc<VfsEntry>, Arc<MountPoint>), FileSystemError>

Resolve a path from an optional base directory with options

Source

pub fn resolve_mount_point( &self, path: &str, ) -> VfsResult<(VfsEntryRef, Arc<MountPoint>)>

Resolve a path to mount point (returns VfsEntryRef instead of Arc)

This is useful for operations that need to work with mount point information but don’t necessarily need strong references to entries.

§Arguments
  • path - The path to resolve
§Returns

Returns a tuple of (VfsEntryRef, Arc) on success

Source

pub fn resolve_mount_point_with_options( &self, path: &str, options: &PathResolutionOptions, ) -> VfsResult<(VfsEntryRef, Arc<MountPoint>)>

Resolve a path to mount point with specified options

Source

pub fn resolve_mount_point_from( &self, base_entry: &Arc<VfsEntry>, base_mount: &Arc<MountPoint>, path: &str, options: &PathResolutionOptions, ) -> VfsResult<(VfsEntryRef, Arc<MountPoint>)>

Source

pub fn resolve_mount_point_from_with_options( &self, base_entry: &Arc<VfsEntry>, base_mount: &Arc<MountPoint>, path: &str, options: &PathResolutionOptions, ) -> VfsResult<(VfsEntryRef, Arc<MountPoint>)>

Create a hard link

This will create a hard link where the source file is linked to the target path. Both paths will refer to the same underlying file data.

§Arguments
  • source_path - Path of the existing file to link to
  • target_path - Path where the hard link should be created
§Errors

Returns an error if the source doesn’t exist, target already exists, filesystems don’t match, or hard links aren’t supported.

Source

fn split_parent_child( &self, path: &str, ) -> Result<(String, String), FileSystemError>

Split a path into parent directory and filename

Source

pub fn open_from( &self, base_entry: &Arc<VfsEntry>, base_mount: &Arc<MountPoint>, path: &str, flags: u32, ) -> Result<KernelObject, FileSystemError>

Open a file relative to a given base entry and mount (for *at syscalls)

§Arguments
  • base_entry - Base VfsEntry to resolve relative path from
  • base_mount - Base MountPoint for the base entry
  • path - Relative or absolute path
  • flags - Open flags
§Returns

KernelObject::File(VfsFileObject) Open a file with optional base directory (unified openat implementation)

If base_entry and base_mount are None, behaves like regular open(). If base is provided, resolves relative paths from that base (for *at syscalls).

Source

pub fn resolve_path_to_absolute(&self, path: &str) -> String

Resolve a relative path to an absolute path using the current working directory

If the path is already absolute, returns it as-is. If the path is relative, combines it with the current working directory.

§Arguments
  • path - The path to resolve (relative or absolute)
§Returns

An absolute path string

Auto Trait Implementations§

§

impl !Freeze for VfsManager

§

impl !RefUnwindSafe for VfsManager

§

impl Send for VfsManager

§

impl Sync for VfsManager

§

impl Unpin for VfsManager

§

impl !UnwindSafe for VfsManager

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.