]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.c
62fee6f03136eddf55135a359942311f6ca8ddc5
[mirror_edk2.git] / OvmfPkg / Library / NvVarsFileLib / NvVarsFileLib.c
1 /** @file
2 Save Non-Volatile Variables to a file system.
3
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
9
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.
12
13 **/
14
15 #include "NvVarsFileLib.h"
16 #include <Library/DebugLib.h>
17 #include <Library/NvVarsFileLib.h>
18
19 EFI_HANDLE mNvVarsFileLibFsHandle = NULL;
20
21
22 /**
23 Attempts to connect the NvVarsFileLib to the specified file system.
24
25 @param[in] FsHandle - Handle for a gEfiSimpleFileSystemProtocolGuid instance
26
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
30
31 **/
32 EFI_STATUS
33 EFIAPI
34 ConnectNvVarsToFileSystem (
35 IN EFI_HANDLE FsHandle
36 )
37 {
38 EFI_STATUS Status;
39
40 //
41 // We might fail to load the variable, since the file system initially
42 // will not have the NvVars file.
43 //
44 LoadNvVarsFromFs (FsHandle);
45
46 //
47 // We must be able to save the variables successfully to the file system
48 // to have connected successfully.
49 //
50 Status = SaveNvVarsToFs (FsHandle);
51 if (!EFI_ERROR (Status)) {
52 mNvVarsFileLibFsHandle = FsHandle;
53 }
54
55 return Status;
56 }
57
58
59 /**
60 Update non-volatile variables stored on the file system.
61
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
66
67 **/
68 EFI_STATUS
69 EFIAPI
70 UpdateNvVarsOnFileSystem (
71 )
72 {
73 if (mNvVarsFileLibFsHandle == NULL) {
74 //
75 // A file system had not been connected to the library.
76 //
77 return EFI_NOT_STARTED;
78 } else {
79 return SaveNvVarsToFs (mNvVarsFileLibFsHandle);
80 }
81 }
82
83