public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdePkg/UefiLib: Add a new API GetVariable3
@ 2019-01-07  4:09 Jiansong Xu
  2019-01-29  3:07 ` Gao, Liming
  0 siblings, 1 reply; 2+ messages in thread
From: Jiansong Xu @ 2019-01-07  4:09 UTC (permalink / raw)
  To: edk2-devel; +Cc: jiansonx

From: jiansonx <jiansongx.xu@intel.com>

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1396
Add a new API GetVariable3, which can return the attributes of a variable during reading it.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jiansong Xu <jiansongx.xu@intel.com>
Cc: Liming Gao <liming.gao@intel.com
---
 MdePkg/Include/Library/UefiLib.h | 33 ++++++++++++++++
 MdePkg/Library/UefiLib/UefiLib.c | 81 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 114 insertions(+)

diff --git a/MdePkg/Include/Library/UefiLib.h b/MdePkg/Include/Library/UefiLib.h
index 468bffc3cb..929ee8afb7 100644
--- a/MdePkg/Include/Library/UefiLib.h
+++ b/MdePkg/Include/Library/UefiLib.h
@@ -777,6 +777,39 @@ GetEfiGlobalVariable2 (
   OUT UINTN          *Size OPTIONAL
   );
 
+/** Return the attributes of the variable. 
+
+  Returns the status whether get the variable success. The function retrieves
+  variable  through the UEFI Runtime Service GetVariable().  The
+  returned buffer is allocated using AllocatePool().  The caller is responsible
+  for freeing this buffer with FreePool().  The attributes are returned if
+  the caller provides a valid Attribute parameter.
+
+  If Name  is NULL, then ASSERT().
+  If Guid  is NULL, then ASSERT().
+  If Value is NULL, then ASSERT().
+
+  @param[in]  Name  The pointer to a Null-terminated Unicode string.
+  @param[in]  Guid  The pointer to an EFI_GUID structure
+  @param[out] Value The buffer point saved the variable info.
+  @param[out] Size  The buffer size of the variable.
+  @param[out] Attr  The pointer to the variable attributes as found in var store
+
+  @retval EFI_OUT_OF_RESOURCES      Allocate buffer failed.
+  @retval EFI_SUCCESS               Find the specified variable.
+  @retval Others Errors             Return errors from call to gRT->GetVariable.
+
+**/
+EFI_STATUS
+EFIAPI
+GetVariable3(
+  IN CONST CHAR16       *Name,
+  IN CONST EFI_GUID     *Guid,
+     OUT VOID           **Value,
+     OUT UINTN          *Size OPTIONAL,
+     OUT UINT32         *Attr OPTIONAL
+  );
+
 /**
   Returns a pointer to an allocated buffer that contains the best matching language
   from a set of supported languages.
diff --git a/MdePkg/Library/UefiLib/UefiLib.c b/MdePkg/Library/UefiLib/UefiLib.c
index 39d0ce2b21..475017690c 100644
--- a/MdePkg/Library/UefiLib/UefiLib.c
+++ b/MdePkg/Library/UefiLib/UefiLib.c
@@ -1439,6 +1439,87 @@ GetVariable2 (
   return Status;
 }
 
+/** Return the attributes of the variable.
+
+  Returns the status whether get the variable success. The function retrieves
+  variable  through the UEFI Runtime Service GetVariable().  The
+  returned buffer is allocated using AllocatePool().  The caller is responsible
+  for freeing this buffer with FreePool().  The attributes are returned if
+  the caller provides a valid Attribute parameter.
+
+  If Name  is NULL, then ASSERT().
+  If Guid  is NULL, then ASSERT().
+  If Value is NULL, then ASSERT().
+
+  @param[in]  Name  The pointer to a Null-terminated Unicode string.
+  @param[in]  Guid  The pointer to an EFI_GUID structure
+  @param[out] Value The buffer point saved the variable info.
+  @param[out] Size  The buffer size of the variable.
+  @param[out] Attr  The pointer to the variable attributes as found in var store
+
+  @retval EFI_OUT_OF_RESOURCES      Allocate buffer failed.
+  @retval EFI_SUCCESS               Find the specified variable.
+  @retval Others Errors             Return errors from call to gRT->GetVariable.
+
+**/
+EFI_STATUS
+EFIAPI
+GetVariable3(
+  IN CONST CHAR16       *Name,
+  IN CONST EFI_GUID     *Guid,
+     OUT VOID           **Value,
+     OUT UINTN          *Size OPTIONAL,
+     OUT UINT32         *Attr OPTIONAL
+  )
+{
+  EFI_STATUS  Status;
+  UINTN       BufferSize;
+
+  ASSERT(Name != NULL && Guid != NULL && Value != NULL);
+
+  //
+  // Try to get the variable size.
+  //
+  BufferSize = 0;
+  *Value = NULL;
+  if (Size != NULL) {
+    *Size = 0;
+  }
+
+  if (Attr != NULL) {
+    *Attr = 0;
+  }
+
+  Status = gRT->GetVariable((CHAR16 *)Name, (EFI_GUID *)Guid, Attr, &BufferSize, *Value);
+  if (Status != EFI_BUFFER_TOO_SMALL) {
+    return Status;
+  }
+
+  //
+  // Allocate buffer to get the variable.
+  //
+  *Value = AllocatePool(BufferSize);
+  ASSERT(*Value != NULL);
+  if (*Value == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  //
+  // Get the variable data.
+  //
+  Status = gRT->GetVariable((CHAR16 *)Name, (EFI_GUID *)Guid, Attr, &BufferSize, *Value);
+  if (EFI_ERROR(Status)) {
+    FreePool(*Value);
+    *Value = NULL;
+  }
+
+  if (Size != NULL) {
+    *Size = BufferSize;
+  }
+
+  return Status;
+}
+
 /**
   Returns a pointer to an allocated buffer that contains the contents of a
   variable retrieved through the UEFI Runtime Service GetVariable().  This
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] MdePkg/UefiLib: Add a new API GetVariable3
  2019-01-07  4:09 [PATCH] MdePkg/UefiLib: Add a new API GetVariable3 Jiansong Xu
@ 2019-01-29  3:07 ` Gao, Liming
  0 siblings, 0 replies; 2+ messages in thread
