From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (EUR05-AM6-obe.outbound.protection.outlook.com [40.107.22.60]) by mx.groups.io with SMTP id smtpd.web12.7198.1592919820120164383 for ; Tue, 23 Jun 2020 06:43:40 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=HtK8w3iT; spf=pass (domain: arm.com, ip: 40.107.22.60, mailfrom: tomas.pilar@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=km04FZL++i0I1dy/rVy4hxMVHs/7YsTjVEWvaILGQTs=; b=HtK8w3iTmIh5jaZ3eRCK6poZfrP9kUXRBNnWz98U8yTB/04X3fbhu6G2WQXZhc/lCVzVbGGLrOY/GGOrfPKPx74YzLksqGUDk3CtzGRcASALyqf5LO3r4WkpPynvftcTvnzpiZGpcRd2NCmm04SYAXzjDtKODOGahJNLqTFHp8U= Received: from AM6PR10CA0103.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:8c::44) by AM0PR08MB4307.eurprd08.prod.outlook.com (2603:10a6:208:13d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.22; Tue, 23 Jun 2020 13:43:37 +0000 Received: from AM5EUR03FT058.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:8c:cafe::fb) by AM6PR10CA0103.outlook.office365.com (2603:10a6:209:8c::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.24 via Frontend Transport; Tue, 23 Jun 2020 13:43:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; edk2.groups.io; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT058.mail.protection.outlook.com (10.152.17.48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.22 via Frontend Transport; Tue, 23 Jun 2020 13:43:37 +0000 Received: ("Tessian outbound 217a52b9caed:v59"); Tue, 23 Jun 2020 13:43:37 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 254210a84c8a626e X-CR-MTA-TID: 64aa7808 Received: from eb8b7ed66e5b.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 2FCA9798-BFBA-4DFF-895B-C5A28C97F4D7.1; Tue, 23 Jun 2020 13:43:31 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id eb8b7ed66e5b.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 23 Jun 2020 13:43:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YynomxVwgP8hkhS83xoWyYtthzvv4PyAqB1+FeqadPF6UPMd9QChKyZOdUkig19I9svIfThQU8Za3N1fsfxgwWYz+Oex6SroHaiKWFNWm5fbJc6XFf5Hjg17uaDhDVwJ9L1seJkO8rzPmhaTelHDU/nHuawjIrVuby39J7KlLFs/N/iFGYKWC0Kx9iJTvMPXjiDYeIl+waieCMmTNxTuxAoyzBZK/M9a7gobiy9BMmhHKb/fHaN1/L0p0+4ZbpGZ8i3Mr8LAzo39/LoFFS649W8AO1Alk8s1JOxgWV47HpXzWYcirsfk7tb/p7bAK9Aoy5jJ2J1EnEM47OB6rF1O8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=km04FZL++i0I1dy/rVy4hxMVHs/7YsTjVEWvaILGQTs=; b=kIXHVnRiMj5zVTuVGGp0Xm2lJjGV20TD3+XuZfAwOjoTapor642Q4HMhEYR+1EKaP+gb1Z7JFEg16KuaZZddohMKwUCpcy+KnCHfzwzNFkiCFa4Ry/r2v1O886ireKOU75A46GkV8H59vS+QI2gev6ZIoDTNx+Xxot0SMxckljZDPB/ny2HYfn6N8tL5RYeSsT0yOlH5Wy/u0lZk9TVa1fBIRcKSJNPdcyW3+7idFACWyHDCyTo8wEKODr+C4DK2ns/lmANXUO8Dvu+ZZkjWQZcYPC3p1RiCUDu0IHSBycvKvQME4fPFwQUyikek15MDVb14akdz8o74d3C7WlUaqw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=arm.com; dmarc=bestguesspass action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=km04FZL++i0I1dy/rVy4hxMVHs/7YsTjVEWvaILGQTs=; b=HtK8w3iTmIh5jaZ3eRCK6poZfrP9kUXRBNnWz98U8yTB/04X3fbhu6G2WQXZhc/lCVzVbGGLrOY/GGOrfPKPx74YzLksqGUDk3CtzGRcASALyqf5LO3r4WkpPynvftcTvnzpiZGpcRd2NCmm04SYAXzjDtKODOGahJNLqTFHp8U= Received: from DB6PR0201CA0027.eurprd02.prod.outlook.com (2603:10a6:4:3f::37) by VI1PR08MB3197.eurprd08.prod.outlook.com (2603:10a6:803:3e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.22; Tue, 23 Jun 2020 13:43:30 +0000 Received: from DB5EUR03FT003.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:3f:cafe::97) by DB6PR0201CA0027.outlook.office365.com (2603:10a6:4:3f::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.22 via Frontend Transport; Tue, 23 Jun 2020 13:43:30 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT003.mail.protection.outlook.com (10.152.20.157) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.3109.22 via Frontend Transport; Tue, 23 Jun 2020 13:43:30 +0000 Received: from AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1415.2; Tue, 23 Jun 2020 13:43:24 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1779.2; Tue, 23 Jun 2020 13:43:24 +0000 Received: from localhost.localdomain (10.57.20.205) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Tue, 23 Jun 2020 13:43:24 +0000 From: "Tomas Pilar (tpilar)" To: CC: , , Ray Ni , "Zhichao Gao" Subject: [PATCH v4 5/7] ShellPkg/AcpiView: Refactor DumpAcpiTableToFile Date: Tue, 23 Jun 2020 14:43:02 +0100 Message-ID: <20200623134304.2619-6-Tomas.Pilar@arm.com> X-Mailer: git-send-email 2.24.1.windows.2 In-Reply-To: <20200623134304.2619-1-Tomas.Pilar@arm.com> References: <20200623134304.2619-1-Tomas.Pilar@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFTY:;SFS:(6029001)(4636009)(39860400002)(136003)(396003)(346002)(376002)(46966005)(8936002)(356005)(336012)(82310400002)(81166007)(2906002)(316002)(478600001)(426003)(2616005)(1076003)(6666004)(47076004)(186003)(26005)(82740400003)(4326008)(8676002)(83380400001)(5660300002)(70206006)(70586007)(6916009)(86362001)(36756003)(54906003);DIR:OUT;SFP:1101; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9acdb35b-fb85-424e-5b06-08d8177b6e74 X-MS-TrafficTypeDiagnostic: VI1PR08MB3197:|AM0PR08MB4307: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:9508;OLM:9508; X-Forefront-PRVS: 04433051BF X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: yO47sphk8at98zJ1HHIdFUWh2ynNuHWIETjZ/cfMAIdti0tv9SqQuXQC9Iq2nsQKG/PxfwuqfLFxLY6emji4Cc+aFKc+vCz1ZG39aUzCuuzpl+Qp8ErzZgpwsd3VEhXWV4AcFfSksLeb/R1Cb3ZrHzTmnZOnR2qvvq4lrPp22uC/Fdl3/0L+AeISraU9HZVXt7twD4h3LhkLQD8JBQ8dNP98DIOB6kuIeSe1BMO+6yzr1j0vaDUqivJGqRsf1i54vO2qavOA/q2xN0zcJu7QjEsVRE5QZ9+PFk0hReimJsMrI/UNwyqD4r2Tdy45GN53v1XGm9LoBPfDUZDtQZJ/7sHl9F7twiD0sPxS40jJeD40sTY+3FARx0zcTXoS2EmClrBYmXVdcs+RVIC1xmxkqQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB3197 Return-Path: Tomas.Pilar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT058.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFTY:;SFS:(6029001)(4636009)(39860400002)(136003)(396003)(376002)(346002)(46966005)(36906005)(478600001)(336012)(82310400002)(81166007)(107886003)(2906002)(316002)(426003)(6666004)(47076004)(2616005)(186003)(82740400003)(4326008)(26005)(1076003)(5660300002)(8676002)(8936002)(83380400001)(70586007)(70206006)(6916009)(86362001)(36756003)(54906003);DIR:OUT;SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 304e9d9f-4c6b-4d26-b8f4-08d8177b6a1f X-Forefront-PRVS: 04433051BF X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: edS/TQNxS5CVfP724c4qE/Uh/mXKFPnqvM2UY9nVE1k9Uk0h7xmwFltW+RYbPmjjg7r2Ci1yRMw+m6xRmRgTBaQtXba46Nme93djx2x5Dzs+CBXd8QnVpMv3olmIvyUduKhdO/fUvlunZCCacUIbbQ9XUdKvsfYRpqgi15givoig1UIgdQZQR1zEfR5y6FOnIxIxc0sk0LAUse1cKvD9apDArfA5CQ4nBlBELMhysEBHZskX+B4iGbF2TwvPzYzRZuU6ASVGKpNpW+Aqr0rfKvMmZCjk8oOfVqxfy61SBQ8eTyp+101tW3+1shA5QTj5IWjRQsOgL4/XqfBrU5hc+Vc1InYrV+Bztx8UFnFntONCt7NbP19vyj+ggyHFnEiU56z6ZMMzATIvkWXfwrIrMA== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jun 2020 13:43:37.3850 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9acdb35b-fb85-424e-5b06-08d8177b6e74 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB4307 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Method is refactored into two parts. A new method is=0D created that dumps arbitrary buffers into a newly created=0D file. This method is called from core code after the core code=0D determined the appropriate filename to be used.=0D =0D This improves the modular design.=0D =0D Cc: Ray Ni =0D Cc: Zhichao Gao =0D Reviewed-by: Zhichao Gao =0D Signed-off-by: Tomas Pilar =0D ---=0D .../UefiShellAcpiViewCommandLib/AcpiView.c | 38 +-----------=0D .../UefiShellAcpiViewCommandLib.c | 59 +++++++++++++++++++=0D .../UefiShellAcpiViewCommandLib.h | 17 +++++-=0D 3 files changed, 76 insertions(+), 38 deletions(-)=0D =0D diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c b/Shel= lPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c=0D index e524fcb0b27a..d2240b2e89d5 100644=0D --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c=0D +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c=0D @@ -27,8 +27,6 @@=0D #include "Arm/SbbrValidator.h"=0D #endif=0D =0D -EFI_HII_HANDLE gShellAcpiViewHiiHandle =3D NULL;=0D -=0D STATIC UINT32 mTableCount;=0D STATIC UINT32 mBinTableCount;=0D =0D @@ -48,14 +46,10 @@ DumpAcpiTableToFile (=0D IN CONST UINTN Length=0D )=0D {=0D - EFI_STATUS Status;=0D CHAR16 FileNameBuffer[MAX_FILE_NAME_LEN];=0D - SHELL_FILE_HANDLE DumpFileHandle;=0D UINTN TransferBytes;=0D SELECTED_ACPI_TABLE *SelectedTable;=0D =0D - DumpFileHandle =3D NULL;=0D - TransferBytes =3D Length;=0D GetSelectedAcpiTable (&SelectedTable);=0D =0D UnicodeSPrint (=0D @@ -66,39 +60,9 @@ DumpAcpiTableToFile (=0D mBinTableCount++=0D );=0D =0D - Status =3D ShellOpenFileByName (=0D - FileNameBuffer,=0D - &DumpFileHandle,=0D - EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREA= TE,=0D - 0=0D - );=0D - if (EFI_ERROR (Status)) {=0D - ShellPrintHiiEx (=0D - -1,=0D - -1,=0D - NULL,=0D - STRING_TOKEN (STR_GEN_READONLY_MEDIA),=0D - gShellAcpiViewHiiHandle,=0D - L"acpiview"=0D - );=0D - return FALSE;=0D - }=0D -=0D Print (L"Dumping ACPI table to : %s ... ", FileNameBuffer);=0D =0D - Status =3D ShellWriteFile (=0D - DumpFileHandle,=0D - &TransferBytes,=0D - (VOID*)Ptr=0D - );=0D - if (EFI_ERROR (Status)) {=0D - Print (L"ERROR: Failed to dump table to binary file.\n");=0D - TransferBytes =3D 0;=0D - } else {=0D - Print (L"DONE.\n");=0D - }=0D -=0D - ShellCloseFile (&DumpFileHandle);=0D + TransferBytes =3D ShellDumpBufferToFile (FileNameBuffer, Ptr, Length);=0D return (Length =3D=3D TransferBytes);=0D }=0D =0D diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiView= CommandLib.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiVi= ewCommandLib.c=0D index c3942ad24e5b..e6a65d5bc5f7 100644=0D --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommand= Lib.c=0D +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommand= Lib.c=0D @@ -25,6 +25,7 @@=0D #include "UefiShellAcpiViewCommandLib.h"=0D =0D CONST CHAR16 gShellAcpiViewFileName[] =3D L"ShellCommand";=0D +EFI_HII_HANDLE gShellAcpiViewHiiHandle =3D NULL;=0D =0D /**=0D An array of acpiview command line parameters.=0D @@ -98,6 +99,64 @@ RegisterAllParsers (=0D return Status;=0D }=0D =0D +/**=0D + Dump a buffer to a file. Print error message if a file cannot be created= .=0D +=0D + @param[in] FileName The filename that shall be created to contain the = buffer.=0D + @param[in] Buffer Pointer to buffer that shall be dumped.=0D + @param[in] BufferSize The size of buffer to be dumped in bytes.=0D +=0D + @return The number of bytes that were written=0D +**/=0D +UINTN=0D +EFIAPI=0D +ShellDumpBufferToFile (=0D + IN CONST CHAR16* FileNameBuffer,=0D + IN CONST VOID* Buffer,=0D + IN CONST UINTN BufferSize=0D + )=0D +{=0D + EFI_STATUS Status;=0D + SHELL_FILE_HANDLE DumpFileHandle;=0D + UINTN TransferBytes;=0D +=0D + Status =3D ShellOpenFileByName (=0D + FileNameBuffer,=0D + &DumpFileHandle,=0D + EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREA= TE,=0D + 0=0D + );=0D +=0D + if (EFI_ERROR (Status)) {=0D + ShellPrintHiiEx (=0D + -1,=0D + -1,=0D + NULL,=0D + STRING_TOKEN (STR_GEN_READONLY_MEDIA),=0D + gShellAcpiViewHiiHandle,=0D + L"acpiview"=0D + );=0D + return 0;=0D + }=0D +=0D + TransferBytes =3D BufferSize;=0D + Status =3D ShellWriteFile (=0D + DumpFileHandle,=0D + &TransferBytes,=0D + (VOID *) Buffer=0D + );=0D +=0D + if (EFI_ERROR (Status)) {=0D + Print (L"ERROR: Failed to write binary file.\n");=0D + TransferBytes =3D 0;=0D + } else {=0D + Print (L"DONE.\n");=0D + }=0D +=0D + ShellCloseFile (&DumpFileHandle);=0D + return TransferBytes;=0D +}=0D +=0D /**=0D Return the file name of the help text file if not using HII.=0D =0D diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiView= CommandLib.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiVi= ewCommandLib.h=0D index a3a29164004d..b1b1ffe63e28 100644=0D --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommand= Lib.h=0D +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommand= Lib.h=0D @@ -8,7 +8,22 @@=0D #ifndef UEFI_SHELL_ACPIVIEW_COMMAND_LIB_H_=0D #define UEFI_SHELL_ACPIVIEW_COMMAND_LIB_H_=0D =0D -extern EFI_HII_HANDLE gShellAcpiViewHiiHandle;=0D +/**=0D + Dump a buffer to a file. Print error message if a file cannot be created= .=0D +=0D + @param[in] FileName The filename that shall be created to contain the = buffer.=0D + @param[in] Buffer Pointer to buffer that shall be dumped.=0D + @param[in] BufferSize The size of buffer to be dumped in bytes.=0D +=0D + @return The number of bytes that were written=0D +**/=0D +UINTN=0D +EFIAPI=0D +ShellDumpBufferToFile (=0D + IN CONST CHAR16* FileNameBuffer,=0D + IN CONST VOID* Buffer,=0D + IN CONST UINTN BufferSize=0D + );=0D =0D /**=0D Function for 'acpiview' command.=0D -- =0D 2.24.1.windows.2=0D =0D