uefi_raw/
status.rs

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