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: FileSystemIdUnique 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: u32Block size in bytes
root_inode: u32Root directory inode
root: RwLock<Arc<Ext2Node>>Root directory node
name: StringFilesystem 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
impl Ext2FileSystem
Sourcepub fn new(
block_device: Arc<dyn BlockDevice>,
) -> Result<Arc<Self>, FileSystemError>
pub fn new( block_device: Arc<dyn BlockDevice>, ) -> Result<Arc<Self>, FileSystemError>
Create a new ext2 filesystem from a block device
Sourcepub fn new_from_device_id(
device_id: usize,
) -> Result<Arc<Self>, FileSystemError>
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
Sourcepub fn new_from_params(
params: &Ext2Params,
) -> Result<Arc<Self>, FileSystemError>
pub fn new_from_params( params: &Ext2Params, ) -> Result<Arc<Self>, FileSystemError>
Create a new ext2 filesystem from parameters
Sourcepub fn read_inode(&self, inode_num: u32) -> Result<Ext2Inode, FileSystemError>
pub fn read_inode(&self, inode_num: u32) -> Result<Ext2Inode, FileSystemError>
Read an inode from disk
Sourcepub fn read_directory_entries(
&self,
inode: &Ext2Inode,
) -> Result<Vec<Ext2DirectoryEntry>, FileSystemError>
pub fn read_directory_entries( &self, inode: &Ext2Inode, ) -> Result<Vec<Ext2DirectoryEntry>, FileSystemError>
Read directory entries from an inode
Sourcefn get_inode_block(
&self,
inode: &Ext2Inode,
logical_block: u64,
) -> Result<u64, FileSystemError>
fn get_inode_block( &self, inode: &Ext2Inode, logical_block: u64, ) -> Result<u64, FileSystemError>
Get the block number for a logical block within an inode
Sourcefn get_inode_blocks(
&self,
inode: &Ext2Inode,
start_logical_block: u64,
count: u64,
) -> Result<Vec<u64>, FileSystemError>
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.
Sourcepub fn read_file_content(
&self,
inode_num: u32,
size: usize,
) -> Result<Vec<u8>, FileSystemError>
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)
Sourcepub fn read_page_content(
&self,
inode_num: u32,
page_index: u64,
paddr: usize,
) -> Result<(), FileSystemError>
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.
Sourcepub fn write_page_content(
&self,
inode_num: u32,
page_index: u64,
paddr: usize,
) -> Result<(), FileSystemError>
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.
Sourcefn write_inode(
&self,
inode_number: u32,
inode: &Ext2Inode,
) -> Result<(), FileSystemError>
fn write_inode( &self, inode_number: u32, inode: &Ext2Inode, ) -> Result<(), FileSystemError>
Write an inode to disk
Sourcefn initialize_directory(
&self,
dir_inode_number: u32,
parent_inode_number: u32,
) -> Result<(), FileSystemError>
fn initialize_directory( &self, dir_inode_number: u32, parent_inode_number: u32, ) -> Result<(), FileSystemError>
Initialize a new directory with . and .. entries
Sourcefn allocate_block(&self) -> Result<u64, FileSystemError>
fn allocate_block(&self) -> Result<u64, FileSystemError>
Allocate a new data block using proper bitmap management
Sourcefn allocate_block_in_group(&self, group: u32) -> Result<u64, FileSystemError>
fn allocate_block_in_group(&self, group: u32) -> Result<u64, FileSystemError>
Allocate a block in a specific group - OPTIMIZED VERSION
Sourcefn allocate_blocks_contiguous_in_group(
&self,
group: u32,
count: u32,
) -> Result<Vec<u64>, FileSystemError>
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
fn allocate_blocks_contiguous( &self, count: u32, ) -> Result<Vec<u64>, FileSystemError>
Sourcefn allocate_inode(&self) -> Result<u32, FileSystemError>
fn allocate_inode(&self) -> Result<u32, FileSystemError>
Allocate a new inode using proper bitmap management
Sourcefn check_entry_exists(
&self,
parent_inode: u32,
name: &String,
) -> Result<bool, FileSystemError>
fn check_entry_exists( &self, parent_inode: u32, name: &String, ) -> Result<bool, FileSystemError>
Check if a file/directory already exists in the parent directory
Sourcefn add_directory_entry(
&self,
parent_inode: u32,
name: &String,
child_inode: u32,
file_type: FileType,
) -> Result<(), FileSystemError>
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
Sourcefn remove_directory_entry(
&self,
parent_inode: u32,
name: &String,
) -> Result<(), FileSystemError>
fn remove_directory_entry( &self, parent_inode: u32, name: &String, ) -> Result<(), FileSystemError>
Remove a directory entry from a parent directory
Sourcefn free_inode(&self, inode_number: u32) -> Result<(), FileSystemError>
fn free_inode(&self, inode_number: u32) -> Result<(), FileSystemError>
Free an inode and update bitmaps and metadata
fn clear_inode_on_disk(&self, inode_number: u32) -> Result<(), FileSystemError>
Sourcepub fn write_file_content(
&self,
inode_num: u32,
content: &[u8],
) -> Result<(), FileSystemError>
pub fn write_file_content( &self, inode_num: u32, content: &[u8], ) -> Result<(), FileSystemError>
Write the entire content of a file given its inode number
Sourcepub fn file_type_from_inode(
&self,
inode: &Ext2Inode,
_inode_number: u32,
) -> Result<FileType, FileSystemError>
pub fn file_type_from_inode( &self, inode: &Ext2Inode, _inode_number: u32, ) -> Result<FileType, FileSystemError>
Convert ext2 inode mode to FileType
Sourcefn get_inode_data_blocks(
&self,
inode: &Ext2Inode,
) -> Result<Vec<u32>, FileSystemError>
fn get_inode_data_blocks( &self, inode: &Ext2Inode, ) -> Result<Vec<u32>, FileSystemError>
Get all data blocks used by an inode
Sourcefn free_block(&self, block_number: u32) -> Result<(), FileSystemError>
fn free_block(&self, block_number: u32) -> Result<(), FileSystemError>
Free a block and update bitmaps
Sourcefn set_inode_block(
&self,
inode: &mut Ext2Inode,
logical_block: u64,
block_number: u32,
) -> Result<(), FileSystemError>
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
Sourcefn set_inode_blocks_simple_batch(
&self,
inode: &mut Ext2Inode,
assignments: &[(u64, u32)],
) -> Result<(), FileSystemError>
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
Sourcefn update_group_descriptor(
&self,
group: u32,
bgd: &Ext2BlockGroupDescriptor,
) -> Result<(), FileSystemError>
fn update_group_descriptor( &self, group: u32, bgd: &Ext2BlockGroupDescriptor, ) -> Result<(), FileSystemError>
Update group descriptor on disk
Sourcefn update_superblock_counts(
&self,
block_delta: i32,
inode_delta: i32,
_dir_delta: i32,
) -> Result<(), FileSystemError>
fn update_superblock_counts( &self, block_delta: i32, inode_delta: i32, _dir_delta: i32, ) -> Result<(), FileSystemError>
Update superblock counts (blocks, inodes, directories)
Sourcefn update_superblock_free_counts(
&self,
block_delta: i32,
inode_delta: i32,
) -> Result<(), FileSystemError>
fn update_superblock_free_counts( &self, block_delta: i32, inode_delta: i32, ) -> Result<(), FileSystemError>
Update superblock free counts (blocks and inodes)
Sourcefn read_blocks_cached(
&self,
block_nums: &[u64],
) -> Result<Vec<Vec<u8>>, FileSystemError>
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
Sourcefn write_blocks_cached(
&self,
blocks: &BTreeMap<u64, Vec<u8>>,
) -> Result<(), FileSystemError>
fn write_blocks_cached( &self, blocks: &BTreeMap<u64, Vec<u8>>, ) -> Result<(), FileSystemError>
Write multiple filesystem blocks with write-through to device and cache update
Sourcefn sectors_per_block(&self) -> u64
fn sectors_per_block(&self) -> u64
Sectors per filesystem block
Sourcefn block_to_sector(&self, block_num: u64) -> usize
fn block_to_sector(&self, block_num: u64) -> usize
Convert ext2 block number to starting sector index
Sourcefn read_block_cached(&self, block_num: u64) -> Result<Vec<u8>, FileSystemError>
fn read_block_cached(&self, block_num: u64) -> Result<Vec<u8>, FileSystemError>
Read one filesystem block with LRU cache
Sourcefn write_block_cached(
&self,
block_num: u64,
data: &[u8],
) -> Result<(), FileSystemError>
fn write_block_cached( &self, block_num: u64, data: &[u8], ) -> Result<(), FileSystemError>
Write one filesystem block with write-through to device and cache update
Sourcepub fn print_cache_stats(&self)
pub fn print_cache_stats(&self)
Print cache statistics for debugging