1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2pub enum FsError {
3 NotFound,
4 NotADirectory,
5 IsADirectory,
6 InvalidArgument,
7 BadFileDescriptor,
8 PermissionDenied,
9 AlreadyExists,
10 NotEmpty,
11}
12
13impl FsError {
14 pub fn to_errno(&self) -> i32 {
16 match self {
17 FsError::NotFound => -2, FsError::NotADirectory => -20, FsError::IsADirectory => -21, FsError::InvalidArgument => -22, FsError::BadFileDescriptor => -9, FsError::PermissionDenied => -13, FsError::AlreadyExists => -17, FsError::NotEmpty => -39, }
26 }
27
28 pub fn to_wasi_error_code(&self) -> u8 {
32 match self {
33 FsError::NotFound => 44, FsError::NotADirectory => 54, FsError::IsADirectory => 31, FsError::InvalidArgument => 28, FsError::BadFileDescriptor => 8, FsError::PermissionDenied => 2, FsError::AlreadyExists => 20, FsError::NotEmpty => 55, }
42 }
43}