/*-1* Copyright (c) 2006 Marcel Moolenaar2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7*8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR15* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES16* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.17* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,18* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT19* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,20* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY21* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT22* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF23* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.24*/2526#include <efi.h>27#include <efilib.h>2829EFI_STATUS30errno_to_efi_status(int errno)31{32EFI_STATUS status;3334switch (errno) {35case EPERM:36status = EFI_ACCESS_DENIED;37break;3839case EOVERFLOW:40status = EFI_BUFFER_TOO_SMALL;41break;4243case EIO:44status = EFI_DEVICE_ERROR;45break;4647case EINVAL:48status = EFI_INVALID_PARAMETER;49break;5051case ESTALE:52status = EFI_MEDIA_CHANGED;53break;5455case ENXIO:56status = EFI_NO_MEDIA;57break;5859case ENOENT:60status = EFI_NOT_FOUND;61break;6263case ENOMEM:64status = EFI_OUT_OF_RESOURCES;65break;6667case ENOTSUP:68case ENODEV:69status = EFI_UNSUPPORTED;70break;7172case ENOSPC:73status = EFI_VOLUME_FULL;74break;7576case EACCES:77status = EFI_WRITE_PROTECTED;78break;7980case 0:81status = EFI_SUCCESS;82break;8384default:85status = EFI_DEVICE_ERROR;86break;87}8889return (status);90}9192int93efi_status_to_errno(EFI_STATUS status)94{95int errno;9697switch (status) {98case EFI_ACCESS_DENIED:99errno = EPERM;100break;101102case EFI_BUFFER_TOO_SMALL:103errno = EOVERFLOW;104break;105106case EFI_DEVICE_ERROR:107case EFI_VOLUME_CORRUPTED:108errno = EIO;109break;110111case EFI_INVALID_PARAMETER:112errno = EINVAL;113break;114115case EFI_MEDIA_CHANGED:116errno = ESTALE;117break;118119case EFI_NO_MEDIA:120errno = ENXIO;121break;122123case EFI_NOT_FOUND:124errno = ENOENT;125break;126127case EFI_OUT_OF_RESOURCES:128errno = ENOMEM;129break;130131case EFI_UNSUPPORTED:132errno = ENODEV;133break;134135case EFI_VOLUME_FULL:136errno = ENOSPC;137break;138139case EFI_WRITE_PROTECTED:140errno = EACCES;141break;142143case 0:144errno = 0;145break;146147default:148errno = EDOOFUS;149break;150}151152return (errno);153}154155156