mikros: Impl From<io::Error(Kind)> for Errno

This commit is contained in:
pjht 2024-10-04 10:03:24 -05:00
parent 59db13756e
commit 334a5698eb
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E
2 changed files with 91 additions and 19 deletions

View File

@ -134,6 +134,9 @@ pub enum Errno {
ERFKILL = 132,
EHWPOISON = 133,
EAGAIN = 134,
EEOF = 135,
EINVALDAT = 136,
EWRZERO = 137,
}
#[stable(feature = "mikros", since = "1.80.0")]
@ -275,6 +278,9 @@ fn try_from(value: i32) -> Result<Self, Self::Error> {
132 => Ok(ERFKILL),
133 => Ok(EHWPOISON),
134 => Ok(EAGAIN),
135 => Ok(EEOF),
136 => Ok(EINVALDAT),
137 => Ok(EWRZERO),
x => Err(x),
}
}
@ -417,7 +423,69 @@ fn fmt(&self, f: &mut crate::fmt::Formatter<'_>) -> Result<(), crate::fmt::Error
ENOTRECOVERABLE => "State not recoverable",
ERFKILL => "Operation not possible due to RF-kill",
EHWPOISON => "Memory page has hardware error",
EEOF => "Unexpected EOF",
EINVALDAT => "Invalid data",
EWRZERO => "Write zero",
};
f.write_str(errno_name)
}
}
#[stable(feature = "mikros", since = "1.80.0")]
impl From<crate::io::ErrorKind> for Errno {
fn from(kind: crate::io::ErrorKind) -> Self {
use Errno::*;
use crate::io::ErrorKind;
match kind {
ErrorKind::AddrInUse => EADDRINUSE,
ErrorKind::AddrNotAvailable => EADDRNOTAVAIL,
ErrorKind::AlreadyExists => EEXIST,
ErrorKind::ArgumentListTooLong => E2BIG,
ErrorKind::BrokenPipe => EPIPE,
ErrorKind::ConnectionAborted => ECONNABORTED,
ErrorKind::ConnectionRefused => ECONNREFUSED,
ErrorKind::ConnectionReset => ECONNRESET,
ErrorKind::CrossesDevices => EXDEV,
ErrorKind::Deadlock => EDEADLK,
ErrorKind::DirectoryNotEmpty => ENOTEMPTY,
ErrorKind::ExecutableFileBusy => ETXTBSY,
ErrorKind::FileTooLarge => EFBIG,
ErrorKind::FilesystemLoop => ELOOP,
ErrorKind::FilesystemQuotaExceeded => EDQUOT,
ErrorKind::HostUnreachable => EHOSTUNREACH,
//ErrorKind::InProgress => EINPROGRESS,
ErrorKind::Interrupted => EINTR,
ErrorKind::InvalidData => EINVALDAT,
ErrorKind::InvalidFilename => ENAMETOOLONG,
ErrorKind::InvalidInput => EINVAL,
ErrorKind::IsADirectory => EISDIR,
ErrorKind::NetworkDown => ENETDOWN,
ErrorKind::NetworkUnreachable => ENETUNREACH,
ErrorKind::NotADirectory => ENOTDIR,
ErrorKind::NotConnected => ENOTCONN,
ErrorKind::NotFound => ENOENT,
ErrorKind::NotSeekable => ESPIPE,
ErrorKind::OutOfMemory => ENOMEM,
ErrorKind::PermissionDenied => EPERM,
ErrorKind::ReadOnlyFilesystem => EROFS,
ErrorKind::ResourceBusy => EBUSY,
ErrorKind::StaleNetworkFileHandle => ESTALE,
ErrorKind::StorageFull => ENOSPC,
ErrorKind::TimedOut => ETIMEDOUT,
ErrorKind::TooManyLinks => EMLINK,
ErrorKind::UnexpectedEof => EEOF,
ErrorKind::Unsupported => ENOSYS,
ErrorKind::WouldBlock => EWOULDBLOCK,
ErrorKind::WriteZero => EWRZERO,
ErrorKind::Other | ErrorKind::Uncategorized => EIO,
}
}
}
#[stable(feature = "mikros", since = "1.80.0")]
impl From<crate::io::Error> for Errno {
fn from(error: crate::io::Error) -> Self {
Self::from(error.kind())
}
}

View File

@ -32,42 +32,46 @@ pub fn decode_error_kind(errno: RawOsError) -> crate::io::ErrorKind {
use crate::io::ErrorKind::*;
match errno {
Errno::E2BIG => ArgumentListTooLong,
Errno::EADDRINUSE => AddrInUse,
Errno::EADDRNOTAVAIL => AddrNotAvailable,
Errno::EBUSY => ResourceBusy,
Errno::EEXIST => AlreadyExists,
Errno::E2BIG => ArgumentListTooLong,
Errno::EPIPE => BrokenPipe,
Errno::ECONNABORTED => ConnectionAborted,
Errno::ECONNREFUSED => ConnectionRefused,
Errno::ECONNRESET => ConnectionReset,
Errno::EXDEV => CrossesDevices,
Errno::EDEADLK => Deadlock,
Errno::EDQUOT => FilesystemQuotaExceeded,
Errno::EEXIST => AlreadyExists,
Errno::ENOTEMPTY => DirectoryNotEmpty,
Errno::ETXTBSY => ExecutableFileBusy,
Errno::EFBIG => FileTooLarge,
Errno::ELOOP => FilesystemLoop,
Errno::EDQUOT => FilesystemQuotaExceeded,
Errno::EHOSTUNREACH => HostUnreachable,
//Errno::EINPROGRESS => InProgress,
Errno::EINTR => Interrupted,
Errno::EINVALDAT => InvalidData,
Errno::ENAMETOOLONG => InvalidFilename,
Errno::EINVAL => InvalidInput,
Errno::EISDIR => IsADirectory,
Errno::ELOOP => FilesystemLoop,
Errno::ENOENT => NotFound,
Errno::ENOMEM => OutOfMemory,
Errno::ENOSPC => StorageFull,
Errno::ENOSYS => Unsupported,
Errno::EMLINK => TooManyLinks,
Errno::ENAMETOOLONG => InvalidFilename,
Errno::ENETDOWN => NetworkDown,
Errno::ENETUNREACH => NetworkUnreachable,
Errno::ENOTCONN => NotConnected,
Errno::ENOTDIR => NotADirectory,
Errno::ENOTEMPTY => DirectoryNotEmpty,
Errno::EPIPE => BrokenPipe,
Errno::EROFS => ReadOnlyFilesystem,
Errno::ENOTCONN => NotConnected,
Errno::ENOENT => NotFound,
Errno::ESPIPE => NotSeekable,
Errno::ESTALE => StaleNetworkFileHandle,
Errno::ETIMEDOUT => TimedOut,
Errno::ETXTBSY => ExecutableFileBusy,
Errno::EXDEV => CrossesDevices,
Errno::ENOMEM => OutOfMemory,
Errno::EACCES | Errno::EPERM => PermissionDenied,
Errno::EROFS => ReadOnlyFilesystem,
Errno::EBUSY => ResourceBusy,
Errno::ESTALE => StaleNetworkFileHandle,
Errno::ENOSPC => StorageFull,
Errno::ETIMEDOUT => TimedOut,
Errno::EMLINK => TooManyLinks,
Errno::EEOF => UnexpectedEof,
Errno::ENOSYS => Unsupported,
Errno::EAGAIN | Errno::EWOULDBLOCK => WouldBlock,
Errno::EWRZERO => WriteZero,
_ => Uncategorized,
}
}