NvVarsFileLib.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /** @file
  2. Save Non-Volatile Variables to a file system.
  3. Copyright (c) 2019 Intel Corporation. All rights reserved. <BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "NvVarsFileLib.h"
  7. #include <Library/DebugLib.h>
  8. #include <Library/NvVarsFileLib.h>
  9. EFI_HANDLE mNvVarsFileLibFsHandle = NULL;
  10. /**
  11. Attempts to connect the NvVarsFileLib to the specified file system.
  12. @param[in] FsHandle - Handle for a gEfiSimpleFileSystemProtocolGuid instance
  13. @return The EFI_STATUS while attempting to connect the NvVarsFileLib
  14. to the file system instance.
  15. @retval EFI_SUCCESS - The given file system was connected successfully
  16. **/
  17. EFI_STATUS
  18. EFIAPI
  19. ConnectNvVarsToFileSystem (
  20. IN EFI_HANDLE FsHandle
  21. )
  22. {
  23. EFI_STATUS Status;
  24. //
  25. // We might fail to load the variable, since the file system initially
  26. // will not have the NvVars file.
  27. //
  28. LoadNvVarsFromFs (FsHandle);
  29. //
  30. // We must be able to save the variables successfully to the file system
  31. // to have connected successfully.
  32. //
  33. Status = SaveNvVarsToFs (FsHandle);
  34. if (!EFI_ERROR (Status)) {
  35. mNvVarsFileLibFsHandle = FsHandle;
  36. }
  37. return Status;
  38. }
  39. /**
  40. Update non-volatile variables stored on the file system.
  41. @return The EFI_STATUS while attempting to update the variable on
  42. the connected file system.
  43. @retval EFI_SUCCESS - The non-volatile variables were saved to the disk
  44. @retval EFI_NOT_STARTED - A file system has not been connected
  45. **/
  46. EFI_STATUS
  47. EFIAPI
  48. UpdateNvVarsOnFileSystem (
  49. )
  50. {
  51. if (mNvVarsFileLibFsHandle == NULL) {
  52. //
  53. // A file system had not been connected to the library.
  54. //
  55. return EFI_NOT_STARTED;
  56. } else {
  57. return SaveNvVarsToFs (mNvVarsFileLibFsHandle);
  58. }
  59. }