exfat/
param.rs

1pub(crate) struct Params {
2    pub fat_offset: u64,          // in sector
3    pub fat_length: u64,          // in sector
4    pub cluster_heap_offset: u64, // in sector
5    pub cluster_count: usize,     // not including the first 2 pseudo clusters
6    pub first_cluster_of_root_directory: usize,
7    pub volume_flags: VolumeFlags,
8    pub bytes_per_sector: u64,
9    pub sectors_per_cluster: u64,
10    pub number_of_fats: u8,
11}
12
13impl Params {
14    /// Calculates offset in the image of a specified cluster.
15    pub fn cluster_offset(&self, index: usize) -> Option<u64> {
16        if index < 2 {
17            return None;
18        }
19
20        let index = index - 2;
21
22        if index >= self.cluster_count {
23            return None;
24        }
25
26        let sector = self.cluster_heap_offset + self.sectors_per_cluster * index as u64;
27        let offset = self.bytes_per_sector * sector;
28
29        Some(offset)
30    }
31
32    /// Gets the size of cluster, in bytes.
33    pub fn cluster_size(&self) -> u64 {
34        self.bytes_per_sector * self.sectors_per_cluster
35    }
36}
37
38#[derive(Clone, Copy)]
39#[repr(transparent)]
40pub(crate) struct VolumeFlags(u16);
41
42impl VolumeFlags {
43    pub fn active_fat(self) -> usize {
44        (self.0 & 1) as usize
45    }
46}
47
48impl From<u16> for VolumeFlags {
49    fn from(v: u16) -> Self {
50        Self(v)
51    }
52}