1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum VhdxError {
5 #[error("not a VHDX file (bad magic)")]
6 BadMagic,
7 #[error("no valid VHDX header found")]
8 NoValidHeader,
9 #[error("region table not found or invalid")]
10 InvalidRegionTable,
11 #[error("BAT region not found in region table")]
12 BatRegionMissing,
13 #[error("metadata region not found in region table")]
14 MetadataRegionMissing,
15 #[error("required metadata item missing: {0}")]
16 MetadataMissing(&'static str),
17 #[error("metadata value is outside valid range: {0}")]
18 InvalidMetadata(&'static str),
19 #[error("container is too small to be a valid VHDX (minimum {0} bytes required)")]
20 ContainerTooSmall(u64),
21 #[error("region or BAT file offset is outside the container bounds")]
22 OffsetOutOfBounds,
23 #[error("BAT entry file offset calculation overflows u64")]
24 AddressOverflow,
25 #[error("sector out of range (sector {sector}, virtual disk size {size})")]
26 SectorOutOfRange { sector: u64, size: u64 },
27 #[error("BAT entry not present for sector {0}")]
28 BlockNotPresent(u64),
29 #[error("I/O error: {0}")]
30 Io(#[from] std::io::Error),
31 #[error("VHDX has a parent locator (differencing disk not supported)")]
32 DifferencingNotSupported,
33}
34
35pub type Result<T> = std::result::Result<T, VhdxError>;