uefi_raw/status.rs
1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3use core::fmt::Debug;
4
5newtype_enum! {
6/// UEFI uses status codes in order to report successes, errors, and warnings.
7///
8/// The spec allows implementation-specific status codes, so the `Status`
9/// constants are not a comprehensive list of all possible values.
10#[must_use]
11pub enum Status: usize => {
12 /// The operation completed successfully.
13 SUCCESS = 0,
14
15 /// The string contained characters that could not be rendered and were skipped.
16 WARN_UNKNOWN_GLYPH = 1,
17 /// The handle was closed, but the file was not deleted.
18 WARN_DELETE_FAILURE = 2,
19 /// The handle was closed, but the data to the file was not flushed properly.
20 WARN_WRITE_FAILURE = 3,
21 /// The resulting buffer was too small, and the data was truncated.
22 WARN_BUFFER_TOO_SMALL = 4,
23 /// The data has not been updated within the timeframe set by local policy.
24 WARN_STALE_DATA = 5,
25 /// The resulting buffer contains UEFI-compliant file system.
26 WARN_FILE_SYSTEM = 6,
27 /// The operation will be processed across a system reset.
28 WARN_RESET_REQUIRED = 7,
29
30 /// The image failed to load.
31 LOAD_ERROR = Self::ERROR_BIT | 1,
32 /// A parameter was incorrect.
33 INVALID_PARAMETER = Self::ERROR_BIT | 2,
34 /// The operation is not supported.
35 UNSUPPORTED = Self::ERROR_BIT | 3,
36 /// The buffer was not the proper size for the request.
37 BAD_BUFFER_SIZE = Self::ERROR_BIT | 4,
38 /// The buffer is not large enough to hold the requested data.
39 /// The required buffer size is returned in the appropriate parameter.
40 BUFFER_TOO_SMALL = Self::ERROR_BIT | 5,
41 /// There is no data pending upon return.
42 NOT_READY = Self::ERROR_BIT | 6,
43 /// The physical device reported an error while attempting the operation.
44 DEVICE_ERROR = Self::ERROR_BIT | 7,
45 /// The device cannot be written to.
46 WRITE_PROTECTED = Self::ERROR_BIT | 8,
47 /// A resource has run out.
48 OUT_OF_RESOURCES = Self::ERROR_BIT | 9,
49 /// An inconstency was detected on the file system.
50 VOLUME_CORRUPTED = Self::ERROR_BIT | 10,
51 /// There is no more space on the file system.
52 VOLUME_FULL = Self::ERROR_BIT | 11,
53 /// The device does not contain any medium to perform the operation.
54 NO_MEDIA = Self::ERROR_BIT | 12,
55 /// The medium in the device has changed since the last access.
56 MEDIA_CHANGED = Self::ERROR_BIT | 13,
57 /// The item was not found.
58 NOT_FOUND = Self::ERROR_BIT | 14,
59 /// Access was denied.
60 ACCESS_DENIED = Self::ERROR_BIT | 15,
61 /// The server was not found or did not respond to the request.
62 NO_RESPONSE = Self::ERROR_BIT | 16,
63 /// A mapping to a device does not exist.
64 NO_MAPPING = Self::ERROR_BIT | 17,
65 /// The timeout time expired.
66 TIMEOUT = Self::ERROR_BIT | 18,
67 /// The protocol has not been started.
68 NOT_STARTED = Self::ERROR_BIT | 19,
69 /// The protocol has already been started.
70 ALREADY_STARTED = Self::ERROR_BIT | 20,
71 /// The operation was aborted.
72 ABORTED = Self::ERROR_BIT | 21,
73 /// An ICMP error occurred during the network operation.
74 ICMP_ERROR = Self::ERROR_BIT | 22,
75 /// A TFTP error occurred during the network operation.
76 TFTP_ERROR = Self::ERROR_BIT | 23,
77 /// A protocol error occurred during the network operation.
78 PROTOCOL_ERROR = Self::ERROR_BIT | 24,
79 /// The function encountered an internal version that was
80 /// incompatible with a version requested by the caller.
81 INCOMPATIBLE_VERSION = Self::ERROR_BIT | 25,
82 /// The function was not performed due to a security violation.
83 SECURITY_VIOLATION = Self::ERROR_BIT | 26,
84 /// A CRC error was detected.
85 CRC_ERROR = Self::ERROR_BIT | 27,
86 /// Beginning or end of media was reached
87 END_OF_MEDIA = Self::ERROR_BIT | 28,
88 /// The end of the file was reached.
89 END_OF_FILE = Self::ERROR_BIT | 31,
90 /// The language specified was invalid.
91 INVALID_LANGUAGE = Self::ERROR_BIT | 32,
92 /// The security status of the data is unknown or compromised and
93 /// the data must be updated or replaced to restore a valid security status.
94 COMPROMISED_DATA = Self::ERROR_BIT | 33,
95 /// There is an address conflict address allocation
96 IP_ADDRESS_CONFLICT = Self::ERROR_BIT | 34,
97 /// A HTTP error occurred during the network operation.
98 HTTP_ERROR = Self::ERROR_BIT | 35,
99}}
100
101impl Status {
102 /// Bit indicating that an UEFI status code is an error.
103 pub const ERROR_BIT: usize = 1 << (usize::BITS - 1);
104
105 /// Returns true if status code indicates success.
106 #[inline]
107 #[must_use]
108 pub fn is_success(self) -> bool {
109 self == Self::SUCCESS
110 }
111
112 /// Returns true if status code indicates a warning.
113 #[inline]
114 #[must_use]
115 pub fn is_warning(self) -> bool {
116 (self != Self::SUCCESS) && (self.0 & Self::ERROR_BIT == 0)
117 }
118
119 /// Returns true if the status code indicates an error.
120 #[inline]
121 #[must_use]
122 pub const fn is_error(self) -> bool {
123 self.0 & Self::ERROR_BIT != 0
124 }
125}
126
127impl core::fmt::Display for Status {
128 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
129 Debug::fmt(self, f)
130 }
131}