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", ¶ms)?;
Fields§
§drivers: RwLock<BTreeMap<String, Box<dyn FileSystemDriver>>>
Registered file system drivers indexed by name
Implementations§
Source§impl FileSystemDriverManager
impl FileSystemDriverManager
Sourcepub fn new() -> Self
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
Sourcepub fn register_driver(&mut self, driver: Box<dyn FileSystemDriver>)
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));
Sourcepub fn list_drivers(&self) -> Vec<String>
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
Sourcepub fn has_driver(&self, driver_name: &str) -> bool
pub fn has_driver(&self, driver_name: &str) -> bool
Sourcepub fn create_from_block(
&self,
driver_name: &str,
block_device: Box<dyn BlockDevice>,
block_size: usize,
) -> Result<Box<dyn VirtualFileSystem>>
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 useblock_device
- The block device that will store the filesystem datablock_size
- The block size for I/O operations (typically 512, 1024, or 4096 bytes)
§Returns
Ok(Box<dyn VirtualFileSystem>)
- Successfully created filesystem instanceErr(FileSystemError)
- If driver not found, doesn’t support block devices, or creation fails
§Errors
NotFound
- Driver with the specified name is not registeredNotSupported
- 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)?;
Sourcepub fn create_from_memory(
&self,
driver_name: &str,
memory_area: &MemoryArea,
) -> Result<Box<dyn VirtualFileSystem>>
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 usememory_area
- The memory region containing filesystem data or available for use
§Returns
Ok(Box<dyn VirtualFileSystem>)
- Successfully created filesystem instanceErr(FileSystemError)
- If driver not found, doesn’t support memory-based creation, or creation fails
§Errors
NotFound
- Driver with the specified name is not registeredNotSupported
- 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)?;
Sourcepub fn create_with_params(
&self,
driver_name: &str,
params: &dyn FileSystemParams,
) -> Result<Box<dyn VirtualFileSystem>>
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 useparams
- Parameter structure implementing FileSystemParams trait
§Returns
Ok(Box<dyn VirtualFileSystem>)
- Successfully created filesystem instanceErr(FileSystemError)
- If driver not found, parameters invalid, or creation fails
§Errors
NotFound
- Driver with the specified name is not registeredNotSupported
- 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", ¶ms)?;
§Note
This method uses dynamic dispatch for parameter handling to support future dynamic filesystem module loading while maintaining type safety.
Sourcepub fn get_driver_type(&self, driver_name: &str) -> Option<FileSystemType>
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 existsNone
- 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"),
}
}