OVMF: Add support for saving the NV variables to disk following each SetVariable...
[edk2.git] / OvmfPkg / Library / NvVarsFileLib / NvVarsFileLib.c
blob62fee6f03136eddf55135a359942311f6ca8ddc5
1 /** @file
2 Save Non-Volatile Variables to a file system.
4 Copyright (c) 2009, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 **/
15 #include "NvVarsFileLib.h"
16 #include <Library/DebugLib.h>
17 #include <Library/NvVarsFileLib.h>
19 EFI_HANDLE mNvVarsFileLibFsHandle = NULL;
22 /**
23 Attempts to connect the NvVarsFileLib to the specified file system.
25 @param[in] FsHandle - Handle for a gEfiSimpleFileSystemProtocolGuid instance
27 @return The EFI_STATUS while attempting to connect the NvVarsFileLib
28 to the file system instance.
29 @retval EFI_SUCCESS - The given file system was connected successfully
31 **/
32 EFI_STATUS
33 EFIAPI
34 ConnectNvVarsToFileSystem (
35 IN EFI_HANDLE FsHandle
38 EFI_STATUS Status;
41 // We might fail to load the variable, since the file system initially
42 // will not have the NvVars file.
44 LoadNvVarsFromFs (FsHandle);
47 // We must be able to save the variables successfully to the file system
48 // to have connected successfully.
50 Status = SaveNvVarsToFs (FsHandle);
51 if (!EFI_ERROR (Status)) {
52 mNvVarsFileLibFsHandle = FsHandle;
55 return Status;
59 /**
60 Update non-volatile variables stored on the file system.
62 @return The EFI_STATUS while attempting to update the variable on
63 the connected file system.
64 @retval EFI_SUCCESS - The non-volatile variables were saved to the disk
65 @retval EFI_NOT_STARTED - A file system has not been connected
67 **/
68 EFI_STATUS
69 EFIAPI
70 UpdateNvVarsOnFileSystem (
73 if (mNvVarsFileLibFsHandle == NULL) {
75 // A file system had not been connected to the library.
77 return EFI_NOT_STARTED;
78 } else {
79 return SaveNvVarsToFs (mNvVarsFileLibFsHandle);