1#[non_exhaustive]
5#[derive(Debug, thiserror::Error)]
6pub enum Error {
7 #[error("{op}: {}", describe_ext2fs_error(*.code))]
9 Ext2fs {
10 op: &'static str,
12 code: i64,
14 },
15
16 #[error("invalid path: {0}")]
18 InvalidPath(String),
19
20 #[error(transparent)]
22 Io(#[from] std::io::Error),
23}
24
25pub type Result<T> = std::result::Result<T, Error>;
27
28fn describe_ext2fs_error(code: i64) -> String {
32 const BASE: i64 = 2_133_571_328;
34 match code - BASE {
35 1 => "bad magic number in superblock".into(),
36 2 => "filesystem revision too high".into(),
37 4 => "illegal block number".into(),
38 5 => "illegal inode number".into(),
39 6 => "internal error in ext2fs_open_icount".into(),
40 7 => "cannot write to an fs opened read-only".into(),
41 8 => "block bitmap not loaded".into(),
42 9 => "inode bitmap not loaded".into(),
43 10 => "no free blocks".into(),
44 11 => "no free inodes".into(),
45 12 => "directory block not found".into(),
46 16 => "inode already allocated".into(),
47 17 => "block already allocated".into(),
48 22 => "filesystem not open".into(),
49 23 => "device is read-only".into(),
50 24 => "directory corrupted".into(),
51 25 => "short read".into(),
52 26 => "short write".into(),
53 28 => "filesystem too large".into(),
54 _ => format!("libext2fs error {code:#x}"),
55 }
56}