pub use self::{
bda_size::{BDAExtendedSize, ReservedSize},
blkdev_size::BlockdevSize,
mda_size::{MDADataSize, MDARegionSize, MDASize},
static_header_size::{StaticHeaderSize, STATIC_HEADER_SIZE},
};
pub mod static_header_size {
use devicemapper::Sectors;
pub const PRE_SIGBLOCK_PADDING_SECTORS: usize = 1;
pub const SIGBLOCK_SECTORS: usize = 1;
pub const POST_SIGBLOCK_PADDING_SECTORS: usize = 6;
pub const SIGBLOCK_REGION_SECTORS: usize =
PRE_SIGBLOCK_PADDING_SECTORS + SIGBLOCK_SECTORS + POST_SIGBLOCK_PADDING_SECTORS;
pub const STATIC_HEADER_SECTORS: usize = 2 * SIGBLOCK_REGION_SECTORS;
pub const FIRST_SIGBLOCK_START_SECTORS: usize = PRE_SIGBLOCK_PADDING_SECTORS;
pub const SECOND_SIGBLOCK_START_SECTORS: usize =
SIGBLOCK_REGION_SECTORS + PRE_SIGBLOCK_PADDING_SECTORS;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct StaticHeaderSize(Sectors);
pub const STATIC_HEADER_SIZE: StaticHeaderSize =
StaticHeaderSize(Sectors(STATIC_HEADER_SECTORS as u64));
impl StaticHeaderSize {
pub fn sectors(self) -> Sectors {
self.0
}
}
}
pub mod mda_size {
use devicemapper::{Bytes, Sectors};
pub const _MDA_REGION_HDR_SIZE: usize = 32;
const MDA_REGION_HDR_SIZE: Bytes = Bytes(_MDA_REGION_HDR_SIZE as u128);
pub const MIN_MDA_DATA_REGION_SIZE: Bytes = Bytes(260_064);
pub const NUM_PRIMARY_MDA_REGIONS: usize = 2;
pub const NUM_MDA_REGIONS: usize = 2 * NUM_PRIMARY_MDA_REGIONS;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct MDASize(pub Sectors);
impl Default for MDASize {
fn default() -> MDASize {
MDARegionSize::default().mda_size()
}
}
impl MDASize {
pub fn sectors(self) -> Sectors {
self.0
}
pub fn region_size(self) -> MDARegionSize {
MDARegionSize(self.0 / NUM_MDA_REGIONS)
}
pub fn bda_size(self) -> super::bda_size::BDASize {
super::bda_size::BDASize::new(
self.0 + Sectors(super::static_header_size::STATIC_HEADER_SECTORS as u64),
)
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct MDARegionSize(pub Sectors);
impl Default for MDARegionSize {
fn default() -> MDARegionSize {
MDADataSize::default().region_size()
}
}
impl MDARegionSize {
pub fn sectors(self) -> Sectors {
self.0
}
pub fn mda_size(self) -> MDASize {
MDASize(self.0 * NUM_MDA_REGIONS)
}
pub fn data_size(self) -> MDADataSize {
MDADataSize(self.0.bytes() - MDA_REGION_HDR_SIZE)
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct MDADataSize(Bytes);
impl Default for MDADataSize {
fn default() -> MDADataSize {
MDADataSize(MIN_MDA_DATA_REGION_SIZE)
}
}
impl MDADataSize {
#[allow(dead_code)]
pub fn new(value: Bytes) -> MDADataSize {
if value > MIN_MDA_DATA_REGION_SIZE {
MDADataSize(value)
} else {
MDADataSize::default()
}
}
pub fn region_size(self) -> MDARegionSize {
let bytes = self.0 + MDA_REGION_HDR_SIZE;
let sectors = bytes.sectors();
MDARegionSize(if sectors.bytes() != bytes {
sectors + Sectors(1)
} else {
sectors
})
}
pub fn bytes(self) -> Bytes {
self.0
}
}
}
pub mod bda_size {
use devicemapper::Sectors;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct BDASize(Sectors);
impl BDASize {
pub fn new(value: Sectors) -> BDASize {
BDASize(value)
}
pub fn sectors(self) -> Sectors {
self.0
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct BDAExtendedSize(Sectors);
impl BDAExtendedSize {
pub fn new(value: Sectors) -> BDAExtendedSize {
BDAExtendedSize(value)
}
pub fn sectors(self) -> Sectors {
self.0
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ReservedSize(Sectors);
impl ReservedSize {
pub fn new(value: Sectors) -> ReservedSize {
ReservedSize(value)
}
pub fn sectors(self) -> Sectors {
self.0
}
}
}
pub mod blkdev_size {
use devicemapper::Sectors;
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct BlockdevSize(Sectors);
impl BlockdevSize {
pub fn new(value: Sectors) -> BlockdevSize {
BlockdevSize(value)
}
pub fn sectors(self) -> Sectors {
self.0
}
}
impl Default for BlockdevSize {
fn default() -> BlockdevSize {
BlockdevSize(Sectors(0))
}
}
}