|
| 1 | +use crate::io; |
| 2 | +use crate::sys::io::RawOsError; |
| 3 | + |
| 4 | +pub fn errno() -> RawOsError { |
| 5 | + // Not used in Motor OS because it is ambiguous: Motor OS |
| 6 | + // is micro-kernel-based, and I/O happens via a shared-memory |
| 7 | + // ring buffer, so an I/O operation that on a unix is a syscall |
| 8 | + // may involve no sycalls on Motor OS at all, or a syscall |
| 9 | + // that e.g. waits for a notification from the I/O driver |
| 10 | + // (sys-io); and the wait syscall may succeed, but the |
| 11 | + // driver may report an I/O error; or a bunch of results |
| 12 | + // for several I/O operations, some successful and some |
| 13 | + // not. |
| 14 | + // |
| 15 | + // Also I/O operations in a Motor OS process are handled by a |
| 16 | + // separate runtime background/I/O thread, so it is really hard |
| 17 | + // to define what "last system error in the current thread" |
| 18 | + // actually means. |
| 19 | + let error_code: moto_rt::ErrorCode = moto_rt::Error::Unknown.into(); |
| 20 | + error_code.into() |
| 21 | +} |
| 22 | + |
| 23 | +pub fn is_interrupted(_code: io::RawOsError) -> bool { |
| 24 | + false // Motor OS doesn't have signals. |
| 25 | +} |
| 26 | + |
| 27 | +pub fn decode_error_kind(code: io::RawOsError) -> io::ErrorKind { |
| 28 | + if code < 0 || code > u16::MAX.into() { |
| 29 | + return io::ErrorKind::Uncategorized; |
| 30 | + } |
| 31 | + |
| 32 | + let error = moto_rt::Error::from(code as moto_rt::ErrorCode); |
| 33 | + |
| 34 | + match error { |
| 35 | + moto_rt::Error::Unspecified => io::ErrorKind::Uncategorized, |
| 36 | + moto_rt::Error::Unknown => io::ErrorKind::Uncategorized, |
| 37 | + moto_rt::Error::NotReady => io::ErrorKind::WouldBlock, |
| 38 | + moto_rt::Error::NotImplemented => io::ErrorKind::Unsupported, |
| 39 | + moto_rt::Error::VersionTooHigh => io::ErrorKind::Unsupported, |
| 40 | + moto_rt::Error::VersionTooLow => io::ErrorKind::Unsupported, |
| 41 | + moto_rt::Error::InvalidArgument => io::ErrorKind::InvalidInput, |
| 42 | + moto_rt::Error::OutOfMemory => io::ErrorKind::OutOfMemory, |
| 43 | + moto_rt::Error::NotAllowed => io::ErrorKind::PermissionDenied, |
| 44 | + moto_rt::Error::NotFound => io::ErrorKind::NotFound, |
| 45 | + moto_rt::Error::InternalError => io::ErrorKind::Other, |
| 46 | + moto_rt::Error::TimedOut => io::ErrorKind::TimedOut, |
| 47 | + moto_rt::Error::AlreadyInUse => io::ErrorKind::AlreadyExists, |
| 48 | + moto_rt::Error::UnexpectedEof => io::ErrorKind::UnexpectedEof, |
| 49 | + moto_rt::Error::InvalidFilename => io::ErrorKind::InvalidFilename, |
| 50 | + moto_rt::Error::NotADirectory => io::ErrorKind::NotADirectory, |
| 51 | + moto_rt::Error::BadHandle => io::ErrorKind::InvalidInput, |
| 52 | + moto_rt::Error::FileTooLarge => io::ErrorKind::FileTooLarge, |
| 53 | + moto_rt::Error::NotConnected => io::ErrorKind::NotConnected, |
| 54 | + moto_rt::Error::StorageFull => io::ErrorKind::StorageFull, |
| 55 | + moto_rt::Error::InvalidData => io::ErrorKind::InvalidData, |
| 56 | + _ => io::ErrorKind::Uncategorized, |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +pub fn error_string(errno: RawOsError) -> String { |
| 61 | + let error: moto_rt::Error = match errno { |
| 62 | + x if x < 0 => moto_rt::Error::Unknown, |
| 63 | + x if x > u16::MAX.into() => moto_rt::Error::Unknown, |
| 64 | + x => (x as moto_rt::ErrorCode).into(), /* u16 */ |
| 65 | + }; |
| 66 | + format!("{}", error) |
| 67 | +} |
0 commit comments