Ext2FileSystem

Struct Ext2FileSystem 

Source
pub struct Ext2FileSystem {
    fs_id: FileSystemId,
    block_device: Arc<dyn BlockDevice>,
    superblock: Box<Ext2Superblock>,
    block_size: u32,
    root_inode: u32,
    root: RwLock<Arc<Ext2Node>>,
    name: String,
    next_file_id: Mutex<u64>,
    inode_cache: Mutex<InodeLruCache>,
    block_cache: Mutex<BlockLruCache>,
}
Expand description

ext2 Filesystem implementation

This struct implements an ext2 filesystem that can be mounted on block devices. It maintains the block device reference and provides filesystem operations through the VFS v2 interface.

Fields§

§fs_id: FileSystemId

Unique filesystem identifier

§block_device: Arc<dyn BlockDevice>

Reference to the underlying block device

§superblock: Box<Ext2Superblock>

Superblock information (heap allocated to avoid stack overflow)

§block_size: u32

Block size in bytes

§root_inode: u32

Root directory inode

§root: RwLock<Arc<Ext2Node>>

Root directory node

§name: String

Filesystem name

§next_file_id: Mutex<u64>

Next file ID generator

§inode_cache: Mutex<InodeLruCache>

LRU cached inodes

§block_cache: Mutex<BlockLruCache>

LRU cached blocks

Implementations§

Source§

impl Ext2FileSystem

Source

pub fn new( block_device: Arc<dyn BlockDevice>, ) -> Result<Arc<Self>, FileSystemError>

Create a new ext2 filesystem from a block device

Source

pub fn new_from_device_id( device_id: usize, ) -> Result<Arc<Self>, FileSystemError>

Create a new ext2 filesystem from a device ID using the new Device trait methods

Source

pub fn new_from_params( params: &Ext2Params, ) -> Result<Arc<Self>, FileSystemError>

Create a new ext2 filesystem from parameters

Source

pub fn read_inode(&self, inode_num: u32) -> Result<Ext2Inode, FileSystemError>

Read an inode from disk

Source

pub fn read_directory_entries( &self, inode: &Ext2Inode, ) -> Result<Vec<Ext2DirectoryEntry>, FileSystemError>

Read directory entries from an inode

Source

fn get_inode_block( &self, inode: &Ext2Inode, logical_block: u64, ) -> Result<u64, FileSystemError>

Get the block number for a logical block within an inode

Source

fn get_inode_blocks( &self, inode: &Ext2Inode, start_logical_block: u64, count: u64, ) -> Result<Vec<u64>, FileSystemError>

Get multiple contiguous block numbers for logical blocks within an inode (batched version) This function efficiently maps multiple logical blocks to physical blocks, reducing the number of indirect block reads by batching them together.

Source

pub fn read_file_content( &self, inode_num: u32, size: usize, ) -> Result<Vec<u8>, FileSystemError>

Read the entire content of a file given its inode number (optimized)

Source

pub fn read_page_content( &self, inode_num: u32, page_index: u64, paddr: usize, ) -> Result<(), FileSystemError>

Read a single page (4096 bytes) of file content into physical memory.

This is used by the page cache manager for demand paging. The page is filled with zeros if beyond EOF.

Source

pub fn write_page_content( &self, inode_num: u32, page_index: u64, paddr: usize, ) -> Result<(), FileSystemError>

Write a single page (4096 bytes) of file content from physical memory.

This is used by the page cache manager for writeback.

Source

fn write_inode( &self, inode_number: u32, inode: &Ext2Inode, ) -> Result<(), FileSystemError>

Write an inode to disk

Source

fn initialize_directory( &self, dir_inode_number: u32, parent_inode_number: u32, ) -> Result<(), FileSystemError>

Initialize a new directory with . and .. entries

Source

fn allocate_block(&self) -> Result<u64, FileSystemError>

Allocate a new data block using proper bitmap management

Source

fn allocate_block_in_group(&self, group: u32) -> Result<u64, FileSystemError>

Allocate a block in a specific group - OPTIMIZED VERSION

Source

fn allocate_blocks_contiguous_in_group( &self, group: u32, count: u32, ) -> Result<Vec<u64>, FileSystemError>

Allocate multiple contiguous blocks in a specific group - OPTIMIZED VERSION

Source

fn allocate_blocks_contiguous( &self, count: u32, ) -> Result<Vec<u64>, FileSystemError>

Source

fn allocate_inode(&self) -> Result<u32, FileSystemError>

Allocate a new inode using proper bitmap management

Source

fn check_entry_exists( &self, parent_inode: u32, name: &String, ) -> Result<bool, FileSystemError>

Check if a file/directory already exists in the parent directory

Source

fn add_directory_entry( &self, parent_inode: u32, name: &String, child_inode: u32, file_type: FileType, ) -> Result<(), FileSystemError>

Add a directory entry to a parent directory

Source

