Skip to main content

FatSectorCache

Struct FatSectorCache 

Source
pub struct FatSectorCache { /* private fields */ }
Expand description

FAT sector cache with LRU eviction.

This cache stores FAT table sectors in memory to reduce seek operations during cluster chain traversal and allocation.

Implementations§

Source§

impl FatSectorCache

Source

pub fn new( fat_start: usize, fat_size: usize, fat_count: usize, sector_size: usize, capacity: usize, ) -> Self

Create a new FAT sector cache.

§Arguments
  • fat_start - Start offset of the FAT in bytes
  • fat_size - Size of one FAT copy in bytes
  • fat_count - Number of FAT copies (typically 2)
  • sector_size - Size of each sector in bytes
  • capacity - Maximum number of sectors to cache
Source

pub fn with_default_capacity( fat_start: usize, fat_size: usize, fat_count: usize, sector_size: usize, ) -> Self

Create a cache with default capacity.

Source

pub fn stats(&self) -> CacheStats

Get cache statistics.

Source

pub fn reset_stats(&mut self)

Reset cache statistics.

Source

pub fn clear<T: Read + Write + Seek>( &mut self, writer: Option<&mut T>, ) -> Result<()>

Clear the cache, optionally flushing dirty sectors first.

Source

pub fn len(&self) -> usize

Get the number of cached sectors.

Source

pub fn is_empty(&self) -> bool

Check if the cache is empty.

Source

pub fn flush<T: Write + Seek>(&mut self, writer: &mut T) -> Result<()>

Flush all dirty sectors to disk.

Source

pub fn read_fat12_entry<T: Read + Seek>( &mut self, reader: &mut T, cluster: usize, ) -> Result<u16>

Read a FAT12 entry using the cache.

Source

pub fn write_fat12_entry<T: Read + Write + Seek>( &mut self, io: &mut T, cluster: usize, value: u16, ) -> Result<()>

Write a FAT12 entry through the cache.

Requires Read + Write + Seek because the cache is write-back: an LRU eviction during this call must flush a dirty sector to disk before discarding it.

Source

pub fn read_fat16_entry<T: Read + Seek>( &mut self, reader: &mut T, cluster: usize, ) -> Result<u16>

Read a FAT16 entry using the cache.

Source

pub fn write_fat16_entry<T: Read + Write + Seek>( &mut self, io: &mut T, cluster: usize, value: u16, ) -> Result<()>

Write a FAT16 entry through the cache.

Requires Read + Write + Seek because eviction may flush a dirty sector before discarding it (see Self::write_fat12_entry).

Source

pub fn read_fat32_entry<T: Read + Seek>( &mut self, reader: &mut T, cluster: usize, ) -> Result<u32>

Read a FAT32 entry using the cache.

Source

pub fn write_fat32_entry<T: Read + Write + Seek>( &mut self, io: &mut T, cluster: usize, value: u32, ) -> Result<()>

Write a FAT32 entry through the cache.

Requires Read + Write + Seek because eviction may flush a dirty sector before discarding it (see Self::write_fat12_entry).

Trait Implementations§

Source§

impl Debug for FatSectorCache

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MaybePod for T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.