pub const SECTOR_SIZE: usize = 512;
const META_BLOCK_SIZE: Sectors = Sectors(8);
#[allow(dead_code)]
const MAX_META_DEV_SIZE: MetaBlocks = MetaBlocks(255 * ((1 << 14) - 64));
range_u64!(
DataBlocks,
"data blocks"
);
range_u64!(
MetaBlocks,
"meta blocks"
);
impl MetaBlocks {
pub fn sectors(self) -> Sectors {
self.0 * META_BLOCK_SIZE
}
}
range_u128!(
Bytes,
"bytes"
);
impl Bytes {
pub fn sectors(self) -> Sectors {
Sectors((self.0 / SECTOR_SIZE as u128) as u64)
}
}
range_u64!(
Sectors,
"sectors"
);
impl Sectors {
pub fn bytes(self) -> Bytes {
Bytes(u128::from(self.0) * SECTOR_SIZE as u128)
}
pub fn metablocks(self) -> MetaBlocks {
MetaBlocks(self / META_BLOCK_SIZE)
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_large() {
let max_sectors = Sectors(u64::MAX).bytes();
let size_sectors = max_sectors.sectors();
assert_eq!(size_sectors.bytes(), max_sectors);
}
#[test]
fn test_too_large() {
let max_bytes = Sectors(u64::MAX).bytes() + Sectors(1).bytes();
let sectors = max_bytes.sectors();
assert_eq!(sectors, Sectors(0));
}
}