pub struct FastFileSystemInner {
pub(crate) disk: Disk,
pub block_count: usize,
pub inode_count: usize,
pub has_journal: usize,
pub blocks: SpinLock<LRUCache<LogicalBlockAddress, Arc<SpinLock<[u8; 4096]>>, 512>>,
pub sb: BlockPointsTo<SuperBlock>,
pub inodes: SpinLock<BTreeMap<InodeNumber, Arc<RwLock<Inode>>>>,
pub journal: Option<SpinLock<Journal>>,
pub debug_journal: bool,
}Expand description
Represents the internal structure of a Fast File System (FFS).
This structure encapsulates the core components of the FFS implementation, including metadata loaded from disk, in-memory caches, and journal state. It provides the foundational layer for all low-level filesystem operations, such as reading/writing blocks and accessing inode metadata.
This type is used internally by FastFileSystem and is not intended
to be accessed directly by external code.
Fields§
§disk: DiskThe underlying disk device used by the filesystem.
block_count: usizeTotal number of blocks available in the filesystem.
inode_count: usizeTotal number of inodes supported by the filesystem.
has_journal: usizeIndicate this file system support journaling.
blocks: SpinLock<LRUCache<LogicalBlockAddress, Arc<SpinLock<[u8; 4096]>>, 512>>The expected view of the disk after all journaled changes are checkpointed.
This in-memory map reflects the filesystem state after applying journaled updates, but may differ from the actual disk contents if a crash occurred before checkpointing.
sb: BlockPointsTo<SuperBlock>On-disk superblock structure, wrapped in metadata-aware block access.
inodes: SpinLock<BTreeMap<InodeNumber, Arc<RwLock<Inode>>>>In-memory table mapping inode numbers to their live representations.
journal: Option<SpinLock<Journal>>The current state of the journal (if present), wrapped in a lock to allow mutable access during journal operations.
debug_journal: boolWhether trace the transactions for debugging purpose.
Implementations§
Source§impl FastFileSystemInner
impl FastFileSystemInner
Sourcepub fn from_raw_sb(
sb: BlockPointsTo<SuperBlock>,
disk: Disk,
debug_journal: bool,
disable_journal: bool,
) -> Result<Self, KernelError>
pub fn from_raw_sb( sb: BlockPointsTo<SuperBlock>, disk: Disk, debug_journal: bool, disable_journal: bool, ) -> Result<Self, KernelError>
Constructs a new file system instance from an on-disk superblock.
This function initializes a FastFileSystemInner by reading the
provided superblock and setting up access to the underlying disk.
Sourcepub fn inode_bitmap(&self) -> Range<LogicalBlockAddress>
pub fn inode_bitmap(&self) -> Range<LogicalBlockAddress>
Returns the range of block address of the inode bitmap.
The inode bitmap is located immediately after the inode table.
Sourcepub fn block_bitmap(&self) -> Range<LogicalBlockAddress>
pub fn block_bitmap(&self) -> Range<LogicalBlockAddress>
Returns the range of block address of the block bitmap.
The block bitmap follows the inode bitmap.
Sourcepub fn journal(&self) -> Range<LogicalBlockAddress>
pub fn journal(&self) -> Range<LogicalBlockAddress>
Returns the range of block address of the journal.
The data block region follows the bitmaps.
Sourcepub fn inode(&self) -> Range<LogicalBlockAddress>
pub fn inode(&self) -> Range<LogicalBlockAddress>
Returns the range of the block address of the Inode[] startpoint.
The data block region follows the bitmaps.
Sourcepub fn data_block_start(&self) -> LogicalBlockAddress
pub fn data_block_start(&self) -> LogicalBlockAddress
Returns the starting block address of the data blocks.
The data block region follows the bitmaps and journal.
Sourcepub fn open_transaction(&self, name: &str) -> RunningTransaction<'_>
pub fn open_transaction(&self, name: &str) -> RunningTransaction<'_>
Opens a new running transaction.
This function begins a transaction on the file system, allowing multiple operations to be grouped together atomically. Transactions ensure crash consistency by recording updates in the journal before they are committed to the main file system.
Sourcepub fn read_data_block(
&self,
lba: LogicalBlockAddress,
) -> Result<Box<[u8; 4096]>, KernelError>
pub fn read_data_block( &self, lba: LogicalBlockAddress, ) -> Result<Box<[u8; 4096]>, KernelError>
Reads a data block from disk.
This function retrieves the 4 KiB block located at the specified logical block address (LBA) from the underlying disk. It is used for reading file data on disk.
Sourcepub fn write_data_block(
&self,
lba: LogicalBlockAddress,
b: &[u8; 4096],
) -> Result<(), KernelError>
pub fn write_data_block( &self, lba: LogicalBlockAddress, b: &[u8; 4096], ) -> Result<(), KernelError>
Writes a 4 KiB data block to disk.
This function stores the given buffer at the specified logical block address (LBA) on the underlying disk. It is typically used for writing file contents.
Sourcepub fn get_inode_bitmap_lba_index(
&self,
ino: InodeNumber,
) -> Option<(LogicalBlockAddress, usize)>
pub fn get_inode_bitmap_lba_index( &self, ino: InodeNumber, ) -> Option<(LogicalBlockAddress, usize)>
Converts this inode number into the corresponding location in the inode bitmap.
§Arguments
fs: Reference to the file system’s internal metadata layout.
§Returns
Some((lba, offset): if the inode number is valid, which includes:lba: the logical block address of the inode bitmap block that contains this inode.offset: the bit offset within that bitmap block corresponding to this inode.
None: if the inode number is out of bounds.
Sourcepub fn get_inode_array_lba_index(
&self,
ino: InodeNumber,
) -> Option<(LogicalBlockAddress, usize)>
pub fn get_inode_array_lba_index( &self, ino: InodeNumber, ) -> Option<(LogicalBlockAddress, usize)>
Converts this inode number into the corresponding location in the inode array.
§Returns
Some((lba, offset)): if the inode number is valid, which includes:lba: the logical block address where the containingInodeArrayis located.offset:the index within that array where this specific inode resides.
None: if the inode number is out of bounds.
Sourcepub fn allocate_inode(
self: &Arc<Self>,
is_dir: bool,
tx: &RunningTransaction<'_>,
) -> Result<(InodeNumber, TrackedInode), KernelError>
pub fn allocate_inode( self: &Arc<Self>, is_dir: bool, tx: &RunningTransaction<'_>, ) -> Result<(InodeNumber, TrackedInode), KernelError>
Allocates a new inode in the file system.
This function creates a new inode on disk and returns both its
inode number and a TrackedInode handle for in-memory access.
The allocation is recorded in the given transaction for crash
consistency.
Sourcepub fn allocate_block(
&self,
tx: &RunningTransaction<'_>,
) -> Result<LogicalBlockAddress, KernelError>
pub fn allocate_block( &self, tx: &RunningTransaction<'_>, ) -> Result<LogicalBlockAddress, KernelError>
Allocates a new data block on disk.
This function reserves a free block for use in the file system, recording the allocation in the active transaction. The block is marked as used in the allocation bitmap and returned to the caller.
Sourcepub fn get_inode(
self: &Arc<Self>,
ino: InodeNumber,
) -> Result<TrackedInode, KernelError>
pub fn get_inode( self: &Arc<Self>, ino: InodeNumber, ) -> Result<TrackedInode, KernelError>
Retrieves an inode from disk or cache.
This function returns a TrackedInode corresponding to the given
inode number. If the inode is cached in memory, it is returned
directly; otherwise, it is read from disk and added to the cache.
This method manages a “unique view” of a single inode.
Sourcepub fn remove_inode(&self, ino: InodeNumber) -> Option<Arc<RwLock<Inode>>>
pub fn remove_inode(&self, ino: InodeNumber) -> Option<Arc<RwLock<Inode>>>
Removes an inode from the in-memory inode table.
This function evicts the given inode from the inode cache maintained by the file system. It does not remove the inode’s contents on disk, only its in-memory representation.