]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg/AcpiView: Refactor DumpAcpiTableToFile
authorTomas Pilar <Tomas.Pilar@arm.com>
Fri, 19 Jun 2020 11:59:54 +0000 (12:59 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Tue, 30 Jun 2020 01:39:50 +0000 (01:39 +0000)
Method is refactored into two parts. A new method is
created that dumps arbitrary buffers into a newly created
file. This method is called from core code after the core code
determined the appropriate filename to be used.

This improves the modular design.

Cc: Ray Ni <ray.ni@intel.com>
Cc: Zhichao Gao <zhichao.gao@intel.com>
Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>
Signed-off-by: Tomas Pilar <tomas.pilar@arm.com>
ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c
ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.h

index e524fcb0b27ace37a5148615d6c12d4f6876c59f..d2240b2e89d5668f90060e57f5fd67d3c55c008f 100644 (file)
@@ -27,8 +27,6 @@
 #include "Arm/SbbrValidator.h"\r
 #endif\r
 \r
-EFI_HII_HANDLE gShellAcpiViewHiiHandle = NULL;\r
-\r
 STATIC UINT32             mTableCount;\r
 STATIC UINT32             mBinTableCount;\r
 \r
@@ -48,14 +46,10 @@ DumpAcpiTableToFile (
   IN CONST UINTN   Length\r
   )\r
 {\r
-  EFI_STATUS          Status;\r
   CHAR16              FileNameBuffer[MAX_FILE_NAME_LEN];\r
-  SHELL_FILE_HANDLE   DumpFileHandle;\r
   UINTN               TransferBytes;\r
   SELECTED_ACPI_TABLE *SelectedTable;\r
 \r
-  DumpFileHandle = NULL;\r
-  TransferBytes = Length;\r
   GetSelectedAcpiTable (&SelectedTable);\r
 \r
   UnicodeSPrint (\r
@@ -66,39 +60,9 @@ DumpAcpiTableToFile (
     mBinTableCount++\r
     );\r
 \r
-  Status = ShellOpenFileByName (\r
-             FileNameBuffer,\r
-             &DumpFileHandle,\r
-             EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE,\r
-             0\r
-             );\r
-  if (EFI_ERROR (Status)) {\r
-    ShellPrintHiiEx (\r
-      -1,\r
-      -1,\r
-      NULL,\r
-      STRING_TOKEN (STR_GEN_READONLY_MEDIA),\r
-      gShellAcpiViewHiiHandle,\r
-      L"acpiview"\r
-      );\r
-    return FALSE;\r
-  }\r
-\r
   Print (L"Dumping ACPI table to : %s ... ", FileNameBuffer);\r
 \r
-  Status = ShellWriteFile (\r
-             DumpFileHandle,\r
-             &TransferBytes,\r
-             (VOID*)Ptr\r
-             );\r
-  if (EFI_ERROR (Status)) {\r
-    Print (L"ERROR: Failed to dump table to binary file.\n");\r
-    TransferBytes = 0;\r
-  } else {\r
-    Print (L"DONE.\n");\r
-  }\r
-\r
-  ShellCloseFile (&DumpFileHandle);\r
+  TransferBytes = ShellDumpBufferToFile (FileNameBuffer, Ptr, Length);\r
   return (Length == TransferBytes);\r
 }\r
 \r
index c3942ad24e5b9c885dc78fbe97434a87147e306e..e6a65d5bc5f7e19b81ad460183495a495144993c 100644 (file)
@@ -25,6 +25,7 @@
 #include "UefiShellAcpiViewCommandLib.h"\r
 \r
 CONST CHAR16 gShellAcpiViewFileName[] = L"ShellCommand";\r
+EFI_HII_HANDLE gShellAcpiViewHiiHandle = NULL;\r
 \r
 /**\r
   An array of acpiview command line parameters.\r
@@ -98,6 +99,64 @@ RegisterAllParsers (
   return Status;\r
 }\r
 \r
+/**\r
+  Dump a buffer to a file. Print error message if a file cannot be created.\r
+\r
+  @param[in] FileName   The filename that shall be created to contain the buffer.\r
+  @param[in] Buffer     Pointer to buffer that shall be dumped.\r
+  @param[in] BufferSize The size of buffer to be dumped in bytes.\r
+\r
+  @return The number of bytes that were written\r
+**/\r
+UINTN\r
+EFIAPI\r
+ShellDumpBufferToFile (\r
+  IN CONST CHAR16* FileNameBuffer,\r
+  IN CONST VOID*   Buffer,\r
+  IN CONST UINTN   BufferSize\r
+  )\r
+{\r
+  EFI_STATUS          Status;\r
+  SHELL_FILE_HANDLE   DumpFileHandle;\r
+  UINTN               TransferBytes;\r
+\r
+  Status = ShellOpenFileByName (\r
+             FileNameBuffer,\r
+             &DumpFileHandle,\r
+             EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE,\r
+             0\r
+             );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    ShellPrintHiiEx (\r
+      -1,\r
+      -1,\r
+      NULL,\r
+      STRING_TOKEN (STR_GEN_READONLY_MEDIA),\r
+      gShellAcpiViewHiiHandle,\r
+      L"acpiview"\r
+      );\r
+    return 0;\r
+  }\r
+\r
+  TransferBytes = BufferSize;\r
+  Status = ShellWriteFile (\r
+             DumpFileHandle,\r
+             &TransferBytes,\r
+             (VOID *) Buffer\r
+             );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    Print (L"ERROR: Failed to write binary file.\n");\r
+    TransferBytes = 0;\r
+  } else {\r
+    Print (L"DONE.\n");\r
+  }\r
+\r
+  ShellCloseFile (&DumpFileHandle);\r
+  return TransferBytes;\r
+}\r
+\r
 /**\r
   Return the file name of the help text file if not using HII.\r
 \r
index a3a29164004d6b424ad1860442d56c25bc0ac131..b1b1ffe63e28811ec6e39c57b9b621b37de39ae7 100644 (file)
@@ -8,7 +8,22 @@
 #ifndef UEFI_SHELL_ACPIVIEW_COMMAND_LIB_H_\r
 #define UEFI_SHELL_ACPIVIEW_COMMAND_LIB_H_\r
 \r
-extern EFI_HII_HANDLE gShellAcpiViewHiiHandle;\r
+/**\r
+  Dump a buffer to a file. Print error message if a file cannot be created.\r
+\r
+  @param[in] FileName   The filename that shall be created to contain the buffer.\r
+  @param[in] Buffer     Pointer to buffer that shall be dumped.\r
+  @param[in] BufferSize The size of buffer to be dumped in bytes.\r
+\r
+  @return The number of bytes that were written\r
+**/\r
+UINTN\r
+EFIAPI\r
+ShellDumpBufferToFile (\r
+  IN CONST CHAR16* FileNameBuffer,\r
+  IN CONST VOID*   Buffer,\r
+  IN CONST UINTN   BufferSize\r
+  );\r
 \r
 /**\r
   Function for 'acpiview' command.\r