1use std::path::PathBuf;
2
3#[derive(Debug, thiserror::Error)]
5pub enum ReadError {
6 #[error("file at path {0} not found")]
7 NotFound(PathBuf),
8 #[error("could not read {2} bytes of superblock from {0} at offset {1}")]
9 CouldNotReadSuperBlock(PathBuf, u64, usize),
10 #[error("not a valid ext4 superblock")]
11 InvalidSuperBlock,
12 #[error("deep extents (depth > 1) are not supported")]
13 DeepExtentsUnsupported,
14 #[error("extents invalid or corrupted")]
15 InvalidExtents,
16 #[error("invalid extended attribute entry")]
17 InvalidXattrEntry,
18 #[error("could not read block {0}")]
19 CouldNotReadBlock(u32),
20 #[error("could not read inode {0}")]
21 CouldNotReadInode(u32),
22 #[error("could not read group descriptor {0}")]
23 CouldNotReadGroup(u32),
24 #[error("no such file or directory: {0}")]
25 PathNotFound(String),
26 #[error("not a regular file: {0}")]
27 NotAFile(String),
28 #[error("is a directory: {0}")]
29 IsDirectory(String),
30 #[error("not a directory: {0}")]
31 NotADirectory(String),
32 #[error("symlink loop while resolving: {0}")]
33 SymlinkLoop(String),
34 #[error("invalid path: {0}")]
35 InvalidPath(String),
36 #[error(transparent)]
37 Io(#[from] std::io::Error),
38}
39
40#[derive(Debug, thiserror::Error)]
42pub enum FormatError {
43 #[error("{0} is not a directory")]
44 NotDirectory(PathBuf),
45 #[error("{0} is not a file")]
46 NotFile(PathBuf),
47 #[error("{0} not found")]
48 NotFound(PathBuf),
49 #[error("{0} already exists")]
50 AlreadyExists(PathBuf),
51 #[error("file type not supported")]
52 UnsupportedFiletype,
53 #[error("maximum links exceeded for path: {0}")]
54 MaximumLinksExceeded(PathBuf),
55 #[error("{0} exceeds max file size (128 GiB)")]
56 FileTooBig(u64),
57 #[error("'{0}' is an invalid link")]
58 InvalidLink(PathBuf),
59 #[error("'{0}' is an invalid name")]
60 InvalidName(String),
61 #[error("not enough space for trailing directory entry")]
62 NoSpaceForTrailingDirEntry,
63 #[error("not enough space for group descriptor blocks")]
64 InsufficientSpaceForGroupDescriptorBlocks,
65 #[error("cannot create hard links to directory target: {0}")]
66 CannotHardlinkDirectory(PathBuf),
67 #[error("unsupported block size {0} (only 4096 is supported)")]
68 UnsupportedBlockSize(u32),
69 #[error("cannot truncate file: {0}")]
70 CannotTruncateFile(PathBuf),
71 #[error("cannot create sparse file at {0}")]
72 CannotCreateSparseFile(PathBuf),
73 #[error("cannot resize fs to {0} bytes")]
74 CannotResizeFs(u64),
75 #[error("cannot fit xattr for inode {0}")]
76 XattrInsufficientSpace(u32),
77 #[error("malformed extended attribute buffer")]
78 MalformedXattrBuffer,
79 #[error("cannot convert string '{0}' to ASCII")]
80 InvalidAsciiString(String),
81 #[error("circular hard links found")]
82 CircularLinks,
83 #[error("invalid path encoding for '{0}', must be ascii or utf8")]
84 InvalidPathEncoding(String),
85 #[error(transparent)]
86 Io(#[from] std::io::Error),
87}
88
89pub type ReadResult<T> = std::result::Result<T, ReadError>;
90pub type FormatResult<T> = std::result::Result<T, FormatError>;