VirtualBox

Changeset 81137 in vbox for trunk/src/VBox/Runtime/r3/linux


Ignore:
Timestamp:
Oct 8, 2019 8:28:31 AM (5 years ago)
Author:
vboxsync
Message:

IPRT/RTSystem*Firmware: Simplified the interface and made it follow the style of the rest of RTSystemQuery*. Added RTSystemFirmwareTypeName() to avoid duplicating enum->string code over and over again.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/linux/RTSystemFirmware-linux.cpp

    r81068 r81137  
    4545
    4646
    47 RTDECL(int) RTSystemFirmwareQueryType(PRTSYSFWTYPE penmFirmwareType)
     47RTDECL(int) RTSystemQueryFirmwareType(PRTSYSFWTYPE penmFirmwareType)
    4848{
    4949    if (RTLinuxSysFsExists("firmware/efi/"))
     
    5858    return VINF_SUCCESS;
    5959}
    60 RT_EXPORT_SYMBOL(RTSystemFirmwareQueryType);
     60RT_EXPORT_SYMBOL(RTSystemQueryFirmwareType);
    6161
    6262
    63 RTDECL(void) RTSystemFirmwareFreeValue(PRTSYSFWVALUE pValue)
     63RTDECL(int) RTSystemQueryFirmwareBoolean(RTSYSFWPROP enmProp, bool *pfValue)
    6464{
    65     RT_NOREF(pValue);
    66 }
    67 RT_EXPORT_SYMBOL(RTSystemFirmwareFreeValue);
    68 
    69 
    70 RTDECL(int) RTSystemFirmwareQueryValue(RTSYSFWPROP enmProp, PRTSYSFWVALUE pValue)
    71 {
    72     RT_ZERO(*pValue);
     65    *pfValue = false;
    7366
    7467    /*
    75      * Translate the property into type and variable base filename.
     68     * Translate the property to variable base filename.
    7669     */
    7770    const char *pszName;
     
    7972    {
    8073        case RTSYSFWPROP_SECURE_BOOT:
    81             pValue->enmType = RTSYSFWVALUETYPE_BOOLEAN;
    8274            pszName = "firmware/efi/efivars/SecureBoot";
    8375            break;
     
    9587    int rc = RTLinuxSysFsOpen(&hFile, "%s-" VBOX_UEFI_UUID_GLOBALS, pszName);
    9688    /** @todo try other suffixes if file-not-found. */
    97 
    98     switch (pValue->enmType)
     89    if (RT_SUCCESS(rc))
    9990    {
    100         case RTSYSFWVALUETYPE_BOOLEAN:
    101         {
    102             if (RT_SUCCESS(rc))
    103             {
    104                 uint8_t abBuf[16];
    105                 size_t  cbRead = 0;
    106                 rc = RTLinuxSysFsReadFile(hFile, abBuf, sizeof(abBuf), &cbRead);
    107                 pValue->u.fVal = cbRead > 1 && abBuf[cbRead - 1] != 0;
    108                 RTFileClose(hFile);
    109             }
    110             else if (rc == VERR_FILE_NOT_FOUND || rc == VERR_PATH_NOT_FOUND)
    111                 rc = VINF_SUCCESS;
    112             else if (rc == VERR_PERMISSION_DENIED)
    113                 rc = VERR_NOT_SUPPORTED;
    114             break;
    115         }
    116 
    117         default:
    118             AssertFailedReturn(VERR_INTERNAL_ERROR);
     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);
    11996    }
     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;
    120101
    121102    return rc;
    122103}
    123 RT_EXPORT_SYMBOL(RTSystemFirmwareQueryValue);
     104RT_EXPORT_SYMBOL(RTSystemQueryFirmwareBoolean);
    124105
Note: See TracChangeset for help on using the changeset viewer.

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