FastFileSystemInner

Struct FastFileSystemInner 

Source
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: Disk

The underlying disk device used by the filesystem.

§block_count: usize

Total number of blocks available in the filesystem.

§inode_count: usize

Total number of inodes supported by the filesystem.

§has_journal: usize

Indicate 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: bool

Whether trace the transactions for debugging purpose.

Implementations§

Source§

impl FastFileSystemInner

Source

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.

Source

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.

Source

pub fn block_bitmap(&self) -> Range<LogicalBlockAddress>

Returns the range of block address of the block bitmap.

The block bitmap follows the inode bitmap.

Source

pub fn journal(&self) -> Range<LogicalBlockAddress>

Returns the range of block address of the journal.

The data block region follows the bitmaps.

Source

pub fn inode(&self) -> Range<LogicalBlockAddress>

Returns the range of the block address of the Inode[] startpoint.

The data block region follows the bitmaps.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.
Source

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 containing InodeArray is located.
    • offset:the index within that array where this specific inode resides.
  • None: if the inode number is out of bounds.
Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl !Freeze for FastFileSystemInner

§

impl !RefUnwindSafe for FastFileSystemInner

§

impl Send for FastFileSystemInner

§

impl Sync for FastFileSystemInner

§

impl Unpin for FastFileSystemInner

§

impl !UnwindSafe for FastFileSystemInner

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.