pub struct RegularFile {
ffs: Weak<FastFileSystemInner>,
inode: TrackedInode,
}Expand description
A handle to a regular file in the filesystem.
This struct represents a low-level kernel handle to a regular file,
associated with a specific TrackedInode and the backing
FastFileSystemInner instance.
Fields§
§ffs: Weak<FastFileSystemInner>Weak reference to the FastFileSystemInner.
inode: TrackedInodeThe inode associated with this file.
Implementations§
Source§impl RegularFile
impl RegularFile
Sourcepub fn new(inode: TrackedInode, ffs: Weak<FastFileSystemInner>) -> Option<Self>
pub fn new(inode: TrackedInode, ffs: Weak<FastFileSystemInner>) -> Option<Self>
Creates a new RegularFile from a given inode and filesystem
reference.
Returns None if the provided inode does not represent a regular file.
§Parameters
inode: A tracked reference to the file’s inode.ffs: A weak reference to the filesystem context.
§Returns
Some(RegularFile)if the inode is valid and represents a regular file.Noneif the inode is invalid or not a regular file.
Trait Implementations§
Source§impl RegularFile for RegularFile
impl RegularFile for RegularFile
Source§fn ino(&self) -> InodeNumber
fn ino(&self) -> InodeNumber
Inode number of the file.
Source§fn read(
&self,
fba: FileBlockNumber,
buf: &mut [u8; 4096],
) -> Result<bool, KernelError>
fn read( &self, fba: FileBlockNumber, buf: &mut [u8; 4096], ) -> Result<bool, KernelError>
Source§fn write(
&self,
fba: FileBlockNumber,
buf: &[u8; 4096],
min_size: usize,
) -> Result<(), KernelError>
fn write( &self, fba: FileBlockNumber, buf: &[u8; 4096], min_size: usize, ) -> Result<(), KernelError>
Writes a 4096-byte data into the specified file block.
This method writes the contents of buf to the file block indicated by
fba. If the target block lies beyond the current end of the file,
the file may be extended up to new_size bytes to accommodate the
write.
However, if the target block lies beyond the current file size and
new_size is insufficient to reach it, the write will fail.
§Parameters
fba: TheFileBlockNumberindicating the block to write to.buf: A buffer containing exactly 4096 bytes of data to write.new_size: The desired minimum file size (in bytes) after the write. If this value is less than or equal to the current file size, no growth occurs.
§Returns
Ok(())if the write is successful.Err(KernelError)if the operation fails (e.g., out-of-bounds write, I/O error).