errno.c revision 285830
1147549Simp/*-
2147549Simp * Copyright (c) 2006 Marcel Moolenaar
3147549Simp * All rights reserved.
4147549Simp *
5147549Simp * Redistribution and use in source and binary forms, with or without
6147549Simp * modification, are permitted provided that the following conditions
7147549Simp * are met:
8147549Simp *
9147549Simp * 1. Redistributions of source code must retain the above copyright
10147549Simp *    notice, this list of conditions and the following disclaimer.
11147549Simp * 2. Redistributions in binary form must reproduce the above copyright
12147549Simp *    notice, this list of conditions and the following disclaimer in the
13147549Simp *    documentation and/or other materials provided with the distribution.
14147549Simp *
15147549Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16147549Simp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17147549Simp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18147549Simp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19147549Simp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20147549Simp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21147549Simp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22147549Simp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23147549Simp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24147549Simp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25147549Simp */
26147549Simp
27147549Simp#include <sys/cdefs.h>
28147549Simp__FBSDID("$FreeBSD: releng/10.2/sys/boot/efi/libefi/errno.c 164010 2006-11-05 22:03:04Z marcel $");
29147549Simp
30147549Simp#include <efi.h>
31147549Simp#include <efilib.h>
32147549Simp
33147549Simpint
34147549Simpefi_status_to_errno(EFI_STATUS status)
35147549Simp{
361541Srgrimes	int errno;
372531Swollman
381541Srgrimes	switch (status) {
391541Srgrimes	case EFI_ACCESS_DENIED:
401541Srgrimes		errno = EPERM;
412531Swollman		break;
422531Swollman
432531Swollman	case EFI_BUFFER_TOO_SMALL:
449209Swollman		errno = EOVERFLOW;
45118622Shsu		break;
46118622Shsu
47118622Shsu	case EFI_DEVICE_ERROR:
48118622Shsu	case EFI_VOLUME_CORRUPTED:
49118622Shsu		errno = EIO;
501541Srgrimes		break;
519209Swollman
52118622Shsu	case EFI_INVALID_PARAMETER:
53118622Shsu		errno = EINVAL;
541541Srgrimes		break;
551541Srgrimes
56190012Sbms	case EFI_MEDIA_CHANGED:
57190012Sbms		errno = ESTALE;
58190012Sbms		break;
59190012Sbms
60190012Sbms	case EFI_NO_MEDIA:
61190012Sbms		errno = ENXIO;
62190012Sbms		break;
63190012Sbms
64190012Sbms	case EFI_NOT_FOUND:
65190012Sbms		errno = ENOENT;
66190012Sbms		break;
67190012Sbms
68190012Sbms	case EFI_OUT_OF_RESOURCES:
69172467Ssilby		errno = ENOMEM;
70172467Ssilby		break;
71172467Ssilby
72166938Sbms	case EFI_UNSUPPORTED:
7314328Speter		errno = ENODEV;
741541Srgrimes		break;
75118622Shsu
76118622Shsu	case EFI_VOLUME_FULL:
771541Srgrimes		errno = ENOSPC;
7895759Stanimura		break;
79190148Sbms
8095759Stanimura	case EFI_WRITE_PROTECTED:
81190054Sbms		errno = EACCES;
8242777Sfenner		break;
831541Srgrimes
84129880Sphk	case 0:
85164033Srwatson		errno = 0;
8695759Stanimura		break;
8795759Stanimura
881541Srgrimes	default:
891541Srgrimes		errno = EDOOFUS;
9095759Stanimura		break;
9195759Stanimura	}
9280354Sfenner
932531Swollman	return (errno);
9495759Stanimura}
9595759Stanimura