From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from FRA01-PR2-obe.outbound.protection.outlook.com (FRA01-PR2-obe.outbound.protection.outlook.com [40.107.12.82]) by mx.groups.io with SMTP id smtpd.web11.18793.1592229865427492516 for ; Mon, 15 Jun 2020 07:04:25 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=SCJ0kFVG; spf=pass (domain: arm.com, ip: 40.107.12.82, 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=HoxMJ9UtFi2PbEvrMUM3lKP5FmIsHrnrubxBAcWIel8=; b=SCJ0kFVGVEmN0sVaixsTYoS3PFc53vapHqhDfN5UkGo5ARpKlrwGiGV382zhK8wJvyRW7ZdK2WnUU0lbtxzC/0Y/smbPYyy4DHgMPvTPEVkt+hkwzdPHhoo1bc7R3HKdPuUqg7MpmKvbxwDnmadqq6b8cxVm9Cm3WVMnf8uYVWc= Received: from AM6PR05CA0025.eurprd05.prod.outlook.com (2603:10a6:20b:2e::38) by PR2PR08MB4889.eurprd08.prod.outlook.com (2603:10a6:101:1d::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.19; Mon, 15 Jun 2020 14:04:22 +0000 Received: from VE1EUR03FT018.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:2e:cafe::38) by AM6PR05CA0025.outlook.office365.com (2603:10a6:20b:2e::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.19 via Frontend Transport; Mon, 15 Jun 2020 14:04:21 +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 VE1EUR03FT018.mail.protection.outlook.com (10.152.18.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.18 via Frontend Transport; Mon, 15 Jun 2020 14:04:21 +0000 Received: ("Tessian outbound 3e82c366635e:v59"); Mon, 15 Jun 2020 14:04:20 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: af531cac3bca3e5c X-CR-MTA-TID: 64aa7808 Received: from d0b0b0cddf59.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id ABCD965F-44B9-4CE9-BBA5-055A4F75C778.1; Mon, 15 Jun 2020 14:04:15 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id d0b0b0cddf59.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 15 Jun 2020 14:04:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NIESHU7+P0zko+JTNBasKBmHDTlGvtz6w0PLkpgo6TVjbtHpd05zENNnq7Jdj+b3CnK7ZOGMrPQXMjL5aBhIf1oGJn12erqoTeiuckQqtd+/dfX4sbUU9JCxvQ7+JzepyFXd+UKqGx+T4oM5W7gv9kmq/xUxLEdYGaFJdl9JsiVhti0xrH+qMv6utnHSGF9Ni0zK4J64iKSuw0VuXCflFjg4zLpuEftwwz2tSjTqosZzLmhKiHrf+kJMCnEBmmC+2lAm0DA7RbcX/OQaeMThhY//JfAxqV1uwvmf3H19NCzYZJnAb6dr6M2M2bxj9ty1zB5OFfTQMrOmFNCNJlQB3g== 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=HoxMJ9UtFi2PbEvrMUM3lKP5FmIsHrnrubxBAcWIel8=; b=HfcwVe/yPE25CznZBy5DPui0R/uLs2sLIwPtBAAqjR/ItgEwdNgkSrpDcvXsbdv9hs5UZwsQL6IqG6W4mLkPvJPEJiNvOv46/OqD+MskssYrKfbPBj/DGUg7LDieXN9Jk+hGSwX8ekCOVpfEYBMFXTJGW8S6hk0jXpdjrxSC4En2+EqS9BFPdAbqp8sJ3YKvekCi+dFZPVHMX+HsgVST+3YwZdCwf8WYBkKvWin7PtcBR9wYPggRgKdFwQGQV/xa3GS/M6ZHATiJt7SmmdDogdQgEttW1ncdbgKmsf3BtNlI8rNXUxo5WcN6eECPbVYKRIo2vZY9s6tUxI1b12gIsg== 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=HoxMJ9UtFi2PbEvrMUM3lKP5FmIsHrnrubxBAcWIel8=; b=SCJ0kFVGVEmN0sVaixsTYoS3PFc53vapHqhDfN5UkGo5ARpKlrwGiGV382zhK8wJvyRW7ZdK2WnUU0lbtxzC/0Y/smbPYyy4DHgMPvTPEVkt+hkwzdPHhoo1bc7R3HKdPuUqg7MpmKvbxwDnmadqq6b8cxVm9Cm3WVMnf8uYVWc= Received: from DBBPR09CA0014.eurprd09.prod.outlook.com (2603:10a6:10:c0::26) by HE1PR0802MB2348.eurprd08.prod.outlook.com (2603:10a6:3:c5::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.24; Mon, 15 Jun 2020 14:04:13 +0000 Received: from DB5EUR03FT018.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:c0:cafe::b3) by DBBPR09CA0014.outlook.office365.com (2603:10a6:10:c0::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.21 via Frontend Transport; Mon, 15 Jun 2020 14:04:13 +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 DB5EUR03FT018.mail.protection.outlook.com (10.152.20.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.3088.18 via Frontend Transport; Mon, 15 Jun 2020 14:04:13 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Mon, 15 Jun 2020 14:04:12 +0000 Received: from localhost.localdomain (10.57.15.84) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Mon, 15 Jun 2020 14:04:12 +0000 From: "Tomas Pilar (tpilar)" To: CC: , Ray Ni , Zhichao Gao Subject: [PATCH v3 5/7] ShellPkg/AcpiView: Refactor DumpAcpiTableToFile Date: Mon, 15 Jun 2020 15:03:49 +0100 Message-ID: <20200615140351.1725-6-Tomas.Pilar@arm.com> X-Mailer: git-send-email 2.24.1.windows.2 In-Reply-To: <20200615140351.1725-1-Tomas.Pilar@arm.com> References: <20200615140351.1725-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)(136003)(396003)(376002)(39860400002)(346002)(46966005)(82740400003)(336012)(47076004)(81166007)(426003)(6916009)(83380400001)(82310400002)(36756003)(8936002)(6666004)(70206006)(26005)(86362001)(186003)(5660300002)(1076003)(316002)(2616005)(8676002)(478600001)(2906002)(70586007)(356005)(54906003)(4326008);DIR:OUT;SFP:1101; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6cad713f-1050-4a40-6f7d-08d811350071 X-MS-TrafficTypeDiagnostic: HE1PR0802MB2348:|PR2PR08MB4889: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:9508;OLM:9508; X-Forefront-PRVS: 04359FAD81 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: BuqEm87qCuo/+rZG8Bxbc06OXJjLSRdBsL2zLrGNrZtl4Zryr+kclc3mGDkJxDvAlq6K4I/ZlDePiC0J1PRuwv4OuSa8D8FLwxNGIWBZPq27hu97X7vP1rmxmbL+NPyMxyCwQ/5MQBFzGdobRba5tHjSgwHoQ/DNbQkgAQ51kPBZtt0jf376piK0sZa4fwzh5OJfCnhyZ75wEhbAgtHfyHPIr1RPYUBb5laOSGjWrbG9jAzN8hTZQOxQ9YUuuxBnKWrCcbJ8F346TluHr8A+md6BRCDYc4d9JZgPSvxGQk5uIaa2rFUOfIC3nhzF01FzJm//Pp1L5C0V61wYM9mU536ycnUXTzStOUp4t9IVNJLhigWDNxFNPJQEiRhX0ylJcbhzH2CeoQFsFQyq0Xqr9Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0802MB2348 Return-Path: Tomas.Pilar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT018.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)(346002)(376002)(136003)(396003)(46966005)(6916009)(36906005)(336012)(86362001)(70206006)(1076003)(107886003)(81166007)(82740400003)(70586007)(316002)(54906003)(82310400002)(47076004)(426003)(83380400001)(2616005)(26005)(4326008)(8936002)(36756003)(478600001)(8676002)(6666004)(2906002)(5660300002)(186003);DIR:OUT;SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 9286273b-5cc0-4e34-b545-08d81134fb9c X-Forefront-PRVS: 04359FAD81 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9ucGud3Df/0SgOf8VF12xPi+XWFlES9qK4rwsYokWrjkDlP9i+Vqyku4GU/TvvgtdzH1wP6x56EDRtuE8tSyFYXsMkCwIU5WqNktzpZzdm0dETgVO9xmpVkz2rNKdMFmVqlvJH2lbAnjEbRro6TcNZInOLrP2hp9GPkUmq2nxk+n+ZJRcacocpFtKYcxj22P46AnLEaVfsFbYYoA/FpU7JgSkeIwY4wIOacUjtvrrdjjr4Nnw05MI9MlU2GgXFNtZ3tDUWO/F9iMMcgFk5YR9SoilTLWnoiIjbDVF3KiMx6cJuxRU0qhGlqDwMcowbAmjLAHXLnFxFiTGuh2sHoIekALW5hE0YTZG46fEo39kqeH+fr5G8vOCe3CBpt6f88eZK/6jZaAwhbbGRLPam2jtw== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jun 2020 14:04:21.0165 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6cad713f-1050-4a40-6f7d-08d811350071 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: PR2PR08MB4889 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain 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 Cc: Zhichao Gao Signed-off-by: Tomas Pilar --- .../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/Shel= lPkg/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 =20 -EFI_HII_HANDLE gShellAcpiViewHiiHandle =3D NULL; - STATIC UINT32 mTableCount; STATIC UINT32 mBinTableCount; =20 @@ -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; =20 - DumpFileHandle =3D NULL; - TransferBytes =3D Length; GetSelectedAcpiTable (&SelectedTable); =20 UnicodeSPrint ( @@ -66,39 +60,9 @@ DumpAcpiTableToFile ( mBinTableCount++ ); =20 - Status =3D ShellOpenFileByName ( - FileNameBuffer, - &DumpFileHandle, - EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREA= TE, - 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); =20 - Status =3D ShellWriteFile ( - DumpFileHandle, - &TransferBytes, - (VOID*)Ptr - ); - if (EFI_ERROR (Status)) { - Print (L"ERROR: Failed to dump table to binary file.\n"); - TransferBytes =3D 0; - } else { - Print (L"DONE.\n"); - } - - ShellCloseFile (&DumpFileHandle); + TransferBytes =3D ShellDumpBufferToFile (FileNameBuffer, Ptr, Length); return (Length =3D=3D TransferBytes); } =20 diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiView= CommandLib.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiVi= ewCommandLib.c index c3942ad24e5b..e6a65d5bc5f7 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommand= Lib.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommand= Lib.c @@ -25,6 +25,7 @@ #include "UefiShellAcpiViewCommandLib.h" =20 CONST CHAR16 gShellAcpiViewFileName[] =3D L"ShellCommand"; +EFI_HII_HANDLE gShellAcpiViewHiiHandle =3D NULL; =20 /** An array of acpiview command line parameters. @@ -98,6 +99,64 @@ RegisterAllParsers ( return Status; } =20 +/** + 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 =3D ShellOpenFileByName ( + FileNameBuffer, + &DumpFileHandle, + EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREA= TE, + 0 + ); + + if (EFI_ERROR (Status)) { + ShellPrintHiiEx ( + -1, + -1, + NULL, + STRING_TOKEN (STR_GEN_READONLY_MEDIA), + gShellAcpiViewHiiHandle, + L"acpiview" + ); + return 0; + } + + TransferBytes =3D BufferSize; + Status =3D ShellWriteFile ( + DumpFileHandle, + &TransferBytes, + (VOID *) Buffer + ); + + if (EFI_ERROR (Status)) { + Print (L"ERROR: Failed to write binary file.\n"); + TransferBytes =3D 0; + } else { + Print (L"DONE.\n"); + } + + ShellCloseFile (&DumpFileHandle); + return TransferBytes; +} + /** Return the file name of the help text file if not using HII. =20 diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiView= CommandLib.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiVi= ewCommandLib.h index a3a29164004d..b1b1ffe63e28 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommand= Lib.h +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommand= Lib.h @@ -8,7 +8,22 @@ #ifndef UEFI_SHELL_ACPIVIEW_COMMAND_LIB_H_ #define UEFI_SHELL_ACPIVIEW_COMMAND_LIB_H_ =20 -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 + ); =20 /** Function for 'acpiview' command. --=20 2.24.1.windows.2