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
impl FatSectorCache
Sourcepub fn new(
fat_start: usize,
fat_size: usize,
fat_count: usize,
sector_size: usize,
capacity: usize,
) -> Self
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 bytesfat_size- Size of one FAT copy in bytesfat_count- Number of FAT copies (typically 2)sector_size- Size of each sector in bytescapacity- Maximum number of sectors to cache
Sourcepub fn with_default_capacity(
fat_start: usize,
fat_size: usize,
fat_count: usize,
sector_size: usize,
) -> Self
pub fn with_default_capacity( fat_start: usize, fat_size: usize, fat_count: usize, sector_size: usize, ) -> Self
Create a cache with default capacity.
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Get cache statistics.
Sourcepub fn reset_stats(&mut self)
pub fn reset_stats(&mut self)
Reset cache statistics.
Sourcepub fn clear<T: Read + Write + Seek>(
&mut self,
writer: Option<&mut T>,
) -> Result<()>
pub fn clear<T: Read + Write + Seek>( &mut self, writer: Option<&mut T>, ) -> Result<()>
Clear the cache, optionally flushing dirty sectors first.
Sourcepub fn flush<T: Write + Seek>(&mut self, writer: &mut T) -> Result<()>
pub fn flush<T: Write + Seek>(&mut self, writer: &mut T) -> Result<()>
Flush all dirty sectors to disk.
Sourcepub fn read_fat12_entry<T: Read + Seek>(
&mut self,
reader: &mut T,
cluster: usize,
) -> Result<u16>
pub fn read_fat12_entry<T: Read + Seek>( &mut self, reader: &mut T, cluster: usize, ) -> Result<u16>
Read a FAT12 entry using the cache.
Sourcepub fn write_fat12_entry<T: Read + Write + Seek>(
&mut self,
io: &mut T,
cluster: usize,
value: u16,
) -> Result<()>
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.
Sourcepub fn read_fat16_entry<T: Read + Seek>(
&mut self,
reader: &mut T,
cluster: usize,
) -> Result<u16>
pub fn read_fat16_entry<T: Read + Seek>( &mut self, reader: &mut T, cluster: usize, ) -> Result<u16>
Read a FAT16 entry using the cache.
Sourcepub fn write_fat16_entry<T: Read + Write + Seek>(
&mut self,
io: &mut T,
cluster: usize,
value: u16,
) -> Result<()>
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).