From: Gao, Liming @ 2019-01-29  3:07 UTC (permalink / raw)
  To: Xu, JiansongX, edk2-devel@lists.01.org; +Cc: Xu, JiansongX

Jiansong:
  The patch is good. Reviewed-by: Liming Gao <liming.gao@intel.com>
  
  Besides, this patch is from MS Mu, please keep original patch author. Don't need to send the patch again. 

Thanks
LIming
> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Jiansong Xu
> Sent: Monday, January 7, 2019 12:09 PM
> To: edk2-devel@lists.01.org
> Cc: Xu, JiansongX <jiansongx.xu@intel.com>
> Subject: [edk2] [PATCH] MdePkg/UefiLib: Add a new API GetVariable3
> 
> From: jiansonx <jiansongx.xu@intel.com>
> 
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1396
> Add a new API GetVariable3, which can return the attributes of a variable during reading it.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Jiansong Xu <jiansongx.xu@intel.com>
> Cc: Liming Gao <liming.gao@intel.com
> ---
>  MdePkg/Include/Library/UefiLib.h | 33 ++++++++++++++++
>  MdePkg/Library/UefiLib/UefiLib.c | 81 ++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 114 insertions(+)
> 
> diff --git a/MdePkg/Include/Library/UefiLib.h b/MdePkg/Include/Library/UefiLib.h
> index 468bffc3cb..929ee8afb7 100644
> --- a/MdePkg/Include/Library/UefiLib.h
> +++ b/MdePkg/Include/Library/UefiLib.h
> @@ -777,6 +777,39 @@ GetEfiGlobalVariable2 (
>    OUT UINTN          *Size OPTIONAL
>    );
> 
> +/** Return the attributes of the variable.
> +
> +  Returns the status whether get the variable success. The function retrieves
> +  variable  through the UEFI Runtime Service GetVariable().  The
> +  returned buffer is allocated using AllocatePool().  The caller is responsible
> +  for freeing this buffer with FreePool().  The attributes are returned if
> +  the caller provides a valid Attribute parameter.
> +
> +  If Name  is NULL, then ASSERT().
> +  If Guid  is NULL, then ASSERT().
> +  If Value is NULL, then ASSERT().
> +
> +  @param[in]  Name  The pointer to a Null-terminated Unicode string.
> +  @param[in]  Guid  The pointer to an EFI_GUID structure
> +  @param[out] Value The buffer point saved the variable info.
> +  @param[out] Size  The buffer size of the variable.
> +  @param[out] Attr  The pointer to the variable attributes as found in var store
> +
> +  @retval EFI_OUT_OF_RESOURCES      Allocate buffer failed.
> +  @retval EFI_SUCCESS               Find the specified variable.
> +  @retval Others Errors             Return errors from call to gRT->GetVariable.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +GetVariable3(
> +  IN CONST CHAR16       *Name,
> +  IN CONST EFI_GUID     *Guid,
> +     OUT VOID           **Value,
> +     OUT UINTN          *Size OPTIONAL,
> +     OUT UINT32         *Attr OPTIONAL
> +  );
> +
>  /**
>    Returns a pointer to an allocated buffer that contains the best matching language
>    from a set of supported languages.
> diff --git a/MdePkg/Library/UefiLib/UefiLib.c b/MdePkg/Library/UefiLib/UefiLib.c
> index 39d0ce2b21..475017690c 100644
> --- a/MdePkg/Library/UefiLib/UefiLib.c
> +++ b/MdePkg/Library/UefiLib/UefiLib.c
> @@ -1439,6 +1439,87 @@ GetVariable2 (
>    return Status;
>  }
> 
> +/** Return the attributes of the variable.
> +
> +  Returns the status whether get the variable success. The function retrieves
> +  variable  through the UEFI Runtime Service GetVariable().  The
> +  returned buffer is allocated using AllocatePool().  The caller is responsible
> +  for freeing this buffer with FreePool().  The attributes are returned if
> +  the caller provides a valid Attribute parameter.
> +
> +  If Name  is NULL, then ASSERT().
> +  If Guid  is NULL, then ASSERT().
> +  If Value is NULL, then ASSERT().
> +
> +  @param[in]  Name  The pointer to a Null-terminated Unicode string.
> +  @param[in]  Guid  The pointer to an EFI_GUID structure
> +  @param[out] Value The buffer point saved the variable info.
> +  @param[out] Size  The buffer size of the variable.
> +  @param[out] Attr  The pointer to the variable attributes as found in var store
> +
> +  @retval EFI_OUT_OF_RESOURCES      Allocate buffer failed.
> +  @retval EFI_SUCCESS               Find the specified variable.
> +  @retval Others Errors             Return errors from call to gRT->GetVariable.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +GetVariable3(
> +  IN CONST CHAR16       *Name,
> +  IN CONST EFI_GUID     *Guid,
> +     OUT VOID           **Value,
> +     OUT UINTN          *Size OPTIONAL,
> +     OUT UINT32         *Attr OPTIONAL
> +  )
> +{
> +  EFI_STATUS  Status;
> +  UINTN       BufferSize;
> +
> +  ASSERT(Name != NULL && Guid != NULL && Value != NULL);
> +
> +  //
> +  // Try to get the variable size.
> +  //
> +  BufferSize = 0;
> +  *Value = NULL;
> +  if (Size != NULL) {
> +    *Size = 0;
> +  }
> +
> +  if (Attr != NULL) {
> +    *Attr = 0;
> +  }
> +
> +  Status = gRT->GetVariable((CHAR16 *)Name, (EFI_GUID *)Guid, Attr, &BufferSize, *Value);
> +  if (Status != EFI_BUFFER_TOO_SMALL) {
> +    return Status;
> +  }
> +
> +  //
> +  // Allocate buffer to get the variable.
> +  //
> +  *Value = AllocatePool(BufferSize);
> +  ASSERT(*Value != NULL);
> +  if (*Value == NULL) {
> +    return EFI_OUT_OF_RESOURCES;
> +  }
> +
> +  //
> +  // Get the variable data.
> +  //
> +  Status = gRT->GetVariable((CHAR16 *)Name, (EFI_GUID *)Guid, Attr, &BufferSize, *Value);
> +  if (EFI_ERROR(Status)) {
> +    FreePool(*Value);
> +    *Value = NULL;
> +  }
> +
> +  if (Size != NULL) {
> +    *Size = BufferSize;
> +  }
> +
> +  return Status;
> +}
> +
>  /**
>    Returns a pointer to an allocated buffer that contains the contents of a
>    variable retrieved through the UEFI Runtime Service GetVariable().  This
> --
> 2.16.2.windows.1
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-01-29  3:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-07  4:09 [PATCH] MdePkg/UefiLib: Add a new API GetVariable3 Jiansong Xu
2019-01-29  3:07 ` Gao, Liming

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox