]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Variable/RuntimeDxe/VarCheck.c
MdeModulePkg Variable: Return GetVariable() attr if EFI_BUFFER_TOO_SMALL
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / RuntimeDxe / VarCheck.c
CommitLineData
efb01a10 1/** @file\r
8021f4c7
SZ
2 Implementation functions and structures for var check protocol\r
3 and variable lock protocol based on VarCheckLib.\r
efb01a10
SZ
4\r
5Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
9d510e61 6SPDX-License-Identifier: BSD-2-Clause-Patent\r
efb01a10
SZ
7\r
8**/\r
9\r
10#include "Variable.h"\r
efb01a10
SZ
11\r
12/**\r
8021f4c7
SZ
13 Mark a variable that will become read-only after leaving the DXE phase of execution.\r
14 Write request coming from SMM environment through EFI_SMM_VARIABLE_PROTOCOL is allowed.\r
efb01a10 15\r
8021f4c7
SZ
16 @param[in] This The VARIABLE_LOCK_PROTOCOL instance.\r
17 @param[in] VariableName A pointer to the variable name that will be made read-only subsequently.\r
18 @param[in] VendorGuid A pointer to the vendor GUID that will be made read-only subsequently.\r
efb01a10 19\r
8021f4c7
SZ
20 @retval EFI_SUCCESS The variable specified by the VariableName and the VendorGuid was marked\r
21 as pending to be read-only.\r
22 @retval EFI_INVALID_PARAMETER VariableName or VendorGuid is NULL.\r
23 Or VariableName is an empty string.\r
24 @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has\r
25 already been signaled.\r
26 @retval EFI_OUT_OF_RESOURCES There is not enough resource to hold the lock request.\r
efb01a10
SZ
27**/\r
28EFI_STATUS\r
29EFIAPI\r
8021f4c7
SZ
30VariableLockRequestToLock (\r
31 IN CONST EDKII_VARIABLE_LOCK_PROTOCOL *This,\r
32 IN CHAR16 *VariableName,\r
33 IN EFI_GUID *VendorGuid\r
efb01a10
SZ
34 )\r
35{\r
36 EFI_STATUS Status;\r
8021f4c7 37 VAR_CHECK_VARIABLE_PROPERTY Property;\r
efb01a10 38\r
8021f4c7 39 AcquireLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r
efb01a10 40\r
8021f4c7
SZ
41 Status = VarCheckLibVariablePropertyGet (VariableName, VendorGuid, &Property);\r
42 if (!EFI_ERROR (Status)) {\r
43 Property.Property |= VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY;\r
44 } else {\r
45 Property.Revision = VAR_CHECK_VARIABLE_PROPERTY_REVISION;\r
46 Property.Property = VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY;\r
47 Property.Attributes = 0;\r
48 Property.MinSize = 1;\r
49 Property.MaxSize = MAX_UINTN;\r
efb01a10 50 }\r
8021f4c7 51 Status = VarCheckLibVariablePropertySet (VariableName, VendorGuid, &Property);\r
efb01a10 52\r
8021f4c7 53 DEBUG ((EFI_D_INFO, "[Variable] Lock: %g:%s %r\n", VendorGuid, VariableName, Status));\r
efb01a10 54\r
8021f4c7 55 ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r
efb01a10 56\r
8021f4c7 57 return Status;\r
efb01a10
SZ
58}\r
59\r
60/**\r
61 Register SetVariable check handler.\r
62\r
63 @param[in] Handler Pointer to check handler.\r
64\r
65 @retval EFI_SUCCESS The SetVariable check handler was registered successfully.\r
66 @retval EFI_INVALID_PARAMETER Handler is NULL.\r
67 @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has\r
68 already been signaled.\r
69 @retval EFI_OUT_OF_RESOURCES There is not enough resource for the SetVariable check handler register request.\r
70 @retval EFI_UNSUPPORTED This interface is not implemented.\r
71 For example, it is unsupported in VarCheck protocol if both VarCheck and SmmVarCheck protocols are present.\r
72\r
73**/\r
74EFI_STATUS\r
75EFIAPI\r
76VarCheckRegisterSetVariableCheckHandler (\r
77 IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler\r
78 )\r
79{\r
80 EFI_STATUS Status;\r
81\r
fa0737a8 82 AcquireLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r
8021f4c7 83 Status = VarCheckLibRegisterSetVariableCheckHandler (Handler);\r
fa0737a8
SZ
84 ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r
85\r
86 return Status;\r
efb01a10
SZ
87}\r
88\r
efb01a10
SZ
89/**\r
90 Variable property set.\r
91\r
92 @param[in] Name Pointer to the variable name.\r
93 @param[in] Guid Pointer to the vendor GUID.\r
94 @param[in] VariableProperty Pointer to the input variable property.\r
95\r
96 @retval EFI_SUCCESS The property of variable specified by the Name and Guid was set successfully.\r
97 @retval EFI_INVALID_PARAMETER Name, Guid or VariableProperty is NULL, or Name is an empty string,\r
98 or the fields of VariableProperty are not valid.\r
99 @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has\r
100 already been signaled.\r
101 @retval EFI_OUT_OF_RESOURCES There is not enough resource for the variable property set request.\r
102\r
103**/\r
104EFI_STATUS\r
105EFIAPI\r
106VarCheckVariablePropertySet (\r
107 IN CHAR16 *Name,\r
108 IN EFI_GUID *Guid,\r
109 IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty\r
110 )\r
111{\r
8021f4c7 112 EFI_STATUS Status;\r
efb01a10 113\r
efb01a10 114 AcquireLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r
8021f4c7 115 Status = VarCheckLibVariablePropertySet (Name, Guid, VariableProperty);\r
efb01a10
SZ
116 ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r
117\r
118 return Status;\r
119}\r
120\r
4edb1866
SZ
121/**\r
122 Variable property get.\r
123\r
124 @param[in] Name Pointer to the variable name.\r
125 @param[in] Guid Pointer to the vendor GUID.\r
126 @param[out] VariableProperty Pointer to the output variable property.\r
127\r
128 @retval EFI_SUCCESS The property of variable specified by the Name and Guid was got successfully.\r
129 @retval EFI_INVALID_PARAMETER Name, Guid or VariableProperty is NULL, or Name is an empty string.\r
130 @retval EFI_NOT_FOUND The property of variable specified by the Name and Guid was not found.\r
131\r
132**/\r
133EFI_STATUS\r
134EFIAPI\r
135VarCheckVariablePropertyGet (\r
136 IN CHAR16 *Name,\r
137 IN EFI_GUID *Guid,\r
138 OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty\r
139 )\r
140{\r
141 EFI_STATUS Status;\r
142\r
4edb1866 143 AcquireLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r
8021f4c7 144 Status = VarCheckLibVariablePropertyGet (Name, Guid, VariableProperty);\r
efb01a10
SZ
145 ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r
146\r
4edb1866 147 return Status;\r
efb01a10
SZ
148}\r
149\r