fn remove_directory_entry( &self, parent_inode: u32, name: &String, ) -> Result<(), FileSystemError>

Remove a directory entry from a parent directory

Source

fn free_inode(&self, inode_number: u32) -> Result<(), FileSystemError>

Free an inode and update bitmaps and metadata

Source

fn clear_inode_on_disk(&self, inode_number: u32) -> Result<(), FileSystemError>

Source

pub fn write_file_content( &self, inode_num: u32, content: &[u8], ) -> Result<(), FileSystemError>

Write the entire content of a file given its inode number

Source

pub fn file_type_from_inode( &self, inode: &Ext2Inode, _inode_number: u32, ) -> Result<FileType, FileSystemError>

Convert ext2 inode mode to FileType

Source

fn get_inode_data_blocks( &self, inode: &Ext2Inode, ) -> Result<Vec<u32>, FileSystemError>

Get all data blocks used by an inode

Source

fn free_block(&self, block_number: u32) -> Result<(), FileSystemError>

Free a block and update bitmaps

Source

fn set_inode_block( &self, inode: &mut Ext2Inode, logical_block: u64, block_number: u32, ) -> Result<(), FileSystemError>

Set the block number for a logical block within an inode

Source

fn set_inode_blocks_simple_batch( &self, inode: &mut Ext2Inode, assignments: &[(u64, u32)], ) -> Result<(), FileSystemError>

Set multiple inode blocks efficiently by batching operations for Single Indirect blocks

Source

fn update_group_descriptor( &self, group: u32, bgd: &Ext2BlockGroupDescriptor, ) -> Result<(), FileSystemError>

Update group descriptor on disk

Source

fn update_superblock_counts( &self, block_delta: i32, inode_delta: i32, _dir_delta: i32, ) -> Result<(), FileSystemError>

Update superblock counts (blocks, inodes, directories)

Source

fn update_superblock_free_counts( &self, block_delta: i32, inode_delta: i32, ) -> Result<(), FileSystemError>

Update superblock free counts (blocks and inodes)

Source

fn read_blocks_cached( &self, block_nums: &[u64], ) -> Result<Vec<Vec<u8>>, FileSystemError>

Read multiple filesystem blocks with improved LRU cache and batching Optimized for fast path when all blocks are cached

Source

fn write_blocks_cached( &self, blocks: &BTreeMap<u64, Vec<u8>>, ) -> Result<(), FileSystemError>

Write multiple filesystem blocks with write-through to device and cache update

Source

fn sectors_per_block(&self) -> u64

Sectors per filesystem block

Source

fn block_to_sector(&self, block_num: u64) -> usize

Convert ext2 block number to starting sector index

Source

fn read_block_cached(&self, block_num: u64) -> Result<Vec<u8>, FileSystemError>

Read one filesystem block with LRU cache

Source

fn write_block_cached( &self, block_num: u64, data: &[u8], ) -> Result<(), FileSystemError>

Write one filesystem block with write-through to device and cache update

Source

pub fn print_cache_stats(&self)

Print cache statistics for debugging

Trait Implementations§

Source§

impl FileSystemOperations for Ext2FileSystem

Source§

fn fs_id(&self) -> FileSystemId

Get the unique filesystem identifier. Read more
Source§

fn lookup( &self, parent: &Arc<dyn VfsNode>, name: &String, ) -> Result<Arc<dyn VfsNode>, FileSystemError>

Look up a child node by name within a parent directory Read more
Source§

fn readdir( &self, node: &Arc<dyn VfsNode>, ) -> Result<Vec<DirectoryEntryInternal>, FileSystemError>

Read directory entries from a directory node
Source§

fn open( &self, node: &Arc<dyn VfsNode>, _flags: u32, ) -> Result<Arc<dyn FileObject>, FileSystemError>

Open a file represented by a VfsNode Read more
Source§

fn create( &self, parent: &Arc<dyn VfsNode>, name: &String, file_type: FileType, _mode: u32, ) -> Result<Arc<dyn VfsNode>, FileSystemError>

Create a new file in the specified directory
Source§

fn remove( &self, parent: &Arc<dyn VfsNode>, name: &String, ) -> Result<(), FileSystemError>

Remove a file from the specified directory
Source§

fn root_node(&self) -> Arc<dyn VfsNode>

Get the root VfsNode for this filesystem
Source§

fn name(&self) -> &str

Get filesystem name
Source§

fn as_any(&self) -> &dyn Any

Access to Any trait for downcasting
Source§

fn is_read_only(&self) -> bool

Check if filesystem is read-only
Create a hard link to an existing file Read more

Auto Trait Implementations§

§

impl !Freeze for Ext2FileSystem

§

impl !RefUnwindSafe for Ext2FileSystem

§

impl Send for Ext2FileSystem

§

impl Sync for Ext2FileSystem

§

impl Unpin for Ext2FileSystem

§

impl !UnwindSafe for Ext2FileSystem

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.