Struct FileSystemDriverManager

Source
pub struct FileSystemDriverManager {
    drivers: RwLock<BTreeMap<String, Box<dyn FileSystemDriver>>>,
}
Expand description

Global filesystem driver manager singleton

Provides global access to the FileSystemDriverManager instance. This function ensures thread-safe initialization of the singleton and returns a mutable reference for driver registration and filesystem creation.

§Returns

Mutable reference to the global FileSystemDriverManager instance

§Thread Safety

This function is marked as unsafe due to static mutable access, but Filesystem driver manager for centralized driver registration and management

The FileSystemDriverManager provides a centralized system for managing filesystem drivers in the kernel. It separates driver management responsibilities from individual VfsManager instances, enabling shared driver access across multiple VFS namespaces.

§Features

  • Driver Registration: Register filesystem drivers for system-wide use
  • Type-Safe Creation: Create filesystems with structured parameter validation
  • Multi-Source Support: Support for block device, memory, and virtual filesystems
  • Thread Safety: All operations are thread-safe using RwLock protection
  • Future Extensibility: Designed for dynamic filesystem module loading

§Architecture

The manager maintains a registry of drivers identified by name, with each driver implementing the FileSystemDriver trait. Drivers specify their supported source types (block, memory, virtual) and provide creation methods for each type.

§Usage

// Register a filesystem driver
let manager = get_fs_driver_manager();
manager.register_driver(Box::new(MyFSDriver));
 
// Create filesystem from block device
let device = get_block_device();
let fs = manager.create_from_block("myfs", device, 512)?;
 
// Create filesystem with structured parameters
let params = MyFSParams::new();
let fs = manager.create_with_params("myfs", &params)?;

Fields§

§drivers: RwLock<BTreeMap<String, Box<dyn FileSystemDriver>>>

Registered file system drivers indexed by name

Implementations§

Source§

impl FileSystemDriverManager

Source

pub fn new() -> Self

Create a new filesystem driver manager

Initializes an empty driver manager with no registered drivers. Drivers must be registered using register_driver() before they can be used to create filesystems.

§Returns

A new FileSystemDriverManager instance

Source

pub fn register_driver(&mut self, driver: Box<dyn FileSystemDriver>)

Register a filesystem driver

Adds a new filesystem driver to the manager’s registry. The driver will be indexed by its name() method return value. If a driver with the same name already exists, it will be replaced.

§Arguments
  • driver - The filesystem driver to register, implementing FileSystemDriver trait
§Example
let manager = get_fs_driver_manager();
manager.register_driver(Box::new(MyFileSystemDriver));
Source

pub fn list_drivers(&self) -> Vec<String>

Get a list of registered driver names

Returns the names of all currently registered filesystem drivers. This is useful for debugging and system introspection.

§Returns

Vector of driver names in alphabetical order

Source

pub fn has_driver(&self, driver_name: &str) -> bool

Check if a driver with the specified name is registered

Performs a quick lookup to determine if a named driver exists in the registry without attempting to use it.

§Arguments
  • driver_name - The name of the driver to check for
§Returns

true if the driver is registered, false otherwise

Source

pub fn create_from_block( &self, driver_name: &str, block_device: Box<dyn BlockDevice>, block_size: usize, ) -> Result<Box<dyn VirtualFileSystem>>

Create a filesystem from a block device

Creates a new filesystem instance using the specified driver and block device. The driver must support block device-based filesystem creation. This method validates that the driver supports block devices before attempting creation.

§Arguments
  • driver_name - The name of the registered driver to use
  • block_device - The block device that will store the filesystem data
  • block_size - The block size for I/O operations (typically 512, 1024, or 4096 bytes)
§Returns
  • Ok(Box<dyn VirtualFileSystem>) - Successfully created filesystem instance
  • Err(FileSystemError) - If driver not found, doesn’t support block devices, or creation fails
§Errors
  • NotFound - Driver with the specified name is not registered
  • NotSupported - Driver doesn’t support block device-based filesystems
  • Driver-specific errors during filesystem creation
§Example
let device = get_block_device();
let fs = manager.create_from_block("ext4", device, 4096)?;
Source

pub fn create_from_memory( &self, driver_name: &str, memory_area: &MemoryArea, ) -> Result<Box<dyn VirtualFileSystem>>

Create a filesystem from a memory area

Creates a new filesystem instance using the specified driver and memory region. This is typically used for RAM-based filesystems like tmpfs or for mounting filesystem images stored in memory (e.g., initramfs).

§Arguments
  • driver_name - The name of the registered driver to use
  • memory_area - The memory region containing filesystem data or available for use
§Returns
  • Ok(Box<dyn VirtualFileSystem>) - Successfully created filesystem instance
  • Err(FileSystemError) - If driver not found, doesn’t support memory-based creation, or creation fails
§Errors
  • NotFound - Driver with the specified name is not registered
  • NotSupported - Driver only supports block device-based filesystems
  • Driver-specific errors during filesystem creation
§Example
let memory_area = MemoryArea::new(addr, size);
let fs = manager.create_from_memory("cpiofs", &memory_area)?;
Source

pub fn create_with_params( &self, driver_name: &str, params: &dyn FileSystemParams, ) -> Result<Box<dyn VirtualFileSystem>>

Create a filesystem with structured parameters

This method creates filesystems using type-safe structured parameters that implement the FileSystemParams trait. This approach replaces the old BTreeMap<String, String> configuration method with better type safety and validation.

The method uses dynamic dispatch to handle different parameter types, enabling future dynamic filesystem module loading while maintaining type safety at the driver level.

§Arguments
  • driver_name - The name of the registered driver to use
  • params - Parameter structure implementing FileSystemParams trait
§Returns
  • Ok(Box<dyn VirtualFileSystem>) - Successfully created filesystem instance
  • Err(FileSystemError) - If driver not found, parameters invalid, or creation fails
§Errors
  • NotFound - Driver with the specified name is not registered
  • NotSupported - Driver doesn’t support the provided parameter type
  • Driver-specific parameter validation errors
§Example
use crate::fs::params::TmpFSParams;
 
let params = TmpFSParams::new(1048576, 0); // 1MB limit
let fs = manager.create_with_params("tmpfs", &params)?;
§Note

This method uses dynamic dispatch for parameter handling to support future dynamic filesystem module loading while maintaining type safety.

Source

pub fn get_driver_type(&self, driver_name: &str) -> Option<FileSystemType>

Get filesystem driver information by name

Retrieves the filesystem type supported by a registered driver. This is useful for validating driver capabilities before attempting to create filesystems.

§Arguments
  • driver_name - The name of the driver to query
§Returns
  • Some(FileSystemType) - The filesystem type if driver exists
  • None - If no driver with the specified name is registered
§Example
if let Some(fs_type) = manager.get_driver_type("tmpfs") {
    match fs_type {
        FileSystemType::Virtual => println!("TmpFS is a virtual filesystem"),
        _ => println!("Unexpected filesystem type"),
    }
}

Trait Implementations§

Source§

impl Default for FileSystemDriverManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !Freeze for FileSystemDriverManager

§

impl !RefUnwindSafe for FileSystemDriverManager

§

impl Send for FileSystemDriverManager

§

impl Sync for FileSystemDriverManager

§

impl Unpin for FileSystemDriverManager

§

impl !UnwindSafe for FileSystemDriverManager

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.