1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
use core::fmt;
use rcore_fs::vfs::FsError;
use zircon_object::ZxError;
pub type LxResult<T = ()> = Result<T, LxError>;
pub type SysResult = LxResult<usize>;
#[allow(dead_code)]
#[repr(isize)]
#[derive(Debug)]
pub enum LxError {
EUNDEF = 0,
EPERM = 1,
ENOENT = 2,
ESRCH = 3,
EINTR = 4,
EIO = 5,
ENXIO = 6,
E2BIG = 7,
ENOEXEC = 8,
EBADF = 9,
ECHILD = 10,
EAGAIN = 11,
ENOMEM = 12,
EACCES = 13,
EFAULT = 14,
ENOTBLK = 15,
EBUSY = 16,
EEXIST = 17,
EXDEV = 18,
ENODEV = 19,
ENOTDIR = 20,
EISDIR = 21,
EINVAL = 22,
ENFILE = 23,
EMFILE = 24,
ENOTTY = 25,
ETXTBSY = 26,
EFBIG = 27,
ENOSPC = 28,
ESPIPE = 29,
EROFS = 30,
EMLINK = 31,
EPIPE = 32,
EDOM = 33,
ERANGE = 34,
EDEADLK = 35,
ENAMETOOLONG = 36,
ENOLCK = 37,
ENOSYS = 38,
ENOTEMPTY = 39,
ELOOP = 40,
EIDRM = 43,
ENOTSOCK = 88,
ENOPROTOOPT = 92,
EPFNOSUPPORT = 96,
EAFNOSUPPORT = 97,
ENOBUFS = 105,
EISCONN = 106,
ENOTCONN = 107,
ETIMEDOUT = 110,
ECONNREFUSED = 111,
}
#[allow(non_snake_case)]
impl fmt::Display for LxError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::LxError::*;
let explain = match self {
EPERM => "Operation not permitted",
ENOENT => "No such file or directory",
ESRCH => "No such process",
EINTR => "Interrupted system call",
EIO => "I/O error",
ENXIO => "No such device or address",
E2BIG => "Argument list too long",
ENOEXEC => "Exec format error",
EBADF => "Bad file number",
ECHILD => "No child processes",
EAGAIN => "Try again",
ENOMEM => "Out of memory",
EACCES => "Permission denied",
EFAULT => "Bad address",
ENOTBLK => "Block device required",
EBUSY => "Device or resource busy",
EEXIST => "File exists",
EXDEV => "Cross-device link",
ENODEV => "No such device",
ENOTDIR => "Not a directory",
EISDIR => "Is a directory",
EINVAL => "Invalid argument",
ENFILE => "File table overflow",
EMFILE => "Too many open files",
ENOTTY => "Not a typewriter",
ETXTBSY => "Text file busy",
EFBIG => "File too large",
ENOSPC => "No space left on device",
ESPIPE => "Illegal seek",
EROFS => "Read-only file system",
EMLINK => "Too many links",
EPIPE => "Broken pipe",
EDOM => "Math argument out of domain of func",
ERANGE => "Math result not representable",
EDEADLK => "Resource deadlock would occur",
ENAMETOOLONG => "File name too long",
ENOLCK => "No record locks available",
ENOSYS => "Function not implemented",
ENOTEMPTY => "Directory not empty",
ELOOP => "Too many symbolic links encountered",
EIDRM => "Identifier removed",
ENOTSOCK => "Socket operation on non-socket",
ENOPROTOOPT => "Protocol not available",
EPFNOSUPPORT => "Protocol family not supported",
EAFNOSUPPORT => "Address family not supported by protocol",
ENOBUFS => "No buffer space available",
EISCONN => "Transport endpoint is already connected",
ENOTCONN => "Transport endpoint is not connected",
ECONNREFUSED => "Connection refused",
_ => "Unknown error",
};
write!(f, "{}", explain)
}
}
impl From<ZxError> for LxError {
fn from(e: ZxError) -> Self {
match e {
ZxError::INVALID_ARGS => LxError::EINVAL,
ZxError::NOT_SUPPORTED => LxError::ENOSYS,
ZxError::ALREADY_EXISTS => LxError::EEXIST,
ZxError::SHOULD_WAIT => LxError::EAGAIN,
ZxError::PEER_CLOSED => LxError::EPIPE,
ZxError::BAD_HANDLE => LxError::EBADF,
ZxError::TIMED_OUT => LxError::ETIMEDOUT,
ZxError::STOP => LxError::ESRCH,
ZxError::BAD_STATE => LxError::EAGAIN,
_ => unimplemented!("unknown error type: {:?}", e),
}
}
}
impl From<FsError> for LxError {
fn from(error: FsError) -> Self {
match error {
FsError::NotSupported => LxError::ENOSYS,
FsError::NotFile => LxError::EISDIR,
FsError::IsDir => LxError::EISDIR,
FsError::NotDir => LxError::ENOTDIR,
FsError::EntryNotFound => LxError::ENOENT,
FsError::EntryExist => LxError::EEXIST,
FsError::NotSameFs => LxError::EXDEV,
FsError::InvalidParam => LxError::EINVAL,
FsError::NoDeviceSpace => LxError::ENOMEM,
FsError::DirRemoved => LxError::ENOENT,
FsError::DirNotEmpty => LxError::ENOTEMPTY,
FsError::WrongFs => LxError::EINVAL,
FsError::DeviceError => LxError::EIO,
FsError::IOCTLError => LxError::EINVAL,
FsError::NoDevice => LxError::EINVAL,
FsError::Again => LxError::EAGAIN,
FsError::SymLoop => LxError::ELOOP,
FsError::Busy => LxError::EBUSY,
FsError::Interrupted => LxError::EINTR,
}
}
}
use kernel_hal::user::Error;
impl From<Error> for LxError {
fn from(e: Error) -> Self {
match e {
Error::InvalidUtf8 => LxError::EINVAL,
Error::InvalidPointer => LxError::EFAULT,
Error::BufferTooSmall => LxError::ENOBUFS,
Error::InvalidLength => LxError::EINVAL,
Error::InvalidVectorAddress => LxError::EINVAL,
}
}
}