use crate::binrw_util;
use alloc::vec::Vec;
use binrw::binrw;
#[binrw]
#[derive(Clone, Debug)]
pub struct DiskStatus {
#[br(map = binrw_util::map_u4)]
#[bw(map = binrw_util::unmap_u4)]
pub tow: Option<u32>,
#[br(map = binrw_util::map_u2)]
#[bw(map = binrw_util::unmap_u2)]
pub wnc: Option<u16>,
pub n: u8,
pub sb_length: u8,
pub reserved: [u8; 4],
#[br(args { count: usize::from(n), inner: (usize::from(sb_length),) }, map = binrw_util::unwrap_subblocks)]
#[bw(args_raw = (usize::from(*sb_length),), map = binrw_util::wrap_subblocks)]
pub disks: Vec<DiskData>,
}
#[binrw]
#[derive(Clone, Debug)]
pub struct DiskData {
pub disk_id: u8,
pub status: u8,
#[br(map = binrw_util::map_u2)]
#[bw(map = binrw_util::unmap_u2)]
pub disk_usage_msb: Option<u16>,
#[br(map = binrw_util::map_u4)]
#[bw(map = binrw_util::unmap_u4)]
pub disk_usage_lsb: Option<u32>,
#[br(map = binrw_util::map_u4_zero)]
#[bw(map = binrw_util::unmap_u4_zero)]
pub disk_size: Option<u32>,
pub create_delete_count: u8,
#[br(map = binrw_util::map_u1)]
#[bw(map = binrw_util::unmap_u1)]
pub error: Option<u8>,
}
impl DiskData {
pub fn disk_usage_bytes(&self) -> Option<u64> {
match (self.disk_usage_msb, self.disk_usage_lsb) {
(Some(msb), Some(lsb)) => Some((u64::from(msb) << 32) | u64::from(lsb)),
_ => None,
}
}
pub fn mounted(&self) -> bool {
self.status & 1 != 0
}
pub fn full(&self) -> bool {
self.status & (1 << 1) != 0
}
pub fn logging_enabled(&self) -> bool {
self.status & (1 << 3) != 0
}
}