1164010Smarcel/*-
2164010Smarcel * Copyright (c) 2006 Marcel Moolenaar
3164010Smarcel * All rights reserved.
4164010Smarcel *
5164010Smarcel * Redistribution and use in source and binary forms, with or without
6164010Smarcel * modification, are permitted provided that the following conditions
7164010Smarcel * are met:
8164010Smarcel *
9164010Smarcel * 1. Redistributions of source code must retain the above copyright
10164010Smarcel *    notice, this list of conditions and the following disclaimer.
11164010Smarcel * 2. Redistributions in binary form must reproduce the above copyright
12164010Smarcel *    notice, this list of conditions and the following disclaimer in the
13164010Smarcel *    documentation and/or other materials provided with the distribution.
14164010Smarcel *
15164010Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16164010Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17164010Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18164010Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19164010Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20164010Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21164010Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22164010Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23164010Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24164010Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25164010Smarcel */
26164010Smarcel
27164010Smarcel#include <sys/cdefs.h>
28164010Smarcel__FBSDID("$FreeBSD$");
29164010Smarcel
30164010Smarcel#include <efi.h>
31164010Smarcel#include <efilib.h>
32164010Smarcel
33164010Smarcelint
34164010Smarcelefi_status_to_errno(EFI_STATUS status)
35164010Smarcel{
36164010Smarcel	int errno;
37164010Smarcel
38164010Smarcel	switch (status) {
39164010Smarcel	case EFI_ACCESS_DENIED:
40164010Smarcel		errno = EPERM;
41164010Smarcel		break;
42164010Smarcel
43164010Smarcel	case EFI_BUFFER_TOO_SMALL:
44164010Smarcel		errno = EOVERFLOW;
45164010Smarcel		break;
46164010Smarcel
47164010Smarcel	case EFI_DEVICE_ERROR:
48164010Smarcel	case EFI_VOLUME_CORRUPTED:
49164010Smarcel		errno = EIO;
50164010Smarcel		break;
51164010Smarcel
52164010Smarcel	case EFI_INVALID_PARAMETER:
53164010Smarcel		errno = EINVAL;
54164010Smarcel		break;
55164010Smarcel
56164010Smarcel	case EFI_MEDIA_CHANGED:
57164010Smarcel		errno = ESTALE;
58164010Smarcel		break;
59164010Smarcel
60164010Smarcel	case EFI_NO_MEDIA:
61164010Smarcel		errno = ENXIO;
62164010Smarcel		break;
63164010Smarcel
64164010Smarcel	case EFI_NOT_FOUND:
65164010Smarcel		errno = ENOENT;
66164010Smarcel		break;
67164010Smarcel
68164010Smarcel	case EFI_OUT_OF_RESOURCES:
69164010Smarcel		errno = ENOMEM;
70164010Smarcel		break;
71164010Smarcel
72164010Smarcel	case EFI_UNSUPPORTED:
73164010Smarcel		errno = ENODEV;
74164010Smarcel		break;
75164010Smarcel
76164010Smarcel	case EFI_VOLUME_FULL:
77164010Smarcel		errno = ENOSPC;
78164010Smarcel		break;
79164010Smarcel
80164010Smarcel	case EFI_WRITE_PROTECTED:
81164010Smarcel		errno = EACCES;
82164010Smarcel		break;
83164010Smarcel
84164010Smarcel	case 0:
85164010Smarcel		errno = 0;
86164010Smarcel		break;
87164010Smarcel
88164010Smarcel	default:
89164010Smarcel		errno = EDOOFUS;
90164010Smarcel		break;
91164010Smarcel	}
92164010Smarcel
93164010Smarcel	return (errno);
94164010Smarcel}
95