pub trait FileSystemDriver: Send + Sync {
// Required methods
fn name(&self) -> &'static str;
fn filesystem_type(&self) -> FileSystemType;
// Provided methods
fn create_from_block(
&self,
_block_device: Box<dyn BlockDevice>,
_block_size: usize,
) -> Result<Arc<dyn FileSystemOperations>, FileSystemError> { ... }
fn create_from_memory(
&self,
_memory_area: &MemoryArea,
) -> Result<Arc<dyn FileSystemOperations>, FileSystemError> { ... }
fn create(&self) -> Result<Arc<dyn FileSystemOperations>, FileSystemError> { ... }
fn create_from_option_string(
&self,
options: &str,
) -> Result<Arc<dyn FileSystemOperations>, FileSystemError> { ... }
fn create_from_params(
&self,
params: &dyn FileSystemParams,
) -> Result<Arc<dyn FileSystemOperations>, FileSystemError> { ... }
}
Expand description
Trait for file system drivers
This trait is used to create file systems from block devices or memory areas. It is not intended to be used directly by the VFS manager. Instead, the VFS manager will use the appropriate creation method based on the source.
Required Methods§
Sourcefn filesystem_type(&self) -> FileSystemType
fn filesystem_type(&self) -> FileSystemType
Get the type of the file system
Provided Methods§
Sourcefn create_from_block(
&self,
_block_device: Box<dyn BlockDevice>,
_block_size: usize,
) -> Result<Arc<dyn FileSystemOperations>, FileSystemError>
fn create_from_block( &self, _block_device: Box<dyn BlockDevice>, _block_size: usize, ) -> Result<Arc<dyn FileSystemOperations>, FileSystemError>
Create a file system from a block device
When implementing this method, ensure that the file system driver can handle block device-based creation. If the driver does not support this, return an appropriate error.
§Arguments
_block_device
- The block device to use for creating the file system_block_size
- The block size of the device
Sourcefn create_from_memory(
&self,
_memory_area: &MemoryArea,
) -> Result<Arc<dyn FileSystemOperations>, FileSystemError>
fn create_from_memory( &self, _memory_area: &MemoryArea, ) -> Result<Arc<dyn FileSystemOperations>, FileSystemError>
Create a file system from a memory area
When implementing this method, ensure that the file system driver can handle memory-based creation. If the driver does not support this, return an appropriate error.
§Notes
File system drivers must validate the provided MemoryArea to ensure it is valid. If the MemoryArea is invalid, the driver should return an appropriate error.
§Arguments
_memory_area
- The memory area to use for creating the file system
§Returns
Result<Arc<dyn FileSystemOperations>, FileSystemError>
- The created file system
fn create(&self) -> Result<Arc<dyn FileSystemOperations>, FileSystemError>
Sourcefn create_from_option_string(
&self,
options: &str,
) -> Result<Arc<dyn FileSystemOperations>, FileSystemError>
fn create_from_option_string( &self, options: &str, ) -> Result<Arc<dyn FileSystemOperations>, FileSystemError>
Create a file system with option string
This method creates a filesystem instance based on an option string, which is typically passed from the mount() system call. The option string format is filesystem-specific and should be parsed by the individual driver.
§Arguments
options
- Option string containing filesystem-specific parameters
§Returns
Result<Arc<dyn FileSystemOperations>, FileSystemError>
- The created file system
§Note
This method allows the filesystem driver to handle its own option parsing, keeping the mount syscall generic and delegating filesystem-specific logic to the appropriate driver.
Sourcefn create_from_params(
&self,
params: &dyn FileSystemParams,
) -> Result<Arc<dyn FileSystemOperations>, FileSystemError>
fn create_from_params( &self, params: &dyn FileSystemParams, ) -> Result<Arc<dyn FileSystemOperations>, FileSystemError>
Create a file system with structured parameters
This method creates file systems using type-safe structured parameters that implement the FileSystemParams trait. This approach replaces the old BTreeMap<String, String> approach with better type safety.
§Arguments
params
- Structured parameter implementing FileSystemParams
§Returns
Result<Arc<dyn FileSystemOperations>, FileSystemError>
- The created file system
§Note
This method uses dynamic dispatch for parameter handling to support future dynamic filesystem module loading while maintaining type safety.