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: InodeNumberThe unique inode number assigned to this file or directory.
ftype: FileTypeThe type of the file (e.g., regular file, directory, symbolic link).
Uses a u32 to store values corresponding to FileType.
size: usizeThe total size of the file in bytes.
link_count: usizeNumber 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
impl Inode
Sourcepub(crate) fn from_disk_layout(inode: &Inode) -> Result<Self, KernelError>
pub(crate) fn from_disk_layout(inode: &Inode) -> Result<Self, KernelError>
Constructs an in-memory Inode from its on-disk representation.
§Arguments
inode: A reference to thedisk_layout::Inodestructure loaded from disk.
§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.
Sourcepub fn into_disk_format(&self) -> Inode
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.
Sourcepub(crate) fn new(ino: InodeNumber, is_dir: bool) -> Self
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.
Sourcepub fn get(
&self,
ffs: &FastFileSystemInner,
fba: FileBlockNumber,
) -> Result<Option<LogicalBlockAddress>, KernelError>
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.
Sourcepub fn grow(
&mut self,
ffs: &FastFileSystemInner,
until: FileBlockNumber,
tx: &RunningTransaction<'_>,
) -> Result<(), KernelError>
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 targetFileBlockNumber(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.
Sourcepub fn zeroify(
ino: &mut TrackedInodeWriteGuard<'_, '_, '_, '_>,
tx: &RunningTransaction<'_>,
ffs: &FastFileSystemInner,
)
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.