1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum FsError {
10 NotFound, AlreadyExists, NotDirectory, IsDirectory, DirectoryNotEmpty, PermissionDenied, BadFileDescriptor, TooManyOpenFiles, InvalidArgument, NameTooLong, ReadOnlyFs, NoSpace, IoError, NoDevice, BrokenPipe, WouldBlock, NotConnected, NotSupported, TooManyLinks, }
45
46impl FsError {
47 pub fn to_errno(&self) -> isize {
49 match self {
50 FsError::NotFound => -2,
51 FsError::IoError => -5,
52 FsError::BadFileDescriptor => -9,
53 FsError::WouldBlock => -11,
54 FsError::PermissionDenied => -13,
55 FsError::AlreadyExists => -17,
56 FsError::NoDevice => -19,
57 FsError::NotDirectory => -20,
58 FsError::IsDirectory => -21,
59 FsError::InvalidArgument => -22,
60 FsError::TooManyOpenFiles => -24,
61 FsError::NoSpace => -28,
62 FsError::ReadOnlyFs => -30,
63 FsError::TooManyLinks => -31,
64 FsError::BrokenPipe => -32,
65 FsError::NameTooLong => -36,
66 FsError::DirectoryNotEmpty => -39,
67 FsError::NotSupported => -95,
68 FsError::NotConnected => -107,
69 }
70 }
71}
72
73#[cfg(test)]
74mod tests {
75 use crate::{kassert, test_case};
76
77 use super::*;
78
79 test_case!(test_error_codes, {
80 kassert!(FsError::NotFound.to_errno() == -2);
81 kassert!(FsError::PermissionDenied.to_errno() == -13);
82 kassert!(FsError::AlreadyExists.to_errno() == -17);
83 });
84}