1
- // The error codes are unportable, but that's how the spec defines them.
2
- #![ allow( clippy:: enum_clike_unportable_variant) ]
3
-
4
1
use super :: Result ;
5
2
use core:: ops;
6
3
use ucs2;
7
4
5
+ /// Bit indicating that an UEFI status code is an error
6
+ const ERROR_BIT : usize = 1 << ( core:: mem:: size_of :: < usize > ( ) * 8 - 1 ) ;
7
+
8
+ newtype_enum ! {
8
9
/// UEFI uses status codes in order to report successes, errors, and warnings.
9
10
///
10
11
/// Unfortunately, the spec allows and encourages implementation-specific
11
12
/// non-portable status codes. Therefore, these cannot be modeled as a Rust
12
13
/// enum, as injecting an unknown value in a Rust enum is undefined behaviour.
13
14
///
14
15
/// For lack of a better option, we therefore model them as a newtype of usize.
15
- #[ derive( Debug , Copy , Clone , Eq , PartialEq ) ]
16
- #[ repr( transparent) ]
17
16
#[ must_use]
18
- pub struct Status ( usize ) ;
19
-
20
- /// Macro to make implementation of status codes easier
21
- macro_rules! status_codes {
22
- ( $( $( #[ $attr: meta] ) *
23
- $status: ident = $code: expr, ) *
24
- ) => {
25
- #[ allow( unused) ]
26
- impl Status {
27
- $( $( #[ $attr] ) *
28
- pub const $status: Status = Status ( $code) ; ) *
29
- }
30
- }
31
- }
32
- //
33
- status_codes ! {
17
+ pub enum Status : usize => {
34
18
/// The operation completed successfully.
35
19
SUCCESS = 0 ,
20
+
36
21
/// The string contained characters that could not be rendered and were skipped.
37
22
WARN_UNKNOWN_GLYPH = 1 ,
38
23
/// The handle was closed, but the file was not deleted.
@@ -47,94 +32,77 @@ status_codes! {
47
32
WARN_FILE_SYSTEM = 6 ,
48
33
/// The operation will be processed across a system reset.
49
34
WARN_RESET_REQUIRED = 7 ,
50
- }
51
-
52
- /// Bit indicating that a status code is an error
53
- const ERROR_BIT : usize = 1 << ( core:: mem:: size_of :: < usize > ( ) * 8 - 1 ) ;
54
35
55
- /// Macro to make implementation of error codes easier
56
- macro_rules! error_codes {
57
- ( $( $( #[ $attr: meta] ) *
58
- $status: ident = $error_code: expr, ) *
59
- ) => {
60
- status_codes! { $(
61
- $( #[ $attr] ) *
62
- $status = $error_code | ERROR_BIT ,
63
- ) * }
64
- }
65
- }
66
- //
67
- error_codes ! {
68
36
/// The image failed to load.
69
- LOAD_ERROR = 1 ,
37
+ LOAD_ERROR = ERROR_BIT | 1 ,
70
38
/// A parameter was incorrect.
71
- INVALID_PARAMETER = 2 ,
39
+ INVALID_PARAMETER = ERROR_BIT | 2 ,
72
40
/// The operation is not supported.
73
- UNSUPPORTED = 3 ,
41
+ UNSUPPORTED = ERROR_BIT | 3 ,
74
42
/// The buffer was not the proper size for the request.
75
- BAD_BUFFER_SIZE = 4 ,
43
+ BAD_BUFFER_SIZE = ERROR_BIT | 4 ,
76
44
/// The buffer is not large enough to hold the requested data.
77
45
/// The required buffer size is returned in the appropriate parameter.
78
- BUFFER_TOO_SMALL = 5 ,
46
+ BUFFER_TOO_SMALL = ERROR_BIT | 5 ,
79
47
/// There is no data pending upon return.
80
- NOT_READY = 6 ,
48
+ NOT_READY = ERROR_BIT | 6 ,
81
49
/// The physical device reported an error while attempting the operation.
82
- DEVICE_ERROR = 7 ,
50
+ DEVICE_ERROR = ERROR_BIT | 7 ,
83
51
/// The device cannot be written to.
84
- WRITE_PROTECTED = 8 ,
52
+ WRITE_PROTECTED = ERROR_BIT | 8 ,
85
53
/// A resource has run out.
86
- OUT_OF_RESOURCES = 9 ,
54
+ OUT_OF_RESOURCES = ERROR_BIT | 9 ,
87
55
/// An inconstency was detected on the file system.
88
- VOLUME_CORRUPTED = 10 ,
56
+ VOLUME_CORRUPTED = ERROR_BIT | 10 ,
89
57
/// There is no more space on the file system.
90
- VOLUME_FULL = 11 ,
58
+ VOLUME_FULL = ERROR_BIT | 11 ,
91
59
/// The device does not contain any medium to perform the operation.
92
- NO_MEDIA = 12 ,
60
+ NO_MEDIA = ERROR_BIT | 12 ,
93
61
/// The medium in the device has changed since the last access.
94
- MEDIA_CHANGED = 13 ,
62
+ MEDIA_CHANGED = ERROR_BIT | 13 ,
95
63
/// The item was not found.
96
- NOT_FOUND = 14 ,
64
+ NOT_FOUND = ERROR_BIT | 14 ,
97
65
/// Access was denied.
98
- ACCESS_DENIED = 15 ,
66
+ ACCESS_DENIED = ERROR_BIT | 15 ,
99
67
/// The server was not found or did not respond to the request.
100
- NO_RESPONSE = 16 ,
68
+ NO_RESPONSE = ERROR_BIT | 16 ,
101
69
/// A mapping to a device does not exist.
102
- NO_MAPPING = 17 ,
70
+ NO_MAPPING = ERROR_BIT | 17 ,
103
71
/// The timeout time expired.
104
- TIMEOUT = 18 ,
72
+ TIMEOUT = ERROR_BIT | 18 ,
105
73
/// The protocol has not been started.
106
- NOT_STARTED = 19 ,
74
+ NOT_STARTED = ERROR_BIT | 19 ,
107
75
/// The protocol has already been started.
108
- ALREADY_STARTED = 20 ,
76
+ ALREADY_STARTED = ERROR_BIT | 20 ,
109
77
/// The operation was aborted.
110
- ABORTED = 21 ,
78
+ ABORTED = ERROR_BIT | 21 ,
111
79
/// An ICMP error occurred during the network operation.
112
- ICMP_ERROR = 22 ,
80
+ ICMP_ERROR = ERROR_BIT | 22 ,
113
81
/// A TFTP error occurred during the network operation.
114
- TFTP_ERROR = 23 ,
82
+ TFTP_ERROR = ERROR_BIT | 23 ,
115
83
/// A protocol error occurred during the network operation.
116
- PROTOCOL_ERROR = 24 ,
84
+ PROTOCOL_ERROR = ERROR_BIT | 24 ,
117
85
/// The function encountered an internal version that was
118
86
/// incompatible with a version requested by the caller.
119
- INCOMPATIBLE_VERSION = 25 ,
87
+ INCOMPATIBLE_VERSION = ERROR_BIT | 25 ,
120
88
/// The function was not performed due to a security violation.
121
- SECURITY_VIOLATION = 26 ,
89
+ SECURITY_VIOLATION = ERROR_BIT | 26 ,
122
90
/// A CRC error was detected.
123
- CRC_ERROR = 27 ,
91
+ CRC_ERROR = ERROR_BIT | 27 ,
124
92
/// Beginning or end of media was reached
125
- END_OF_MEDIA = 28 ,
93
+ END_OF_MEDIA = ERROR_BIT | 28 ,
126
94
/// The end of the file was reached.
127
- END_OF_FILE = 31 ,
95
+ END_OF_FILE = ERROR_BIT | 31 ,
128
96
/// The language specified was invalid.
129
- INVALID_LANGUAGE = 32 ,
97
+ INVALID_LANGUAGE = ERROR_BIT | 32 ,
130
98
/// The security status of the data is unknown or compromised and
131
99
/// the data must be updated or replaced to restore a valid security status.
132
- COMPROMISED_DATA = 33 ,
100
+ COMPROMISED_DATA = ERROR_BIT | 33 ,
133
101
/// There is an address conflict address allocation
134
- IP_ADDRESS_CONFLICT = 34 ,
102
+ IP_ADDRESS_CONFLICT = ERROR_BIT | 34 ,
135
103
/// A HTTP error occurred during the network operation.
136
- HTTP_ERROR = 35 ,
137
- }
104
+ HTTP_ERROR = ERROR_BIT | 35 ,
105
+ } }
138
106
139
107
impl Status {
140
108
/// Returns true if status code indicates success.
0 commit comments