Inode

Struct Inode 

Source
pub struct Inode {
    pub ino: InodeNumber,
    pub ftype: FileType,
    pub size: usize,
    pub link_count: usize,
    pub dblocks: [Option<LogicalBlockAddress>; 12],
    pub iblock: Option<LogicalBlockAddress>,
    pub diblock: Option<LogicalBlockAddress>,
}
Expand description

Represents an inode in memory, the metadata structure for a file or directory.

An inode stores essential information about a file, including its size, type, and the locations of its data blocks.

Fields§

§ino: InodeNumber

The unique inode number assigned to this file or directory.

§ftype: FileType

The type of the file (e.g., regular file, directory, symbolic link).

Uses a u32 to store values corresponding to FileType.

§size: usize

The total size of the file in bytes.

§link_count: usize

Number of links alive in the filesystem.

§dblocks: [Option<LogicalBlockAddress>; 12]

Directly mapped data blocks.

These 12 blocks store the first portions of a file’s data, allowing for efficient access to small files without requiring indirect blocks.

§iblock: Option<LogicalBlockAddress>

An indirect block, which contains pointers to additional data blocks.

This extends the file size capability beyond direct blocks by storing an array of logical block addresses in a separate block.

§diblock: Option<LogicalBlockAddress>

A doubly indirect block, which contains pointers to indirect blocks.

This allows for even larger file sizes by introducing an extra level of indirection.

Implementations§

Source§

impl Inode

Source

pub(crate) fn from_disk_layout(inode: &Inode) -> Result<Self, KernelError>

Constructs an in-memory Inode from its on-disk representation.

§Arguments
§Returns
  • Ok(Self): If the conversion succeeds.
  • Err(KernelError): If the inode contains invalid or inconsistent data.

This function performs necessary validation and translation between the raw on-disk layout and the structured, in-memory format used by the filesystem.

Source

pub fn into_disk_format(&self) -> Inode

Converts the in-memory Inode structure into its on-disk representation.

This is used when persisting an inode to disk, typically during checkpointing or journal submission. The returned disk_layout::Inode struct matches the format expected by the on-disk inode array.

Source

pub(crate) fn new(ino: InodeNumber, is_dir: bool) -> Self

Creates a new in-memory Inode instance.

This function is used to initialize a fresh inode in memory before it is ever written to disk. It sets the inode number and whether the inode represents a directory.

§Parameters
  • ino: The inode number.
  • is_dir: Whether this inode represents a directory (true) or a file (false).
§Returns

A new Inode instance ready to be inserted into the inode table.

Source

pub fn get( &self, ffs: &FastFileSystemInner, fba: FileBlockNumber, ) -> Result<Option<LogicalBlockAddress>, KernelError>

Retrieves the logical block address (LBA) corresponding to a file block.

§Arguments
  • ffs: Reference to the file system.
  • fba: FileBlockNumber, relative to the beginning of the file.
§Returns
  • Ok(lba): The logical block address where the specified file block is stored.
  • Err(KernelError): If the block is not allocated or the block number is out of bounds.
Source

pub fn grow( &mut self, ffs: &FastFileSystemInner, until: FileBlockNumber, tx: &RunningTransaction<'_>, ) -> Result<(), KernelError>

Grows the inode to include at least the given number of file blocks.

§Arguments
  • ffs: Reference to the file system.
  • until: The target FileBlockNumber (inclusive) that the inode should grow to cover.
  • tx: The running transaction used to log allocation changes.
§Returns
  • Ok(()): If the inode was successfully extended.
  • Err(KernelError): If allocation fails or the inode cannot be grown.

This function ensures that all blocks up to until are allocated, performing allocation of direct and indirect blocks as needed. The transaction log is updated to support crash consistency.

Source

pub fn zeroify( ino: &mut TrackedInodeWriteGuard<'_, '_, '_, '_>, tx: &RunningTransaction<'_>, ffs: &FastFileSystemInner, )

Deallocate inner blocks and set the inode’s size to zero.

Note that submitting the InodeWriteGuard is the caller’s responsibility.

Trait Implementations§

Source§

impl Debug for Inode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Inode

§

impl RefUnwindSafe for Inode

§

impl Send for Inode

§

impl Sync for Inode

§

impl Unpin for Inode

§

impl UnwindSafe for Inode

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.