1use fuser_async::Error as ErrorFuse;
3
4use crate::superblock::Compression;
5
6pub(crate) type CacheError = fuser_async::cache::CacheError<Box<Error>>;
7
8#[derive(thiserror::Error, Debug)]
10pub enum Error {
11 #[error("Invalid buffer size")]
12 InvalidBufferSize,
13 #[error("Invalid superblock")]
14 InvalidSuperblock,
15 #[error("Read failure")]
16 ReadFailure(std::io::Error),
17 #[error("File not found: {0:?}")]
18 FileNotFound(Option<String>),
19 #[error("Directory not found")]
20 DirectoryNotFound,
21 #[error("Invalid file offset")]
22 InvalidOffset,
23 #[error("Cache error: {source}")]
24 CacheError {
25 #[from]
26 source: CacheError,
27 },
28 #[error("Readers pool error: {source}")]
29 PoolError {
30 #[from]
31 source: deadpool::managed::PoolError<std::io::Error>,
32 },
33 #[error("Readers pool creation error: {source}")]
34 PoolBuildError {
35 #[from]
36 source: deadpool::managed::BuildError<std::io::Error>,
37 },
38 #[error("Invalid options: {0}")]
39 InvalidOptions(&'static str),
40 #[error("Fragments error: {0}")]
41 Fragments(#[from] FragmentsError),
42 #[error("Inode table error: {0}")]
43 InodeTable(#[from] InodeTableError),
44 #[error("Directory table error: {0}")]
45 DirectoryTable(#[from] DirectoryTableError),
46 #[error("Metadata error: {0}")]
47 Metadata(#[from] MetadataError),
48 #[error("Decompression error: {0}")]
49 Decompress(#[from] DecompressError),
50 #[error("Unsupported encoding")]
51 Encoding,
52 #[error("Invalid inode")]
53 InvalidInode,
54 #[cfg(feature = "memmap")]
55 #[error("Failed to memory map file")]
56 MemMap,
57 #[error("{0}")]
58 Fuse(#[from] ErrorFuse),
59}
60
61impl From<Error> for ErrorFuse {
62 fn from(source: Error) -> Self {
63 match source {
64 Error::FileNotFound(_) | Error::DirectoryNotFound => Self::NoFileDir,
65 Error::InvalidInode | Error::InvalidOffset => Self::InvalidArgument,
66 Error::Encoding => Self::Unimplemented,
67 Error::Fuse(e) => e,
68 _ => Self::IO(source.to_string()),
69 }
70 }
71}
72
73#[derive(thiserror::Error, Debug)]
75pub enum DecompressError {
76 #[error("Failed to decompress data: {0}")]
77 Io(#[from] tokio::io::Error),
78 #[error("Unsupported compression {0:?}")]
79 UnsupportedCompression(Compression),
80}
81#[derive(thiserror::Error, Debug)]
83pub enum MetadataError {
84 #[error("Invalid header")]
85 InvalidHeader,
86 #[error("Invalid entry")]
87 InvalidEntry,
88 #[error("Invalid data length")]
89 InvalidDataLength,
90 #[error("Read failure")]
91 ReadFailure(std::io::Error),
92 #[error("Decompression error: {0}")]
93 Decompress(#[from] DecompressError),
94}
95#[derive(thiserror::Error, Debug)]
97pub enum InodeTableError {
98 #[error("Invalid header")]
99 InvalidHeader,
100 #[error("Invalid entry")]
101 InvalidEntry,
102 #[error("Invalid metadata: {0}")]
103 InvalidMetadata(#[from] MetadataError),
104 #[error("Read failure")]
105 ReadFailure(std::io::Error),
106}
107#[derive(thiserror::Error, Debug)]
109pub enum DirectoryTableError {
110 #[error("Invalid header")]
111 InvalidHeader,
112 #[error("Invalid entry")]
113 InvalidEntry,
114 #[error("Invalid metadata: {0}")]
115 InvalidMetadata(#[from] MetadataError),
116 #[error("Read failure")]
117 ReadFailure(std::io::Error),
118}
119#[derive(thiserror::Error, Debug)]
121pub enum FragmentsError {
122 #[error("Invalid location in fragment table")]
123 InvalidLocation,
124 #[error("Invalid metadata: {0}")]
125 InvalidMetadata(#[from] MetadataError),
126 #[error("Invalid fragment table entry")]
127 InvalidEntry,
128 #[error("Read failure")]
129 ReadFailure(std::io::Error),
130}