VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/linux/RTSystemFirmware-linux.cpp@ 82968

Last change on this file since 82968 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1/* $Id: RTSystemFirmware-linux.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * IPRT - System firmware information, linux.
4 */
5
6/*
7 * Copyright (C) 2019-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include "internal/iprt.h"
32#include <iprt/system.h>
33
34#include <iprt/err.h>
35#include <iprt/file.h>
36#include <iprt/string.h>
37#include <iprt/linux/sysfs.h>
38
39
40/*********************************************************************************************************************************
41* Defined Constants And Macros *
42*********************************************************************************************************************************/
43/** Defines the UEFI Globals UUID that is used here as filename suffix (case sensitive). */
44#define VBOX_UEFI_UUID_GLOBALS "8be4df61-93ca-11d2-aa0d-00e098032b8c"
45
46
47RTDECL(int) RTSystemQueryFirmwareType(PRTSYSFWTYPE penmFirmwareType)
48{
49 if (RTLinuxSysFsExists("firmware/efi/"))
50 *penmFirmwareType = RTSYSFWTYPE_UEFI;
51 else if (RTLinuxSysFsExists(""))
52 *penmFirmwareType = RTSYSFWTYPE_BIOS;
53 else
54 {
55 *penmFirmwareType = RTSYSFWTYPE_INVALID;
56 return VERR_NOT_SUPPORTED;
57 }
58 return VINF_SUCCESS;
59}
60RT_EXPORT_SYMBOL(RTSystemQueryFirmwareType);
61
62
63RTDECL(int) RTSystemQueryFirmwareBoolean(RTSYSFWBOOL enmBoolean, bool *pfValue)
64{
65 *pfValue = false;
66
67 /*
68 * Translate the property to variable base filename.
69 */
70 const char *pszName;
71 switch (enmBoolean)
72 {
73 case RTSYSFWBOOL_SECURE_BOOT:
74 pszName = "firmware/efi/efivars/SecureBoot";
75 break;
76
77 default:
78 AssertReturn(enmBoolean > RTSYSFWBOOL_INVALID && enmBoolean < RTSYSFWBOOL_END, VERR_INVALID_PARAMETER);
79 return VERR_SYS_UNSUPPORTED_FIRMWARE_PROPERTY;
80
81 }
82
83 /*
84 * Try open and read the variable value.
85 */
86 RTFILE hFile;
87 int rc = RTLinuxSysFsOpen(&hFile, "%s-" VBOX_UEFI_UUID_GLOBALS, pszName);
88 /** @todo try other suffixes if file-not-found. */
89 if (RT_SUCCESS(rc))
90 {
91 uint8_t abBuf[16];
92 size_t cbRead = 0;
93 rc = RTLinuxSysFsReadFile(hFile, abBuf, sizeof(abBuf), &cbRead);
94 *pfValue = cbRead > 1 && abBuf[cbRead - 1] != 0;
95 RTFileClose(hFile);
96 }
97 else if (rc == VERR_FILE_NOT_FOUND || rc == VERR_PATH_NOT_FOUND)
98 rc = VINF_SUCCESS;
99 else if (rc == VERR_PERMISSION_DENIED)
100 rc = VERR_NOT_SUPPORTED;
101
102 return rc;
103}
104RT_EXPORT_SYMBOL(RTSystemQueryFirmwareBoolean);
105
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette