Skip to content

Commit 9740bcb

Browse files
authored
Merge pull request #455 from Kloenk/eaddrnotavail
Add EADDRNOTAVAIL error to rust
2 parents 744b1f1 + 2473396 commit 9740bcb

File tree

1 file changed

+254
-70
lines changed

1 file changed

+254
-70
lines changed

rust/kernel/error.rs

Lines changed: 254 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ use core::fmt;
1212
use core::num::TryFromIntError;
1313
use core::str::{self, Utf8Error};
1414

15+
macro_rules! declare_err {
16+
($err:tt) => {
17+
pub const $err: Self = Error(-(bindings::$err as i32));
18+
};
19+
($err:tt, $($doc:expr),+) => {
20+
$(
21+
#[doc = $doc]
22+
)*
23+
pub const $err: Self = Error(-(bindings::$err as i32));
24+
};
25+
}
26+
1527
/// Generic integer kernel error.
1628
///
1729
/// The kernel defines a set of integer generic error codes based on C and
@@ -24,110 +36,282 @@ use core::str::{self, Utf8Error};
2436
pub struct Error(c_types::c_int);
2537

2638
impl Error {
27-
/// Operation not permitted.
28-
pub const EPERM: Self = Error(-(bindings::EPERM as i32));
39+
declare_err!(EPERM, "Operation not permitted.");
40+
41+
declare_err!(ENOENT, "No such file or directory.");
42+
43+
declare_err!(ESRCH, "No such process.");
44+
45+
declare_err!(EINTR, "Interrupted system call.");
46+
47+
declare_err!(EIO, "I/O error.");
48+
49+
declare_err!(ENXIO, "No such device or address.");
50+
51+
declare_err!(E2BIG, "Argument list too long.");
52+
53+
declare_err!(ENOEXEC, "Exec format error.");
54+
55+
declare_err!(EBADF, "Bad file number.");
56+
57+
declare_err!(ECHILD, "Exec format error.");
58+
59+
declare_err!(EAGAIN, "Try again.");
60+
61+
declare_err!(ENOMEM, "Out of memory.");
62+
63+
declare_err!(EACCES, "Permission denied.");
64+
65+
declare_err!(EFAULT, "Bad address.");
66+
67+
declare_err!(ENOTBLK, "Block device required.");
68+
69+
declare_err!(EBUSY, "Device or resource busy.");
70+
71+
declare_err!(EEXIST, "File exists.");
72+
73+
declare_err!(EXDEV, "Cross-device link.");
74+
75+
declare_err!(ENODEV, "No such device.");
76+
77+
declare_err!(ENOTDIR, "Not a directory.");
78+
79+
declare_err!(EISDIR, "Is a directory.");
80+
81+
declare_err!(EINVAL, "Invalid argument.");
82+
83+
declare_err!(ENFILE, "File table overflow.");
84+
85+
declare_err!(EMFILE, "Too many open files.");
86+
87+
declare_err!(ENOTTY, "Not a typewriter.");
88+
89+
declare_err!(ETXTBSY, "Text file busy.");
90+
91+
declare_err!(EFBIG, "File too large.");
92+
93+
declare_err!(ENOSPC, "No space left on device.");
94+
95+
declare_err!(ESPIPE, "Illegal seek.");
96+
97+
declare_err!(EROFS, "Read-only file system.");
98+
99+
declare_err!(EMLINK, "Too many links.");
100+
101+
declare_err!(EPIPE, "Broken pipe.");
102+
103+
declare_err!(EDOM, "Math argument out of domain of func.");
104+
105+
declare_err!(ERANGE, "Math result not representable.");
106+
107+
declare_err!(EDEADLK, "Resource deadlock would occur");
108+
109+
declare_err!(ENAMETOOLONG, "File name too long");
110+
111+
declare_err!(ENOLCK, "No record locks available");
112+
113+
declare_err!(
114+
ENOSYS,
115+
"Invalid system call number.",
116+
"",
117+
"This error code is special: arch syscall entry code will return",
118+
"[`Self::ENOSYS`] if users try to call a syscall that doesn't exist.",
119+
"To keep failures of syscalls that really do exist distinguishable from",
120+
"failures due to attempts to use a nonexistent syscall, syscall",
121+
"implementations should refrain from returning [`Self::ENOSYS`]."
122+
);
123+
124+
declare_err!(ENOTEMPTY, "Directory not empty.");
125+
126+
declare_err!(ELOOP, "Too many symbolic links encountered.");
127+
128+
declare_err!(EWOULDBLOCK, "Operation would block.");
129+
130+
declare_err!(ENOMSG, "No message of desired type.");
131+
132+
declare_err!(EIDRM, "Identifier removed.");
133+
134+
declare_err!(ECHRNG, "Channel number out of range.");
135+
136+
declare_err!(EL2NSYNC, "Level 2 not synchronized.");
137+
138+
declare_err!(EL3HLT, "Level 3 halted.");
139+
140+
declare_err!(EL3RST, "Level 3 reset.");
141+
142+
declare_err!(ELNRNG, "Link number out of range.");
143+
144+
declare_err!(EUNATCH, "Protocol driver not attached.");
145+
146+
declare_err!(ENOCSI, "No CSI structure available.");
147+
148+
declare_err!(EL2HLT, "Level 2 halted.");
149+
150+
declare_err!(EBADE, "Invalid exchange.");
151+
152+
declare_err!(EBADR, "Invalid request descriptor.");
153+
154+
declare_err!(EXFULL, "Exchange full.");
155+
156+
declare_err!(ENOANO, "No anode.");
157+
158+
declare_err!(EBADRQC, "Invalid request code.");
159+
160+
declare_err!(EBADSLT, "Invalid slot.");
161+
162+
declare_err!(EDEADLOCK, "Resource deadlock would occur.");
163+
164+
declare_err!(EBFONT, "Bad font file format.");
165+
166+
declare_err!(ENOSTR, "Device not a stream.");
167+
168+
declare_err!(ENODATA, "No data available.");
169+
170+
declare_err!(ETIME, "Timer expired.");
171+
172+
declare_err!(ENOSR, "Out of streams resources.");
173+
174+
declare_err!(ENONET, "Machine is not on the network.");
175+
176+
declare_err!(ENOPKG, "Package not installed.");
177+
178+
declare_err!(EREMOTE, "Object is remote.");
179+
180+
declare_err!(ENOLINK, "Link has been severed.");
181+
182+
declare_err!(EADV, "Advertise error.");
183+
184+
declare_err!(ESRMNT, "Srmount error.");
185+
186+
declare_err!(ECOMM, "Communication error on send.");
187+
188+
declare_err!(EPROTO, "Protocol error.");
189+
190+
declare_err!(EMULTIHOP, "Multihop attempted.");
191+
192+
declare_err!(EDOTDOT, "RFS specific error.");
193+
194+
declare_err!(EBADMSG, "Not a data message.");
195+
196+
declare_err!(EOVERFLOW, "Value too large for defined data type.");
197+
198+
declare_err!(ENOTUNIQ, "Name not unique on network.");
199+
200+
declare_err!(EBADFD, "File descriptor in bad state.");
201+
202+
declare_err!(EREMCHG, "Remote address changed.");
203+
204+
declare_err!(ELIBACC, "Can not access a needed shared library.");
205+
206+
declare_err!(ELIBBAD, "Accessing a corrupted shared library.");
207+
208+
declare_err!(ELIBSCN, ".lib section in a.out corrupted.");
209+
210+
declare_err!(ELIBMAX, "Attempting to link in too many shared libraries.");
211+
212+
declare_err!(ELIBEXEC, "Cannot exec a shared library directly.");
213+
214+
declare_err!(EILSEQ, "Illegal byte sequence.");
215+
216+
declare_err!(ERESTART, "Interrupted system call should be restarted.");
217+
218+
declare_err!(ESTRPIPE, "Streams pipe error.");
219+
220+
declare_err!(EUSERS, "Too many users.");
221+
222+
declare_err!(ENOTSOCK, "Socket operation on non-socket.");
223+
224+
declare_err!(EDESTADDRREQ, "Destination address required.");
225+
226+
declare_err!(EMSGSIZE, "Message too long.");
227+
228+
declare_err!(EPROTOTYPE, "Protocol wrong type for socket.");
229+
230+
declare_err!(ENOPROTOOPT, "Protocol not available.");
231+
232+
declare_err!(EPROTONOSUPPORT, "Protocol not supported.");
233+
234+
declare_err!(ESOCKTNOSUPPORT, "Socket type not supported.");
235+
236+
declare_err!(EOPNOTSUPP, "Operation not supported on transport endpoint.");
237+
238+
declare_err!(EPFNOSUPPORT, "Protocol family not supported.");
239+
240+
declare_err!(EAFNOSUPPORT, "Address family not supported by protocol.");
241+
242+
declare_err!(EADDRINUSE, "Address already in use.");
243+
244+
declare_err!(EADDRNOTAVAIL, "Cannot assign requested address.");
245+
246+
declare_err!(ENETDOWN, "Network is down.");
29247

30-
/// No such file or directory.
31-
pub const ENOENT: Self = Error(-(bindings::ENOENT as i32));
248+
declare_err!(ENETUNREACH, "Network is unreachable.");
32249

33-
/// No such process.
34-
pub const ESRCH: Self = Error(-(bindings::ESRCH as i32));
250+
declare_err!(ENETRESET, "Network dropped connection because of reset.");
35251

36-
/// Interrupted system call.
37-
pub const EINTR: Self = Error(-(bindings::EINTR as i32));
252+
declare_err!(ECONNABORTED, "Software caused connection abort.");
38253

39-
/// I/O error.
40-
pub const EIO: Self = Error(-(bindings::EIO as i32));
254+
declare_err!(ECONNRESET, "Connection reset by peer.");
41255

42-
/// No such device or address.
43-
pub const ENXIO: Self = Error(-(bindings::ENXIO as i32));
256+
declare_err!(ENOBUFS, "No buffer space available.");
44257

45-
/// Argument list too long.
46-
pub const E2BIG: Self = Error(-(bindings::E2BIG as i32));
258+
declare_err!(EISCONN, "Transport endpoint is already connected.");
47259

48-
/// Exec format error.
49-
pub const ENOEXEC: Self = Error(-(bindings::ENOEXEC as i32));
260+
declare_err!(ENOTCONN, "Transport endpoint is not connected.");
50261

51-
/// Bad file number.
52-
pub const EBADF: Self = Error(-(bindings::EBADF as i32));
262+
declare_err!(ESHUTDOWN, "Cannot send after transport endpoint shutdown.");
53263

54-
/// No child processes.
55-
pub const ECHILD: Self = Error(-(bindings::ECHILD as i32));
264+
declare_err!(ETOOMANYREFS, "Too many references: cannot splice.");
56265

57-
/// Try again.
58-
pub const EAGAIN: Self = Error(-(bindings::EAGAIN as i32));
266+
declare_err!(ETIMEDOUT, "Connection timed out.");
59267

60-
/// Out of memory.
61-
pub const ENOMEM: Self = Error(-(bindings::ENOMEM as i32));
268+
declare_err!(ECONNREFUSED, "Connection refused.");
62269

63-
/// Permission denied.
64-
pub const EACCES: Self = Error(-(bindings::EACCES as i32));
270+
declare_err!(EHOSTDOWN, "Host is down.");
65271

66-
/// Bad address.
67-
pub const EFAULT: Self = Error(-(bindings::EFAULT as i32));
272+
declare_err!(EHOSTUNREACH, "No route to host.");
68273

69-
/// Block device required.
70-
pub const ENOTBLK: Self = Error(-(bindings::ENOTBLK as i32));
274+
declare_err!(EALREADY, "Operation already in progress.");
71275

72-
/// Device or resource busy.
73-
pub const EBUSY: Self = Error(-(bindings::EBUSY as i32));
276+
declare_err!(EINPROGRESS, "Operation now in progress.");
74277

75-
/// File exists.
76-
pub const EEXIST: Self = Error(-(bindings::EEXIST as i32));
278+
declare_err!(ESTALE, "Stale file handle.");
77279

78-
/// Cross-device link.
79-
pub const EXDEV: Self = Error(-(bindings::EXDEV as i32));
280+
declare_err!(EUCLEAN, "Structure needs cleaning.");
80281

81-
/// No such device.
82-
pub const ENODEV: Self = Error(-(bindings::ENODEV as i32));
282+
declare_err!(ENOTNAM, "Not a XENIX named type file.");
83283

84-
/// Not a directory.
85-
pub const ENOTDIR: Self = Error(-(bindings::ENOTDIR as i32));
284+
declare_err!(ENAVAIL, "No XENIX semaphores available.");
86285

87-
/// Is a directory.
88-
pub const EISDIR: Self = Error(-(bindings::EISDIR as i32));
286+
declare_err!(EISNAM, "Is a named type file.");
89287

90-
/// Invalid argument.
91-
pub const EINVAL: Self = Error(-(bindings::EINVAL as i32));
288+
declare_err!(EREMOTEIO, "Remote I/O error.");
92289

93-
/// File table overflow.
94-
pub const ENFILE: Self = Error(-(bindings::ENFILE as i32));
290+
declare_err!(EDQUOT, "Quota exceeded.");
95291

96-
/// Too many open files.
97-
pub const EMFILE: Self = Error(-(bindings::EMFILE as i32));
292+
declare_err!(ENOMEDIUM, "No medium found.");
98293

99-
/// Not a typewriter.
100-
pub const ENOTTY: Self = Error(-(bindings::ENOTTY as i32));
294+
declare_err!(EMEDIUMTYPE, "Wrong medium type.");
101295

102-
/// Text file busy.
103-
pub const ETXTBSY: Self = Error(-(bindings::ETXTBSY as i32));
296+
declare_err!(ECANCELED, "Operation Canceled.");
104297

105-
/// File too large.
106-
pub const EFBIG: Self = Error(-(bindings::EFBIG as i32));
298+
declare_err!(ENOKEY, "Required key not available.");
107299

108-
/// No space left on device.
109-
pub const ENOSPC: Self = Error(-(bindings::ENOSPC as i32));
300+
declare_err!(EKEYEXPIRED, "Key has expired.");
110301

111-
/// Illegal seek.
112-
pub const ESPIPE: Self = Error(-(bindings::ESPIPE as i32));
302+
declare_err!(EKEYREVOKED, "Key has been revoked.");
113303

114-
/// Read-only file system.
115-
pub const EROFS: Self = Error(-(bindings::EROFS as i32));
304+
declare_err!(EKEYREJECTED, "Key was rejected by service.");
116305

117-
/// Too many links.
118-
pub const EMLINK: Self = Error(-(bindings::EMLINK as i32));
306+
declare_err!(EOWNERDEAD, "Owner died.", "", "For robust mutexes.");
119307

120-
/// Broken pipe.
121-
pub const EPIPE: Self = Error(-(bindings::EPIPE as i32));
308+
declare_err!(ENOTRECOVERABLE, "State not recoverable.");
122309

123-
/// Math argument out of domain of func.
124-
pub const EDOM: Self = Error(-(bindings::EDOM as i32));
310+
declare_err!(ERFKILL, "Operation not possible due to RF-kill.");
125311

126-
/// Math result not representable.
127-
pub const ERANGE: Self = Error(-(bindings::ERANGE as i32));
312+
declare_err!(EHWPOISON, "Memory page has hardware error.");
128313

129-
/// Restart the system call.
130-
pub const ERESTARTSYS: Self = Error(-(bindings::ERESTARTSYS as i32));
314+
declare_err!(ERESTARTSYS, "Restart the system call.");
131315

132316
/// Creates an [`Error`] from a kernel error code.
133317
///

0 commit comments

Comments
 (0)