cat_dev/fsemul/pcfs/
errors.rs

1//! Errors related to various PCFS protocols.
2
3use miette::Diagnostic;
4use thiserror::Error;
5
6/// Error's specific to calling a specific PCFS API.
7#[derive(Diagnostic, Error, Debug, PartialEq, Eq)]
8pub enum PCFSApiError {
9	/// `PCFS` Sata protocol only supports [`u32::MAX`] packet sizes because they
10	/// store length of body as a [`u32`].
11	#[error("This packet body is too large to ever fit in a PCFS Sata Packet, is: 0x{0:02X?} bytes long, max is 0xFFFFFFFF!")]
12	#[diagnostic(code(cat_dev::api::fsemul::pcfs::packet_too_large_for_sata))]
13	PacketTooLargeForSata(usize),
14	/// Requested path is not inside of a mapped directory.
15	#[error("The requested path: [{0}] was not inside of a mapped directory, cannot serve.")]
16	#[diagnostic(code(cat_dev::api::fsemul::pcfs::path_not_mapped))]
17	PathNotMapped(String),
18}
19
20/// Error serializing/deserializing the PCFS Sata protocol.
21#[derive(Diagnostic, Error, Debug, PartialEq, Eq)]
22pub enum SataProtocolError {
23	#[error("Mode string is expected to match '(r|w|a)b?+?', but did not! invalid mode: {0}")]
24	#[diagnostic(code(cat_dev::net::parse::pcfs::sata::bad_mode_string))]
25	BadModeString(String),
26	/// PCFS sata headers should always end with 8 NUL bytes for padding.
27	#[error(
28		"Packet header for PCFS should end with 8 bytes of padding (all 0x0), but was: [{0:02X?}]!"
29	)]
30	#[diagnostic(code(cat_dev::net::parse::pcfs::sata::header_bad_padding))]
31	HeaderBadPadding([u8; 8]),
32	/// SATA packets have fields that only the host pc is supposed to set.
33	///
34	/// One of these fields was set by the client instead of the host pc.
35	#[error(
36		"Packet header has fields that only the host should ever populate, but they were populated by the non-host: (timestamp: {0:02X}) / (pid: {1:02X}). This is a malformed packet from this device."
37	)]
38	#[diagnostic(code(cat_dev::net::parse::pcfs::sata::header_non_host_set_host_fields))]
39	NonHostSetHostOnlyHeaderFields(u32, u32),
40	/// Unknown type of packet received on PCFS Sata.
41	#[error("Unknown type of packet for PCFS Sata: {0:02X}!")]
42	#[diagnostic(code(cat_dev::net::parse::pcfs::sata::unknown_type))]
43	UnknownPacketType(u32),
44	/// Unknown type of query for getting a files information.
45	#[error("Unknown query type for GetInfo operation: {0}")]
46	#[diagnostic(code(cat_dev::net::parse::pcfs::sata::unknown_get_info_query_type))]
47	UnknownGetInfoQueryType(u32),
48	#[error("Unknown file location to move too: {0}")]
49	#[diagnostic(code(cat_dev::net::parse::pcfs::sata::unknown_file_location))]
50	UnknownFileLocation(u32),
51}