pub struct Fat<T> {
pub fat_cache_mgr: Arc<Mutex<T>>,
start_block_id: usize,
byts_per_sec: usize,
tot_ent: usize,
vacant_clus: Mutex<VecDeque<u32>>,
hint: Mutex<usize>,
}
Expand description
In-memory data structure In FAT32, there are 2 FATs by default. We use ONLY the first one.
Fields
fat_cache_mgr: Arc<Mutex<T>>
start_block_id: usize
The first block id of FAT. In FAT32, this is equal to bpb.rsvd_sec_cnt
byts_per_sec: usize
size fo sector in bytes copied from BPB
tot_ent: usize
The total number of FAT entries
vacant_clus: Mutex<VecDeque<u32>>
The queue used to store known vacant clusters
hint: Mutex<usize>
The final unused clus id we found
Implementations
Get the next cluster number pointed by current fat entry.
In theory, there may also be one function that only reads the first parts, or the needed FAT entries of the file.
Create a new FAT object in memory.
Argument
rsvd_sec_cnt
: size of BPBbyts_per_sec
: literal meaningclus
: the total numebr of FAT entries
Given any valid cluster number N, where in the FAT(s) is the entry for that cluster number Return the sector number of the FAT sector that contains the entry for cluster N in the first FAT
Given any valid cluster number N, where in the FAT(s) is the entry for that cluster number Return the sector number of the FAT sector that contains the entry for cluster N in the first FAT
Given any valid cluster number N, where in the FAT(s) is the entry for that cluster number Return the sector number of the FAT sector that contains the entry for cluster N in the first FAT
Return the offset (measured by bytes) of the entry from the first bit of the sector of the n is the ordinal number of the cluster
Assign the cluster entry to current
to next
pub fn alloc_mult(
&self,
block_device: &Arc<dyn BlockDevice>,
alloc_num: usize,
attach: Option<u32>
) -> Vec<u32>
pub fn alloc_mult(
&self,
block_device: &Arc<dyn BlockDevice>,
alloc_num: usize,
attach: Option<u32>
) -> Vec<u32>
Allocate as many clusters (but not greater than alloc_num) as possible.
Find and allocate an cluster from data area.
block_device
: The target block_device
cache_mgr
: The cache manager
attach
: The preceding cluster of the one to be allocated
Find and allocate an empty block from data area. This function must be changed into a cluster-based one in the future.