aboutsummaryrefslogtreecommitdiff
path: root/lib/std/os/uefi/status.zig
blob: 2e17ef64c98a6af1a43e44a88deb8f0d0eb72ea7 (plain)
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
const testing = @import("std").testing;

const high_bit = 1 << @typeInfo(usize).int.bits - 1;

pub const Status = enum(usize) {
    /// The operation completed successfully.
    success = 0,

    /// The image failed to load.
    load_error = high_bit | 1,

    /// A parameter was incorrect.
    invalid_parameter = high_bit | 2,

    /// The operation is not supported.
    unsupported = high_bit | 3,

    /// The buffer was not the proper size for the request.
    bad_buffer_size = high_bit | 4,

    /// The buffer is not large enough to hold the requested data. The required buffer size is returned in the appropriate parameter when this error occurs.
    buffer_too_small = high_bit | 5,

    /// There is no data pending upon return.
    not_ready = high_bit | 6,

    /// The physical device reported an error while attempting the operation.
    device_error = high_bit | 7,

    /// The device cannot be written to.
    write_protected = high_bit | 8,

    /// A resource has run out.
    out_of_resources = high_bit | 9,

    /// An inconstancy was detected on the file system causing the operating to fail.
    volume_corrupted = high_bit | 10,

    /// There is no more space on the file system.
    volume_full = high_bit | 11,

    /// The device does not contain any medium to perform the operation.
    no_media = high_bit | 12,

    /// The medium in the device has changed since the last access.
    media_changed = high_bit | 13,

    /// The item was not found.
    not_found = high_bit | 14,

    /// Access was denied.
    access_denied = high_bit | 15,

    /// The server was not found or did not respond to the request.
    no_response = high_bit | 16,

    /// A mapping to a device does not exist.
    no_mapping = high_bit | 17,

    /// The timeout time expired.
    timeout = high_bit | 18,

    /// The protocol has not been started.
    not_started = high_bit | 19,

    /// The protocol has already been started.
    already_started = high_bit | 20,

    /// The operation was aborted.
    aborted = high_bit | 21,

    /// An ICMP error occurred during the network operation.
    icmp_error = high_bit | 22,

    /// A TFTP error occurred during the network operation.
    tftp_error = high_bit | 23,

    /// A protocol error occurred during the network operation.
    protocol_error = high_bit | 24,

    /// The function encountered an internal version that was incompatible with a version requested by the caller.
    incompatible_version = high_bit | 25,

    /// The function was not performed due to a security violation.
    security_violation = high_bit | 26,

    /// A CRC error was detected.
    crc_error = high_bit | 27,

    /// Beginning or end of media was reached
    end_of_media = high_bit | 28,

    /// The end of the file was reached.
    end_of_file = high_bit | 31,

    /// The language specified was invalid.
    invalid_language = high_bit | 32,

    /// The security status of the data is unknown or compromised and the data must be updated or replaced to restore a valid security status.
    compromised_data = high_bit | 33,

    /// There is an address conflict address allocation
    ip_address_conflict = high_bit | 34,

    /// A HTTP error occurred during the network operation.
    http_error = high_bit | 35,

    network_unreachable = high_bit | 100,

    host_unreachable = high_bit | 101,

    protocol_unreachable = high_bit | 102,

    port_unreachable = high_bit | 103,

    connection_fin = high_bit | 104,

    connection_reset = high_bit | 105,

    connection_refused = high_bit | 106,

    /// The string contained one or more characters that the device could not render and were skipped.
    warn_unknown_glyph = 1,

    /// The handle was closed, but the file was not deleted.
    warn_delete_failure = 2,

    /// The handle was closed, but the data to the file was not flushed properly.
    warn_write_failure = 3,

    /// The resulting buffer was too small, and the data was truncated to the buffer size.
    warn_buffer_too_small = 4,

    /// The data has not been updated within the timeframe set by localpolicy for this type of data.
    warn_stale_data = 5,

    /// The resulting buffer contains UEFI-compliant file system.
    warn_file_system = 6,

    /// The operation will be processed across a system reset.
    warn_reset_required = 7,

    _,

    pub const Error = error{
        LoadError,
        InvalidParameter,
        Unsupported,
        BadBufferSize,
        BufferTooSmall,
        NotReady,
        DeviceError,
        WriteProtected,
        OutOfResources,
        VolumeCorrupted,
        VolumeFull,
        NoMedia,
        MediaChanged,
        NotFound,
        AccessDenied,
        NoResponse,
        NoMapping,
        Timeout,
        NotStarted,
        AlreadyStarted,
        Aborted,
        IcmpError,
        TftpError,
        ProtocolError,
        IncompatibleVersion,
        SecurityViolation,
        CrcError,
        EndOfMedia,
        EndOfFile,
        InvalidLanguage,
        CompromisedData,
        IpAddressConflict,
        HttpError,
        NetworkUnreachable,
        HostUnreachable,
        ProtocolUnreachable,
        PortUnreachable,
        ConnectionFin,
        ConnectionReset,
        ConnectionRefused,
    };

    pub fn err(self: Status) Error!void {
        switch (self) {
            .load_error => return error.LoadError,
            .invalid_parameter => return error.InvalidParameter,
            .unsupported => return error.Unsupported,
            .bad_buffer_size => return error.BadBufferSize,
            .buffer_too_small => return error.BufferTooSmall,
            .not_ready => return error.NotReady,
            .device_error => return error.DeviceError,
            .write_protected => return error.WriteProtected,
            .out_of_resources => return error.OutOfResources,
            .volume_corrupted => return error.VolumeCorrupted,
            .volume_full => return error.VolumeFull,
            .no_media => return error.NoMedia,
            .media_changed => return error.MediaChanged,
            .not_found => return error.NotFound,
            .access_denied => return error.AccessDenied,
            .no_response => return error.NoResponse,
            .no_mapping => return error.NoMapping,
            .timeout => return error.Timeout,
            .not_started => return error.NotStarted,
            .already_started => return error.AlreadyStarted,
            .aborted => return error.Aborted,
            .icmp_error => return error.IcmpError,
            .tftp_error => return error.TftpError,
            .protocol_error => return error.ProtocolError,
            .incompatible_version => return error.IncompatibleVersion,
            .security_violation => return error.SecurityViolation,
            .crc_error => return error.CrcError,
            .end_of_media => return error.EndOfMedia,
            .end_of_file => return error.EndOfFile,
            .invalid_language => return error.InvalidLanguage,
            .compromised_data => return error.CompromisedData,
            .ip_address_conflict => return error.IpAddressConflict,
            .http_error => return error.HttpError,
            .network_unreachable => return error.NetworkUnreachable,
            .host_unreachable => return error.HostUnreachable,
            .protocol_unreachable => return error.ProtocolUnreachable,
            .port_unreachable => return error.PortUnreachable,
            .connection_fin => return error.ConnectionFin,
            .connection_reset => return error.ConnectionReset,
            .connection_refused => return error.ConnectionRefused,
            // success, warn_*, _
            else => {},
        }
    }

    pub fn fromError(e: Error) Status {
        return switch (e) {
            Error.Aborted => .aborted,
            Error.AccessDenied => .access_denied,
            Error.AlreadyStarted => .already_started,
            Error.BadBufferSize => .bad_buffer_size,
            Error.BufferTooSmall => .buffer_too_small,
            Error.CompromisedData => .compromised_data,
            Error.ConnectionFin => .connection_fin,
            Error.ConnectionRefused => .connection_refused,
            Error.ConnectionReset => .connection_reset,
            Error.CrcError => .crc_error,
            Error.DeviceError => .device_error,
            Error.EndOfFile => .end_of_file,
            Error.EndOfMedia => .end_of_media,
            Error.HostUnreachable => .host_unreachable,
            Error.HttpError => .http_error,
            Error.IcmpError => .icmp_error,
            Error.IncompatibleVersion => .incompatible_version,
            Error.InvalidLanguage => .invalid_language,
            Error.InvalidParameter => .invalid_parameter,
            Error.IpAddressConflict => .ip_address_conflict,
            Error.LoadError => .load_error,
            Error.MediaChanged => .media_changed,
            Error.NetworkUnreachable => .network_unreachable,
            Error.NoMapping => .no_mapping,
            Error.NoMedia => .no_media,
            Error.NoResponse => .no_response,
            Error.NotFound => .not_found,
            Error.NotReady => .not_ready,
            Error.NotStarted => .not_started,
            Error.OutOfResources => .out_of_resources,
            Error.PortUnreachable => .port_unreachable,
            Error.ProtocolError => .protocol_error,
            Error.ProtocolUnreachable => .protocol_unreachable,
            Error.SecurityViolation => .security_violation,
            Error.TftpError => .tftp_error,
            Error.Timeout => .timeout,
            Error.Unsupported => .unsupported,
            Error.VolumeCorrupted => .volume_corrupted,
            Error.VolumeFull => .volume_full,
            Error.WriteProtected => .write_protected,
        };
    }
};

test "status" {
    var st: Status = .device_error;
    try testing.expectError(error.DeviceError, st.err());
    try testing.expectEqual(st, Status.fromError(st.err()));

    st = .success;
    try st.err();

    st = .warn_unknown_glyph;
    try st.err();
}