Struct GenericFileSystem

Source
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

Source

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 instance
  • block_device - The block device that will provide storage for this filesystem
  • block_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);
Source

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 read
  • buffer - Buffer to store the read data
§Returns
  • Result<()> - Ok if the block was read successfully
Source

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 write
  • buffer - Buffer containing the data to write
§Returns
  • Result<()> - Ok if the block was written successfully

Trait Implementations§

Source§

impl FileSystem for GenericFileSystem

Source§

fn mount(&mut self, mount_point: &str) -> Result<()>

Mount operation
Source§

fn unmount(&mut self) -> Result<()>

Unmount operation
Source§

fn name(&self) -> &str

Get the name of the file system

Auto Trait Implementations§

§

impl !Freeze for GenericFileSystem

§

impl !RefUnwindSafe for GenericFileSystem

§

impl Send for GenericFileSystem

§

impl Sync for GenericFileSystem

§

impl Unpin for GenericFileSystem

§

impl !UnwindSafe for GenericFileSystem

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.