Files
obsw/mission_rust/src/fsrc/osal/error/linux.rs
T
2025-10-24 14:23:35 +02:00

426 lines
21 KiB
Rust

use core::fmt;
mod libc {
// taken from a glibc x86_64 linux:
use core::ffi::c_int;
pub const EPERM: c_int = 1;
pub const ENOENT: c_int = 2;
pub const ESRCH: c_int = 3;
pub const EINTR: c_int = 4;
pub const EIO: c_int = 5;
pub const ENXIO: c_int = 6;
pub const E2BIG: c_int = 7;
pub const ENOEXEC: c_int = 8;
pub const EBADF: c_int = 9;
pub const ECHILD: c_int = 10;
pub const EAGAIN: c_int = 11;
#[allow(unused)]
pub const EWOULDBLOCK: c_int = 11; // equals EAGAIN
pub const ENOMEM: c_int = 12;
pub const EACCES: c_int = 13;
pub const EFAULT: c_int = 14;
pub const ENOTBLK: c_int = 15;
pub const EBUSY: c_int = 16;
pub const EEXIST: c_int = 17;
pub const EXDEV: c_int = 18;
pub const ENODEV: c_int = 19;
pub const ENOTDIR: c_int = 20;
pub const EISDIR: c_int = 21;
pub const EINVAL: c_int = 22;
pub const ENFILE: c_int = 23;
pub const EMFILE: c_int = 24;
pub const ENOTTY: c_int = 25;
pub const ETXTBSY: c_int = 26;
pub const EFBIG: c_int = 27;
pub const ENOSPC: c_int = 28;
pub const ESPIPE: c_int = 29;
pub const EROFS: c_int = 30;
pub const EMLINK: c_int = 31;
pub const EPIPE: c_int = 32;
pub const EDOM: c_int = 33;
pub const ERANGE: c_int = 34;
pub const EDEADLOCK: c_int = 35;
pub const ENAMETOOLONG: c_int = 36;
pub const ENOLCK: c_int = 37;
pub const ENOSYS: c_int = 38;
pub const ENOTEMPTY: c_int = 39;
pub const ELOOP: c_int = 40;
pub const ENOMSG: c_int = 42;
pub const EIDRM: c_int = 43;
pub const ECHRNG: c_int = 44;
pub const ELNRNG: c_int = 48;
pub const EUNATCH: c_int = 49;
pub const ENOCSI: c_int = 50;
pub const EBADE: c_int = 52;
pub const EBADR: c_int = 53;
pub const EXFULL: c_int = 54;
pub const ENOANO: c_int = 55;
pub const EBADRQC: c_int = 56;
pub const EBADSLT: c_int = 57;
pub const EBFONT: c_int = 59;
pub const ENOSTR: c_int = 60;
pub const ENODATA: c_int = 61;
pub const ETIME: c_int = 62;
pub const ENOSR: c_int = 63;
pub const ENONET: c_int = 64;
pub const ENOPKG: c_int = 65;
pub const EREMOTE: c_int = 66;
pub const ENOLINK: c_int = 67;
pub const EADV: c_int = 68;
pub const ESRMNT: c_int = 69;
pub const ECOMM: c_int = 70;
pub const EPROTO: c_int = 71;
pub const EMULTIHOP: c_int = 72;
pub const EDOTDOT: c_int = 73;
pub const EBADMSG: c_int = 74;
pub const EOVERFLOW: c_int = 75;
pub const ENOTUNIQ: c_int = 76;
pub const EBADFD: c_int = 77;
pub const EREMCHG: c_int = 78;
pub const ELIBACC: c_int = 79;
pub const ELIBBAD: c_int = 80;
pub const ELIBSCN: c_int = 81;
pub const ELIBMAX: c_int = 82;
pub const ELIBEXEC: c_int = 83;
pub const EILSEQ: c_int = 84;
pub const ERESTART: c_int = 85;
pub const ESTRPIPE: c_int = 86;
pub const EUSERS: c_int = 87;
pub const ENOTSOCK: c_int = 88;
pub const EDESTADDRREQ: c_int = 89;
pub const EMSGSIZE: c_int = 90;
pub const EPROTOTYPE: c_int = 91;
pub const ENOPROTOOPT: c_int = 92;
pub const EPROTONOSUPPORT: c_int = 93;
pub const ESOCKTNOSUPPORT: c_int = 94;
pub const EOPNOTSUPP: c_int = 95;
#[allow(unused)]
pub const ENOTSUP: c_int = 95; // equals EOPNOTSUPP
pub const EPFNOSUPPORT: c_int = 96;
pub const EAFNOSUPPORT: c_int = 97;
pub const EADDRINUSE: c_int = 98;
pub const EADDRNOTAVAIL: c_int = 99;
pub const ENETDOWN: c_int = 100;
pub const ENETUNREACH: c_int = 101;
pub const ENETRESET: c_int = 102;
pub const ECONNABORTED: c_int = 103;
pub const ECONNRESET: c_int = 104;
pub const ENOBUFS: c_int = 105;
pub const EISCONN: c_int = 106;
pub const ENOTCONN: c_int = 107;
pub const ESHUTDOWN: c_int = 108;
pub const ETOOMANYREFS: c_int = 109;
pub const ETIMEDOUT: c_int = 110;
pub const ECONNREFUSED: c_int = 111;
pub const EHOSTDOWN: c_int = 112;
pub const EHOSTUNREACH: c_int = 113;
pub const EALREADY: c_int = 114;
pub const EINPROGRESS: c_int = 115;
pub const ESTALE: c_int = 116;
pub const EUCLEAN: c_int = 117;
pub const ENOTNAM: c_int = 118;
pub const ENAVAIL: c_int = 119;
pub const EISNAM: c_int = 120;
pub const EREMOTEIO: c_int = 121;
pub const EDQUOT: c_int = 122;
pub const ENOMEDIUM: c_int = 123;
pub const EMEDIUMTYPE: c_int = 124;
pub const ECANCELED: c_int = 125;
pub const ENOKEY: c_int = 126;
pub const EKEYEXPIRED: c_int = 127;
pub const EKEYREVOKED: c_int = 128;
pub const EKEYREJECTED: c_int = 129;
pub const EOWNERDEAD: c_int = 130;
pub const ENOTRECOVERABLE: c_int = 131;
pub const ERFKILL: c_int = 132;
pub const EHWPOISON: c_int = 133;
}
impl From<i32> for super::OsError {
fn from(value: i32) -> Self {
use super::OsError::*;
match value {
libc::EPERM => OperationNotPermitted,
libc::ENOENT => NoSuchFileOrDirectory,
libc::ESRCH => NoSuchProcess,
libc::EINTR => InterruptedSystemCall,
libc::EIO => InputOutputError,
libc::ENXIO => NoSuchDeviceOrAddress,
libc::E2BIG => ArgumentListTooLong,
libc::ENOEXEC => ExecFormatError,
libc::EBADF => BadFileDescriptor,
libc::ECHILD => NoChildProcesses,
libc::EAGAIN => OperationWouldBlock,
//libc::EWOULDBLOCK => OperationWouldBlock, == EAGAIN
libc::ENOMEM => CannotAllocateMemory,
libc::EACCES => PermissionDenied,
libc::EFAULT => BadAddress,
libc::ENOTBLK => BlockDeviceRequired,
libc::EBUSY => DeviceOrResourceBusy,
libc::EEXIST => FileExists,
libc::EXDEV => InvalidCrossDeviceLink,
libc::ENODEV => NoSuchDevice,
libc::ENOTDIR => NotADirectory,
libc::EISDIR => IsADirectory,
libc::EINVAL => InvalidArgument,
libc::ENFILE => TooManyOpenFilesInSystem,
libc::EMFILE => TooManyOpenFiles,
libc::ENOTTY => NotACharacterDevice,
libc::ETXTBSY => TextFileBusy,
libc::EFBIG => FileTooLarge,
libc::ENOSPC => NoSpaceLeftOnDevice,
libc::ESPIPE => IllegalSeek,
libc::EROFS => ReadOnlyFileSystem,
libc::EMLINK => TooManyLinks,
libc::EPIPE => BrokenPipe,
libc::EDOM => NumericalArgumentOutOfDomain,
libc::ERANGE => NumericalResultOutOfRange,
libc::EDEADLOCK => Deadlock,
libc::ENAMETOOLONG => FileNameTooLong,
libc::ENOLCK => NoLocksAvailable,
libc::ENOSYS => FunctionNotImplemented,
libc::ENOTEMPTY => DirectoryNotEmpty,
libc::ELOOP => TooManySymbolicLinks,
libc::ENOMSG => NoMessageOfDesiredType,
libc::EIDRM => IdentifierRemoved,
libc::ECHRNG => ChannelNumberOutOfRange,
libc::ELNRNG => LinkNumberOutOfRange,
libc::EUNATCH => ProtocolDriverNotAttached,
libc::ENOCSI => NoCsiStructureAvailable,
libc::EBADE => InvalidExchange,
libc::EBADR => InvalidRequestDescriptor,
libc::EXFULL => ExchangeFull,
libc::ENOANO => NoAnode,
libc::EBADRQC => InvalidRequestCode,
libc::EBADSLT => InvalidSlot,
libc::EBFONT => BadFontFileFormat,
libc::ENOSTR => DeviceNotAStream,
libc::ENODATA => NoDataAvailable,
libc::ETIME => TimerExpired,
libc::ENOSR => OutOfStreamsResources,
libc::ENONET => MachineIsNotOnTheNetwork,
libc::ENOPKG => PackageNotInstalled,
libc::EREMOTE => ObjectIsRemote,
libc::ENOLINK => LinkHasBeenSevered,
libc::EADV => AdvertiseError,
libc::ESRMNT => SrmountError,
libc::ECOMM => CommunicationErrorOnSend,
libc::EPROTO => ProtocolError,
libc::EMULTIHOP => MultihopAttempted,
libc::EDOTDOT => FsError,
libc::EBADMSG => BadMessage,
libc::EOVERFLOW => ValueTooLargeForDefinedDataType,
libc::ENOTUNIQ => NameNotUniqueOnNetwork,
libc::EBADFD => FileDescriptorInBadState,
libc::EREMCHG => RemoteAddressChanged,
libc::ELIBACC => CanNotAccessANeededSharedLibrary,
libc::ELIBBAD => AccessingACorruptedSharedLibrary,
libc::ELIBSCN => LibSectionInAOutCorrupted,
libc::ELIBMAX => AttemptingToLinkInTooManySharedLibraries,
libc::ELIBEXEC => CannotExecASharedLibraryDirectly,
libc::EILSEQ => InvalidOrIncompleteMultibyteOrWideCharacter,
libc::ERESTART => InterruptedSystemCallShouldBeRestarted,
libc::ESTRPIPE => StreamsPipeError,
libc::EUSERS => TooManyUsers,
libc::ENOTSOCK => SocketOperationOnNonSocket,
libc::EDESTADDRREQ => DestinationAddressRequired,
libc::EMSGSIZE => MessageTooLong,
libc::EPROTOTYPE => ProtocolWrongTypeForSocket,
libc::ENOPROTOOPT => ProtocolNotAvailable,
libc::EPROTONOSUPPORT => ProtocolNotSupported,
libc::ESOCKTNOSUPPORT => SocketTypeNotSupported,
libc::EOPNOTSUPP => OperationNotSupported,
// libc::ENOTSUP => OperationNotSupported, == EOPNOTSUPP
libc::EPFNOSUPPORT => ProtocolFamilyNotSupported,
libc::EAFNOSUPPORT => AddressFamilyNotSupportedByProtocol,
libc::EADDRINUSE => AddressAlreadyInUse,
libc::EADDRNOTAVAIL => AddressNotAvailable,
libc::ENETDOWN => NetworkIsDown,
libc::ENETUNREACH => HostIsUnreachable,
libc::ENETRESET => NetworkDroppedConnectionOnReset,
libc::ECONNABORTED => SoftwareCausedConnectionAbort,
libc::ECONNRESET => ConnectionResetByPeer,
libc::ENOBUFS => NoBufferSpaceAvailable,
libc::EISCONN => TransportEndpointIsAlreadyConnected,
libc::ENOTCONN => TransportEndpointIsNotConnected,
libc::ESHUTDOWN => CannotSendAfterShutdown,
libc::ETOOMANYREFS => TooManyReferencesCannotSplice,
libc::ETIMEDOUT => ConnectionTimedOut,
libc::ECONNREFUSED => ConnectionRefused,
libc::EHOSTDOWN => HostIsDown,
libc::EHOSTUNREACH => NoRouteToHost,
libc::EALREADY => OperationAlreadyInProgress,
libc::EINPROGRESS => OperationNowInProgress,
libc::ESTALE => StaleFileHandle,
libc::EUCLEAN => StructureNeedsCleaning,
libc::ENOTNAM => NotAXenixNamedTypeFile,
libc::ENAVAIL => NoXenixSemaphoresAvailable,
libc::EISNAM => IsANamedTypeFile,
libc::EREMOTEIO => RemoteIOError,
libc::EDQUOT => DiskQuotaExceeded,
libc::ENOMEDIUM => NoMediumFound,
libc::EMEDIUMTYPE => WrongMediumType,
libc::ECANCELED => OperationCanceled,
libc::ENOKEY => RequiredKeyNotAvailable,
libc::EKEYEXPIRED => KeyHasExpired,
libc::EKEYREVOKED => KeyHasBeenRevoked,
libc::EKEYREJECTED => KeyWasRejectedByService,
libc::EOWNERDEAD => OwnerDied,
libc::ENOTRECOVERABLE => StateNotRecoverable,
libc::ERFKILL => OperationNotPossibleDueToRfKill,
libc::EHWPOISON => MemoryPageHasHardwareError,
value => Other(value),
}
}
}
impl fmt::Display for super::OsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use super::OsError::*;
match self {
OperationNotPermitted => write!(f, "Operation not permitted"),
NoSuchFileOrDirectory => write!(f, "No such file or directory"),
NoSuchProcess => write!(f, "No such process"),
InterruptedSystemCall => write!(f, "Interrupted system call"),
InputOutputError => write!(f, "Input/output error"),
NoSuchDeviceOrAddress => write!(f, "No such device or address"),
ArgumentListTooLong => write!(f, "Argument list too long"),
ExecFormatError => write!(f, "Exec format error"),
BadFileDescriptor => write!(f, "Bad file descriptor"),
NoChildProcesses => write!(f, "No child processes"),
OperationWouldBlock => write!(f, "Resource temporarily unavailable"),
CannotAllocateMemory => write!(f, "Cannot allocate memory"),
PermissionDenied => write!(f, "Permission denied"),
BadAddress => write!(f, "Bad address"),
BlockDeviceRequired => write!(f, "Block device required"),
DeviceOrResourceBusy => write!(f, "Device or resource busy"),
FileExists => write!(f, "File exists"),
InvalidCrossDeviceLink => write!(f, "Invalid cross-device link"),
NoSuchDevice => write!(f, "No such device"),
NotADirectory => write!(f, "Not a directory"),
IsADirectory => write!(f, "Is a directory"),
InvalidArgument => write!(f, "Invalid argument"),
TooManyOpenFilesInSystem => write!(f, "Too many open files in system"),
TooManyOpenFiles => write!(f, "Too many open files"),
NotACharacterDevice => write!(f, "Inappropriate ioctl for device"),
TextFileBusy => write!(f, "Text file busy"),
FileTooLarge => write!(f, "File too large"),
NoSpaceLeftOnDevice => write!(f, "No space left on device"),
IllegalSeek => write!(f, "Illegal seek"),
ReadOnlyFileSystem => write!(f, "Read-only file system"),
TooManyLinks => write!(f, "Too many links"),
BrokenPipe => write!(f, "Broken pipe"),
NumericalArgumentOutOfDomain => write!(f, "Numerical argument out of domain"),
NumericalResultOutOfRange => write!(f, "Numerical result out of range"),
Deadlock => write!(f, "Resource deadlock avoided"),
FileNameTooLong => write!(f, "File name too long"),
NoLocksAvailable => write!(f, "No locks available"),
FunctionNotImplemented => write!(f, "Function not implemented"),
DirectoryNotEmpty => write!(f, "Directory not empty"),
TooManySymbolicLinks => write!(f, "Too many levels of symbolic links"),
NoMessageOfDesiredType => write!(f, "No message of desired type"),
IdentifierRemoved => write!(f, "Identifier removed"),
ChannelNumberOutOfRange => write!(f, "Channel number out of range"),
LinkNumberOutOfRange => write!(f, "Link number out of range"),
ProtocolDriverNotAttached => write!(f, "Protocol driver not attached"),
NoCsiStructureAvailable => write!(f, "No CSI structure available"),
InvalidExchange => write!(f, "Invalid exchange"),
InvalidRequestDescriptor => write!(f, "Invalid request descriptor"),
ExchangeFull => write!(f, "Exchange full"),
NoAnode => write!(f, "No anode"),
InvalidRequestCode => write!(f, "Invalid request code"),
InvalidSlot => write!(f, "Invalid slot"),
BadFontFileFormat => write!(f, "Bad font file format"),
DeviceNotAStream => write!(f, "Device not a stream"),
NoDataAvailable => write!(f, "No data available"),
TimerExpired => write!(f, "Timer expired"),
OutOfStreamsResources => write!(f, "Out of streams resources"),
MachineIsNotOnTheNetwork => write!(f, "Machine is not on the network"),
PackageNotInstalled => write!(f, "Package not installed"),
ObjectIsRemote => write!(f, "Object is remote"),
LinkHasBeenSevered => write!(f, "Link has been severed"),
AdvertiseError => write!(f, "Advertise error"),
SrmountError => write!(f, "Srmount error"),
CommunicationErrorOnSend => write!(f, "Communication error on send"),
ProtocolError => write!(f, "Protocol error"),
MultihopAttempted => write!(f, "Multihop attempted"),
FsError => write!(f, "RFS specific error"),
BadMessage => write!(f, "Bad message"),
ValueTooLargeForDefinedDataType => write!(f, "Value too large for defined data type"),
NameNotUniqueOnNetwork => write!(f, "Name not unique on network"),
FileDescriptorInBadState => write!(f, "File descriptor in bad state"),
RemoteAddressChanged => write!(f, "Remote address changed"),
CanNotAccessANeededSharedLibrary => write!(f, "Can not access a needed shared library"),
AccessingACorruptedSharedLibrary => write!(f, "Accessing a corrupted shared library"),
LibSectionInAOutCorrupted => write!(f, ".lib section in a.out corrupted"),
AttemptingToLinkInTooManySharedLibraries => {
write!(f, "Attempting to link in too many shared libraries")
}
CannotExecASharedLibraryDirectly => write!(f, "Cannot exec a shared library directly"),
InvalidOrIncompleteMultibyteOrWideCharacter => {
write!(f, "Invalid or incomplete multibyte or wide character")
}
InterruptedSystemCallShouldBeRestarted => {
write!(f, "Interrupted system call should be restarted")
}
StreamsPipeError => write!(f, "Streams pipe error"),
TooManyUsers => write!(f, "Too many users"),
SocketOperationOnNonSocket => write!(f, "Socket operation on non-socket"),
DestinationAddressRequired => write!(f, "Destination address required"),
MessageTooLong => write!(f, "Message too long"),
ProtocolWrongTypeForSocket => write!(f, "Protocol wrong type for socket"),
ProtocolNotAvailable => write!(f, "Protocol not available"),
ProtocolNotSupported => write!(f, "Protocol not supported"),
SocketTypeNotSupported => write!(f, "Socket type not supported"),
OperationNotSupported => write!(f, "Operation not supported"),
ProtocolFamilyNotSupported => write!(f, "Protocol family not supported"),
AddressFamilyNotSupportedByProtocol => {
write!(f, "Address family not supported by protocol")
}
AddressAlreadyInUse => write!(f, "Address already in use"),
AddressNotAvailable => write!(f, "Cannot assign requested address"),
NetworkIsDown => write!(f, "Network is down"),
HostIsUnreachable => write!(f, "Network is unreachable"),
NetworkDroppedConnectionOnReset => write!(f, "Network dropped connection on reset"),
SoftwareCausedConnectionAbort => write!(f, "Software caused connection abort"),
ConnectionResetByPeer => write!(f, "Connection reset by peer"),
NoBufferSpaceAvailable => write!(f, "No buffer space available"),
TransportEndpointIsAlreadyConnected => {
write!(f, "Transport endpoint is already connected")
}
TransportEndpointIsNotConnected => write!(f, "Transport endpoint is not connected"),
CannotSendAfterShutdown => {
write!(f, "Cannot send after transport endpoint shutdown")
}
TooManyReferencesCannotSplice => write!(f, "Too many references: cannot splice"),
ConnectionTimedOut => write!(f, "Connection timed out"),
ConnectionRefused => write!(f, "Connection refused"),
HostIsDown => write!(f, "Host is down"),
NoRouteToHost => write!(f, "No route to host"),
OperationAlreadyInProgress => write!(f, "Operation already in progress"),
OperationNowInProgress => write!(f, "Operation now in progress"),
StaleFileHandle => write!(f, "Stale file handle"),
StructureNeedsCleaning => write!(f, "Structure needs cleaning"),
NotAXenixNamedTypeFile => write!(f, "Not a XENIX named type file"),
NoXenixSemaphoresAvailable => write!(f, "No XENIX semaphores available"),
IsANamedTypeFile => write!(f, "Is a named type file"),
RemoteIOError => write!(f, "Remote I/O error"),
DiskQuotaExceeded => write!(f, "Disk quota exceeded"),
NoMediumFound => write!(f, "No medium found"),
WrongMediumType => write!(f, "Wrong medium type"),
OperationCanceled => write!(f, "Operation canceled"),
RequiredKeyNotAvailable => write!(f, "Required key not available"),
KeyHasExpired => write!(f, "Key has expired"),
KeyHasBeenRevoked => write!(f, "Key has been revoked"),
KeyWasRejectedByService => write!(f, "Key was rejected by service"),
OwnerDied => write!(f, "Owner died"),
StateNotRecoverable => write!(f, "State not recoverable"),
OperationNotPossibleDueToRfKill => write!(f, "Operation not possible due to RF-kill"),
MemoryPageHasHardwareError => write!(f, "Memory page has hardware error"),
Other(value) => write!(f, "Other error: {}", value),
_ => write!(f, "Unknown Error"), // Errors not present in linux
}
}
}