pub struct GenericFileSystem {
name: &'static str,
block_device: Mutex<Box<dyn BlockDevice>>,
block_size: usize,
mounted: bool,
mount_point: String,
}
Expand description
Template for a basic block device-based file system implementation
GenericFileSystem
provides a foundation for implementing filesystems
that operate on block devices. It handles common filesystem operations
including mounting, block I/O, and basic filesystem state management.
This is primarily used as a base for filesystem drivers and testing, not intended for direct use in production filesystems.
§Architecture
- Block Device Integration: Direct interface with block devices for storage
- Mount State Management: Tracks filesystem mount status and mount points
- Thread-Safe Block I/O: Mutex-protected access to the underlying block device
- Extensible Design: Can be extended by specific filesystem implementations
§Usage
// Create a generic filesystem on a block device
let block_device = Box::new(SomeBlockDevice::new());
let fs = GenericFileSystem::new("myfs", block_device, 512);
// Register with VFS
let fs_id = vfs_manager.register_fs(Box::new(fs));
vfs_manager.mount(fs_id, "/mnt")?;
Fields§
§name: &'static str
Name of the filesystem instance
block_device: Mutex<Box<dyn BlockDevice>>
Block device for storage operations (mutex-protected for thread safety)
block_size: usize
Block size for I/O operations
mounted: bool
Mount status of the filesystem
mount_point: String
Current mount point path
Implementations§
Source§impl GenericFileSystem
impl GenericFileSystem
Sourcepub fn new(
name: &'static str,
block_device: Box<dyn BlockDevice>,
block_size: usize,
) -> Self
pub fn new( name: &'static str, block_device: Box<dyn BlockDevice>, block_size: usize, ) -> Self
Create a new generic filesystem instance
This method initializes a new filesystem instance that operates on a block device. The filesystem starts in an unmounted state and can be mounted later through the VFS layer.
§Arguments
name
- A static string identifier for this filesystem instanceblock_device
- The block device that will provide storage for this filesystemblock_size
- The block size to use for I/O operations (typically 512, 1024, 4096)
§Returns
Self
- A new GenericFileSystem instance ready for registration
§Examples
let device = Box::new(SomeBlockDevice::new());
let fs = GenericFileSystem::new("myfs", device, 512);
Sourcefn read_block_internal(&self, block_idx: usize, buffer: &mut [u8]) -> Result<()>
fn read_block_internal(&self, block_idx: usize, buffer: &mut [u8]) -> Result<()>
Internal method for reading blocks from the underlying block device
This method provides a low-level interface for reading data blocks from the filesystem’s block device. It handles device locking and error conversion for filesystem operations.
§Arguments
block_idx
- The index of the block to readbuffer
- Buffer to store the read data
§Returns
Result<()>
- Ok if the block was read successfully
Sourcefn write_block_internal(&self, block_idx: usize, buffer: &[u8]) -> Result<()>
fn write_block_internal(&self, block_idx: usize, buffer: &[u8]) -> Result<()>
Internal method for writing blocks to the underlying block device
This method provides a low-level interface for writing data blocks to the filesystem’s block device. It handles device locking and error conversion for filesystem operations.
§Arguments
block_idx
- The index of the block to writebuffer
- Buffer containing the data to write
§Returns
Result<()>
- Ok if the block was written successfully