From: "Tomas Pilar (tpilar)" <Tomas.Pilar@arm.com>
To: <devel@edk2.groups.io>
Cc: <nd@arm.com>, Ray Ni <ray.ni@intel.com>,
Zhichao Gao <zhichao.gao@intel.com>
Subject: [PATCH v3 5/7] ShellPkg/AcpiView: Refactor DumpAcpiTableToFile
Date: Mon, 15 Jun 2020 15:03:49 +0100 [thread overview]
Message-ID: <20200615140351.1725-6-Tomas.Pilar@arm.com> (raw)
In-Reply-To: <20200615140351.1725-1-Tomas.Pilar@arm.com>
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>
Signed-off-by: Tomas Pilar <tomas.pilar@arm.com>
---
.../UefiShellAcpiViewCommandLib/AcpiView.c | 38 +-----------
.../UefiShellAcpiViewCommandLib.c | 59 +++++++++++++++++++
.../UefiShellAcpiViewCommandLib.h | 17 +++++-
3 files changed, 76 insertions(+), 38 deletions(-)
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
index 2507ec78204b..1b6721e6734f 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
@@ -27,8 +27,6 @@
#include "Arm/SbbrValidator.h"
#endif
-EFI_HII_HANDLE gShellAcpiViewHiiHandle = NULL;
-
STATIC UINT32 mTableCount;
STATIC UINT32 mBinTableCount;
@@ -48,14 +46,10 @@ DumpAcpiTableToFile (
IN CONST UINTN Length
)
{
- EFI_STATUS Status;
CHAR16 FileNameBuffer[MAX_FILE_NAME_LEN];
- SHELL_FILE_HANDLE DumpFileHandle;
UINTN TransferBytes;
SELECTED_ACPI_TABLE *SelectedTable;
- DumpFileHandle = NULL;
- TransferBytes = Length;
GetSelectedAcpiTable (&SelectedTable);
UnicodeSPrint (
@@ -66,39 +60,9 @@ DumpAcpiTableToFile (
mBinTableCount++
);
- 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 FALSE;
- }
-
Print (L"Dumping ACPI table to : %s ... ", FileNameBuffer);
- Status = ShellWriteFile (
- DumpFileHandle,
- &TransferBytes,
- (VOID*)Ptr
- );
- if (EFI_ERROR (Status)) {
- Print (L"ERROR: Failed to dump table to binary file.\n");
- TransferBytes = 0;
- } else {
- Print (L"DONE.\n");
- }
-
- ShellCloseFile (&DumpFileHandle);
+ TransferBytes = ShellDumpBufferToFile (FileNameBuffer, Ptr, Length);
return (Length == TransferBytes);
}
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c
index c3942ad24e5b..e6a65d5bc5f7 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.
@@ -98,6 +99,64 @@ RegisterAllParsers (
return Status;
}
+/**
+ 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.
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.h
index a3a29164004d..b1b1ffe63e28 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.h
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.h
@@ -8,7 +8,22 @@
#ifndef UEFI_SHELL_ACPIVIEW_COMMAND_LIB_H_
#define UEFI_SHELL_ACPIVIEW_COMMAND_LIB_H_
-extern EFI_HII_HANDLE gShellAcpiViewHiiHandle;
+/**
+ 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
+ );
/**
Function for 'acpiview' command.
--
2.24.1.windows.2
next prev parent reply other threads:[~2020-06-15 14:04 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-15 14:03 [PATCH v3 0/7] Standalone AcpiView Application Tomas Pilar (tpilar)
2020-06-15 14:03 ` [PATCH v3 1/7] ShellPkg/AcpiView: Move log reset to main method Tomas Pilar (tpilar)
2020-06-15 14:03 ` [PATCH v3 2/7] ShellPkg/AcpiView: Refactor configuration Tomas Pilar (tpilar)
2020-06-23 1:23 ` Gao, Zhichao
2020-06-15 14:03 ` [PATCH v3 3/7] ShellPkg/AcpiView: Move table count reset Tomas Pilar (tpilar)
2020-06-15 14:03 ` [PATCH v3 4/7] ShellPkg/AcpiView: Move parameter parsing Tomas Pilar (tpilar)
2020-06-15 14:03 ` Tomas Pilar (tpilar) [this message]
2020-06-23 1:25 ` [PATCH v3 5/7] ShellPkg/AcpiView: Refactor DumpAcpiTableToFile Gao, Zhichao
2020-06-15 14:03 ` [PATCH v3 6/7] ShellPkg: Add AcpiViewCommandLib Tomas Pilar (tpilar)
2020-06-23 1:26 ` [edk2-devel] " Gao, Zhichao
2020-06-15 14:03 ` [PATCH v3 7/7] ShellPkg/AcpiView: Add application wrapper Tomas Pilar (tpilar)
2020-06-23 1:28 ` Gao, Zhichao
2020-06-22 12:23 ` [edk2-devel] [PATCH v3 0/7] Standalone AcpiView Application Tomas Pilar (tpilar)
2020-06-23 1:32 ` Gao, Zhichao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200615140351.1725-6-Tomas.Pilar@arm.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox