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 __FBSDID("$FreeBSD: head/sys/boot/efi/libefi/errno.c 164010 2006-11-05 22:03:04Z marcel $"); 29 30 #include <efi.h> 31 #include <efilib.h> 32 33 int 34 efi_status_to_errno(EFI_STATUS status) 35 { 36 int errno; 37 38 switch (status) { 39 case EFI_ACCESS_DENIED: 40 errno = EPERM; 41 break; 42 43 case EFI_BUFFER_TOO_SMALL: 44 errno = EOVERFLOW; 45 break; 46 47 case EFI_DEVICE_ERROR: 48 case EFI_VOLUME_CORRUPTED: 49 errno = EIO; 50 break; 51 52 case EFI_INVALID_PARAMETER: 53 errno = EINVAL; 54 break; 55 56 case EFI_MEDIA_CHANGED: 57 errno = ESTALE; 58 break; 59 60 case EFI_NO_MEDIA: 61 errno = ENXIO; 62 break; 63 64 case EFI_NOT_FOUND: 65 errno = ENOENT; 66 break; 67 68 case EFI_OUT_OF_RESOURCES: 69 errno = ENOMEM; 70 break; 71 72 case EFI_UNSUPPORTED: 73 errno = ENODEV; 74 break; 75 76 case EFI_VOLUME_FULL: 77 errno = ENOSPC; 78 break; 79 80 case EFI_WRITE_PROTECTED: 81 errno = EACCES; 82 break; 83 84 case 0: 85 errno = 0; 86 break; 87 88 default: 89 errno = EDOOFUS; 90 break; 91 } 92 93 return (errno); 94 } 95