diff options
| author | Tomas Pilar <Tomas.Pilar@arm.com> | 2020-06-19 14:59:54 +0300 |
|---|---|---|
| committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2020-06-30 04:39:50 +0300 |
| commit | d45cf5ffdf65f6bfdde64886746d81a69ae31bf4 (patch) | |
| tree | 56d925178f574d07d7d22c2da924ebae22198e6f /ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c | |
| parent | 422fe85cc3109684c81990911c79dc18d1828d96 (diff) | |
| download | edk2-d45cf5ffdf65f6bfdde64886746d81a69ae31bf4.tar.xz | |
ShellPkg/AcpiView: Refactor DumpAcpiTableToFile
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>
Diffstat (limited to 'ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c')
| -rw-r--r-- | ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c index c3942ad24e..e6a65d5bc5 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c @@ -25,6 +25,7 @@ #include "UefiShellAcpiViewCommandLib.h"
CONST CHAR16 gShellAcpiViewFileName[] = L"ShellCommand";
+EFI_HII_HANDLE gShellAcpiViewHiiHandle = NULL;
/**
An array of acpiview command line parameters.
@@ -99,6 +100,64 @@ RegisterAllParsers ( }
/**
+ Dump a buffer to a file. Print error message if a file cannot be created.
+
+ @param[in] FileName The filename that shall be created to contain the buffer.
+ @param[in] Buffer Pointer to buffer that shall be dumped.
+ @param[in] BufferSize The size of buffer to be dumped in bytes.
+
+ @return The number of bytes that were written
+**/
+UINTN
+EFIAPI
+ShellDumpBufferToFile (
+ IN CONST CHAR16* FileNameBuffer,
+ IN CONST VOID* Buffer,
+ IN CONST UINTN BufferSize
+ )
+{
+ EFI_STATUS Status;
+ SHELL_FILE_HANDLE DumpFileHandle;
+ UINTN TransferBytes;
+
+ Status = ShellOpenFileByName (
+ FileNameBuffer,
+ &DumpFileHandle,
+ EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE,
+ 0
+ );
+
+ if (EFI_ERROR (Status)) {
+ ShellPrintHiiEx (
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_GEN_READONLY_MEDIA),
+ gShellAcpiViewHiiHandle,
+ L"acpiview"
+ );
+ return 0;
+ }
+
+ TransferBytes = BufferSize;
+ Status = ShellWriteFile (
+ DumpFileHandle,
+ &TransferBytes,
+ (VOID *) Buffer
+ );
+
+ if (EFI_ERROR (Status)) {
+ Print (L"ERROR: Failed to write binary file.\n");
+ TransferBytes = 0;
+ } else {
+ Print (L"DONE.\n");
+ }
+
+ ShellCloseFile (&DumpFileHandle);
+ return TransferBytes;
+}
+
+/**
Return the file name of the help text file if not using HII.
@return The string pointer to the file name.
|
