-/**\r
- Update the Cache with Variable information. These are the same \r
- arguments as the EFI Variable services.\r
-\r
- @param[in] VariableName Name of variable\r
- @param[in] VendorGuid Guid of variable\r
- @param[in] Attributes Attribues of the variable\r
- @param[in] DataSize Size of data. 0 means delete\r
- @param[in] Data Variable data\r
-\r
-**/\r
-VOID\r
-UpdateVariableCache (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID *VendorGuid,\r
- IN UINT32 Attributes,\r
- IN UINTN DataSize,\r
- IN VOID *Data\r
- )\r
-{\r
- VARIABLE_CACHE_ENTRY *Entry;\r
- UINTN Index;\r
-\r
- if (EfiAtRuntime ()) {\r
- //\r
- // Don't use the cache at runtime\r
- // \r
- return;\r
- }\r
-\r
- for (Index = 0, Entry = mVariableCache; Index < sizeof (mVariableCache)/sizeof (VARIABLE_CACHE_ENTRY); Index++, Entry++) {\r
- if (CompareGuid (VendorGuid, Entry->Guid)) {\r
- if (StrCmp (VariableName, Entry->Name) == 0) { \r
- Entry->Attributes = Attributes;\r
- if (DataSize == 0) {\r
- //\r
- // Delete Case\r
- //\r
- if (Entry->DataSize != 0) {\r
- FreePool (Entry->Data);\r
- }\r
- Entry->DataSize = DataSize;\r
- } else if (DataSize == Entry->DataSize) {\r
- CopyMem (Entry->Data, Data, DataSize);\r
- } else {\r
- Entry->Data = AllocatePool (DataSize);\r
- ASSERT (Entry->Data != NULL);\r
-\r
- Entry->DataSize = DataSize;\r
- CopyMem (Entry->Data, Data, DataSize);\r
- }\r
- }\r
- }\r
- }\r
-}\r
-\r
-\r
-/**\r
- Search the cache to check if the variable is in it.\r
-\r
- This function searches the variable cache. If the variable to find exists, return its data\r
- and attributes.\r
-\r
- @param VariableName A Null-terminated Unicode string that is the name of the vendor's\r
- variable. Each VariableName is unique for each \r
- VendorGuid.\r
- @param VendorGuid A unique identifier for the vendor\r
- @param Attributes Pointer to the attributes bitmask of the variable for output.\r
- @param DataSize On input, size of the buffer of Data.\r
- On output, size of the variable's data.\r
- @param Data Pointer to the data buffer for output.\r
-\r
- @retval EFI_SUCCESS VariableGuid & VariableName data was returned.\r
- @retval EFI_NOT_FOUND No matching variable found in cache.\r
- @retval EFI_BUFFER_TOO_SMALL *DataSize is smaller than size of the variable's data to return.\r
-\r
-**/\r
-EFI_STATUS\r
-FindVariableInCache (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID *VendorGuid,\r
- OUT UINT32 *Attributes OPTIONAL,\r
- IN OUT UINTN *DataSize,\r
- OUT VOID *Data\r
- )\r
-{\r
- VARIABLE_CACHE_ENTRY *Entry;\r
- UINTN Index;\r
-\r
- if (EfiAtRuntime ()) {\r
- // Don't use the cache at runtime\r
- return EFI_NOT_FOUND;\r
- }\r
-\r
- for (Index = 0, Entry = mVariableCache; Index < sizeof (mVariableCache)/sizeof (VARIABLE_CACHE_ENTRY); Index++, Entry++) {\r
- if (CompareGuid (VendorGuid, Entry->Guid)) {\r
- if (StrCmp (VariableName, Entry->Name) == 0) {\r
- if (Entry->DataSize == 0) {\r
- // Variable was deleted so return not found\r
- return EFI_NOT_FOUND;\r
- } else if (Entry->DataSize > *DataSize) {\r
- // If the buffer is too small return correct size\r
- *DataSize = Entry->DataSize;\r
- return EFI_BUFFER_TOO_SMALL;\r
- } else {\r
- *DataSize = Entry->DataSize;\r
- // Return the data\r
- CopyMem (Data, Entry->Data, Entry->DataSize);\r
- if (Attributes != NULL) {\r
- *Attributes = Entry->Attributes;\r
- }\r
- return EFI_SUCCESS;\r
- }\r
- }\r
- }\r
- }\r
- \r
- return EFI_NOT_FOUND;\r
-}\r
-\r