Nvram.cpp revision c4ccc0915f8ac8c1d8eb0565a17043dda0a666dd
/* $Id$ */
/** @file
* VBox NVRAM COM Class implementation.
*/
/*
* Copyright (C) 2012-2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "Nvram.h"
#include "ConsoleImpl.h"
#include "Global.h"
#include <iprt/critsect.h>
#include <iprt/semaphore.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Intstance data associated with PDMDRVINS.
*/
struct NVRAM
{
/** Pointer to the associated class instance. */
/** The NVRAM connector interface we provide to DevEFI. */
/** The root of the 'Vars' child of the driver config (i.e.
* VBoxInternal/Devices/efi/0/LUN#0/Config/Vars/).
* This node has one child node per NVRAM variable. */
/** The variable node used in the privous drvNvram_VarQueryByIndex call. */
/** The index pLastVarNode corresponds to. */
/** Whether to permanently save the variables or not. */
bool fPermanentSave;
};
/**
*/
{
}
{
if (mpDrv)
{
}
}
/**
* @interface_method_impl(PDMINVRAM,pfnVarStoreSeqEnd)
*/
{
return rc;
}
/**
* Converts the binary to a CFGM overlay binary string.
*
* @returns Pointer to a heap buffer (hand it to RTMemFree when done).
* @param pvBuf The binary data to convert.
* @param cbBuf The number of bytes to convert.
*/
{
static char s_szPrefix[] = "bytes:";
if (pszStr)
{
int rc = RTBase64Encode(pvBuf, cbBuf, &pszStr[sizeof(s_szPrefix) - 1], cbBuf - sizeof(s_szPrefix) + 1, NULL);
if (RT_FAILURE(rc))
{
}
}
return pszStr;
}
/**
* @interface_method_impl(PDMINVRAM,pfnVarStoreSeqPut)
*/
{
int rc = VINF_SUCCESS;
{
char szExtraName[256];
"VBoxInternal/Devices/efi/0/LUN#0/Config/Vars/%4u/", idxVariable);
char szAttribs[32];
char szUuid[RTUUID_STR_LENGTH];
if (pszValue)
{
const char *apszTodo[] =
{
"Name", pszName,
"Uuid", szUuid,
"Attribs", szAttribs,
"Value", pszValue,
};
{
try
{
{
LogRel(("drvNvram_deleteVar: SetExtraData(%s,%s) returned %Rhrc\n", szExtraName, apszTodo[i + 1], hrc));
}
}
catch (...)
{
LogRel(("drvNvram_deleteVar: SetExtraData(%s,%s) threw exception\n", szExtraName, apszTodo[i + 1]));
}
}
}
else
rc = VERR_NO_MEMORY;
}
return rc;
}
/**
* Deletes a variable.
*
* @param pThis The NVRAM driver instance data.
* @param pszVarNodeNm The variable node name.
*/
{
char szExtraName[256];
"VBoxInternal/Devices/efi/0/LUN#0/Config/Vars/%s/", pszVarNodeNm);
for (unsigned i = 0; i < RT_ELEMENTS(s_apszValueNames); i++)
{
try
{
HRESULT hrc = pThis->pNvram->getParent()->machine()->SetExtraData(Bstr(szExtraName).raw(), Bstr().raw());
}
catch (...)
{
}
}
}
/**
* @interface_method_impl(PDMINVRAM,pfnVarStoreSeqBegin)
*/
{
int rc = VINF_SUCCESS;
{
/*
* Remove all existing variables.
*/
for (PCFGMNODE pVarNode = CFGMR3GetFirstChild(pThis->pCfgVarRoot); pVarNode; pVarNode = CFGMR3GetNextChild(pVarNode))
{
char szName[128];
if (RT_SUCCESS(rc))
else
}
}
return rc;
}
/**
* @interface_method_impl(PDMINVRAMCONNECTOR,pfnVarQueryByIndex)
*/
{
/*
* Find the requested variable node.
*/
else
{
}
if (!pVarNode)
return VERR_NOT_FOUND;
/* cache it */
/*
* Read the variable node.
*/
char szUuid[RTUUID_STR_LENGTH];
return VINF_SUCCESS;
}
/**
* @interface_method_impl(PDMIBASE,pfnQueryInterface)
*/
{
return NULL;
}
/**
* @interface_method_impl(PDMDRVREG,pfnDestruct)
*/
{
}
/**
* @interface_method_impl(PDMDRVREG,pfnConstruct)
*/
{
/*
* Initalize instance data variables first.
*/
//pThis->pNvram = NULL;
//pThis->cLoadedVariables = 0;
//pThis->fPermanentSave = false;
//pThis->pLastVarNode = NULL;
/*
* Validate and read configuration.
*/
"PermanentSave\0"))
("Configuration error: Not possible to attach anything to this driver!\n"),
/*
* Let the associated class instance know about us.
*/
return VINF_SUCCESS;
}
{
/* u32Version */
/* szName[32] */
"NvramStorage",
/* szRCMod[32] */
"",
/* szR0Mod[32] */
"",
/* pszDescription */
"NVRAM Main Driver",
/* fFlags */
/* fClass */
/* cMaxInstances */
1,
/* cbInstance */
sizeof(NVRAM),
/* pfnConstruct */
/* pfnDestruct */
/* pfnRelocate */
NULL,
/* pfnIOCtl */
NULL,
/* pfnPowerOn */
NULL,
/* pfnReset */
NULL,
/* pfnSuspend */
NULL,
/* pfnResume */
NULL,
/* pfnAttach */
NULL,
/* pfnDetach */
NULL,
/* pfnPowerOff */
NULL,
/* pfnSoftReset */
NULL,
/* u32VersionEnd */
};
/* vi: set tabstop=4 shiftwidth=4 expandtab: */