1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum NtfsReaderError {
5 #[error("elevation error")]
6 ElevationError,
7 #[error("io error")]
8 IOError(#[from] std::io::Error),
9 #[error("binread error")]
10 BinReadError(#[from] binread::error::Error),
11 #[error("windows error")]
12 WindowsError(#[from] WindowsErrorWrapper),
13 #[error("missing required MFT attribute: {0}")]
14 MissingMftAttribute(String),
15 #[error("corrupt MFT record {number}")]
16 CorruptMftRecord { number: u64 },
17 #[error("invalid MFT record at byte position {position}")]
18 InvalidMftRecord { position: u64 },
19 #[error("corrupt MFT record at byte position {position}")]
20 CorruptMft { position: u64 },
21 #[error("invalid NTFS data run: {details}")]
22 InvalidDataRun { details: &'static str },
23 #[error("unknown")]
24 Unknown,
25}
26
27#[derive(Debug)]
28pub struct WindowsErrorWrapper(windows::core::Error);
29impl WindowsErrorWrapper {
30 pub fn from_thread() -> WindowsErrorWrapper {
31 WindowsErrorWrapper(windows::core::Error::from_thread())
32 }
33}
34
35impl std::fmt::Display for WindowsErrorWrapper {
36 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37 write!(f, "Windows error: {}", self.0)
38 }
39}
40impl std::error::Error for WindowsErrorWrapper {}
41
42pub type NtfsReaderResult<T> = core::result::Result<T, NtfsReaderError>;