pub struct Slot {
pub file: RegularFile,
pub fba: FileBlockNumber,
pub page: Page,
pub writeback_size: Option<usize>,
}Expand description
A single entry in the page cache.
A Slot corresponds to one file block stored in memory.
Fields§
§file: RegularFileThe file this slot belongs to.
fba: FileBlockNumberThe file block number this slot represents.
page: PageThe backing page containing the block’s data.
writeback_size: Option<usize>Size to be write-backed if dirtied. If the slot is clean, this will be
None.
Implementations§
Source§impl Slot
impl Slot
Sourcepub fn new(file: RegularFile, fba: FileBlockNumber, page: Page) -> Self
pub fn new(file: RegularFile, fba: FileBlockNumber, page: Page) -> Self
Create a new slot for the given file, block, and backing page.
By default, the slot is clean (i.e., writeback_size is None).
Sourcepub fn read_page(&self, buf: &mut [u8; 4096])
pub fn read_page(&self, buf: &mut [u8; 4096])
Copy the page contents into the provided buffer.
The buffer must be exactly 4096 bytes long, representing a full page. This method does not trigger I/O.
Sourcepub fn write_page(&mut self, buf: &[u8; 4096], min_size: usize)
pub fn write_page(&mut self, buf: &[u8; 4096], min_size: usize)
Update the page contents from the provided buffer.
Marks the slot as dirty with a write-back of at least min_size bytes.
The buffer must be exactly 4096 bytes long.
Sourcepub fn writeback(&mut self) -> Result<(), KernelError>
pub fn writeback(&mut self) -> Result<(), KernelError>
Write back the dirty portion of the page to the underlying file.
- If
writeback_sizeisSome(size), representing slot is dirty, marked with the desired minimum file size (in bytes) after write-back. - On success, clears the
writeback_sizetoNone.
If the slot is clean, this does not trigger the I/O.