1 /*
2 * Copyright (c) 2006 Marcel Moolenaar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 #include <sys/cdefs.h>
28
29 #include <efi.h>
30 #include <efilib.h>
31
32 EFI_STATUS
errno_to_efi_status(int errno)33 errno_to_efi_status(int errno)
34 {
35 EFI_STATUS status;
36
37 switch (errno) {
38 case EPERM:
39 status = EFI_ACCESS_DENIED;
40 break;
41
42 case EOVERFLOW:
43 status = EFI_BUFFER_TOO_SMALL;
44 break;
45
46 case EIO:
47 status = EFI_DEVICE_ERROR;
48 break;
49
50 case EINVAL:
51 status = EFI_INVALID_PARAMETER;
52 break;
53
54 case ESTALE:
55 status = EFI_MEDIA_CHANGED;
56 break;
57
58 case ENXIO:
59 status = EFI_NO_MEDIA;
60 break;
61
62 case ENOENT:
63 status = EFI_NOT_FOUND;
64 break;
65
66 case ENOMEM:
67 status = EFI_OUT_OF_RESOURCES;
68 break;
69
70 case ENOTSUP:
71 case ENODEV:
72 status = EFI_UNSUPPORTED;
73 break;
74
75 case ENOSPC:
76 status = EFI_VOLUME_FULL;
77 break;
78
79 case EACCES:
80 status = EFI_WRITE_PROTECTED;
81 break;
82
83 case 0:
84 status = EFI_SUCCESS;
85 break;
86
87 default:
88 status = EFI_DEVICE_ERROR;
89 break;
90 }
91
92 return (status);
93 }
94
95 int
efi_status_to_errno(EFI_STATUS status)96 efi_status_to_errno(EFI_STATUS status)
97 {
98 int errno;
99
100 switch (status) {
101 case EFI_ACCESS_DENIED:
102 errno = EPERM;
103 break;
104
105 case EFI_BUFFER_TOO_SMALL:
106 errno = EOVERFLOW;
107 break;
108
109 case EFI_DEVICE_ERROR:
110 case EFI_VOLUME_CORRUPTED:
111 errno = EIO;
112 break;
113
114 case EFI_INVALID_PARAMETER:
115 errno = EINVAL;
116 break;
117
118 case EFI_MEDIA_CHANGED:
119 errno = ESTALE;
120 break;
121
122 case EFI_NO_MEDIA:
123 errno = ENXIO;
124 break;
125
126 case EFI_NOT_FOUND:
127 errno = ENOENT;
128 break;
129
130 case EFI_OUT_OF_RESOURCES:
131 errno = ENOMEM;
132 break;
133
134 case EFI_UNSUPPORTED:
135 errno = ENODEV;
136 break;
137
138 case EFI_VOLUME_FULL:
139 errno = ENOSPC;
140 break;
141
142 case EFI_WRITE_PROTECTED:
143 errno = EACCES;
144 break;
145
146 case 0:
147 errno = 0;
148 break;
149
150 default:
151 errno = EDOOFUS;
152 break;
153 }
154
155 return (errno);
156 }
157