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.88]) by mx.groups.io with SMTP id smtpd.web11.1376.1590085018601262627 for ; Thu, 21 May 2020 11:16:59 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=bXGNTS6o; spf=pass (domain: arm.com, ip: 40.107.12.88, 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=S5YjE/35bNZ0Fk6xY0Mxmb1Lt6aCrGlynzvBV9yWppM=; b=bXGNTS6owFaJ3WCQ7I/nAOIDdOaWn7hGwzeISFUt57NI6mp8ufvPjLziXnGzzrScTfnT0lGZJm2C3U/m63NOv2D7kEAryMgHSK2E1d/GII9AqKFTlzYzAbsLog76N/ylOSjdDIJKmMJZCgBMMn3nQMe3dlp6viMxHGssKxfXm8E= Received: from AM6P192CA0067.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:82::44) by PR2PR08MB4716.eurprd08.prod.outlook.com (2603:10a6:101:28::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.23; Thu, 21 May 2020 18:16:56 +0000 Received: from AM5EUR03FT064.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:82:cafe::d0) by AM6P192CA0067.outlook.office365.com (2603:10a6:209:82::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.23 via Frontend Transport; Thu, 21 May 2020 18:16:56 +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 AM5EUR03FT064.mail.protection.outlook.com (10.152.17.53) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.23 via Frontend Transport; Thu, 21 May 2020 18:16:55 +0000 Received: ("Tessian outbound cff7dd4de28a:v57"); Thu, 21 May 2020 18:16:55 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 18527d3499e99c60 X-CR-MTA-TID: 64aa7808 Received: from 01609b73db7e.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 8B7A2084-5001-42CE-A185-729AA4716B7F.1; Thu, 21 May 2020 18:16:50 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 01609b73db7e.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 21 May 2020 18:16:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZRHX78NQwlEV0vsj82ScBxGWoYunSm9OwsoWshaNu4I42nUDj5qOezKVuCqWF4zJUF1y6LGcAvoLfiTzy5qjce+0SMWXWoIs49kWr7tQ8OhEdr4k0SSyHOO45TfM2tlWDb9cg3vBjMQc1tXhuwNH/BgtG/nYhN5O+bKIXffmAt4L/Auu0zI7WzriDi+qNy0TUyJifKe7goVB2sORJaHora6cnmgiq4NFA6WQXonKIfqVSHu7FSeNfbpTOlEzw1BQFItB/DHYAD6iZpezvQHvZ5NBebVr1OY1lvt4umtk3G2wmNmI0k+5yiOyKO51O5L/DPEhV+bB1FPgEFZXoGR3YQ== 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=S5YjE/35bNZ0Fk6xY0Mxmb1Lt6aCrGlynzvBV9yWppM=; b=gZudrkV1Tel5PTG/t8xPt8AnazK2VkR+uviwkp8J2LW72TfaRdDEE0ORsToyYCJmKJXeudoQSYeuu3rJYq+WpMurD+GM6Ulh18+ReLNgYr0jNlQI4AbbFVZMmkd5tgFxB0n6RJ8dN6SIPiTNnckpb+08MdLTJNAIfahF/j8gcKX9BrUp9EyAhb7U9gaYylvGraPPCetej7a7K2IZnnSpU1tblI63ZxmUbIQ72SFp2xy/6SONAMLpgkuCrX/VW/2BJhjKk6/OQ1blLtjGUhjUXw+JmrFG/yXVrh+C6ZCF9JnYiMkrLLm/Mfpx2950POWHyY+CKJuPmywNLDl4OeAv/w== 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=S5YjE/35bNZ0Fk6xY0Mxmb1Lt6aCrGlynzvBV9yWppM=; b=bXGNTS6owFaJ3WCQ7I/nAOIDdOaWn7hGwzeISFUt57NI6mp8ufvPjLziXnGzzrScTfnT0lGZJm2C3U/m63NOv2D7kEAryMgHSK2E1d/GII9AqKFTlzYzAbsLog76N/ylOSjdDIJKmMJZCgBMMn3nQMe3dlp6viMxHGssKxfXm8E= Received: from AM5PR0602CA0019.eurprd06.prod.outlook.com (2603:10a6:203:a3::29) by AM0PR08MB3394.eurprd08.prod.outlook.com (2603:10a6:208:e0::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.24; Thu, 21 May 2020 18:16:48 +0000 Received: from VE1EUR03FT060.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:a3:cafe::a5) by AM5PR0602CA0019.outlook.office365.com (2603:10a6:203:a3::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.23 via Frontend Transport; Thu, 21 May 2020 18:16:48 +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 VE1EUR03FT060.mail.protection.outlook.com (10.152.19.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.3021.23 via Frontend Transport; Thu, 21 May 2020 18:16:48 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Thu, 21 May 2020 18:16:47 +0000 Received: from localhost.localdomain (10.57.25.130) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Thu, 21 May 2020 18:16:47 +0000 From: "Tomas Pilar (tpilar)" To: CC: Ray Ni , Zhichao Gao Subject: [PATCH v1 5/6] ShellPkg/AcpiView: Refactor DumpAcpiTableToFile Date: Thu, 21 May 2020 19:16:28 +0100 Message-ID: <20200521181629.79-6-Tomas.Pilar@arm.com> X-Mailer: git-send-email 2.24.1.windows.2 In-Reply-To: <20200521181629.79-1-Tomas.Pilar@arm.com> References: <20200521181629.79-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)(346002)(136003)(396003)(39860400002)(376002)(46966005)(8936002)(36756003)(1076003)(8676002)(6666004)(26005)(86362001)(5660300002)(70206006)(70586007)(186003)(6916009)(336012)(2616005)(2906002)(426003)(54906003)(82740400003)(81166007)(82310400002)(4326008)(356005)(478600001)(316002)(47076004);DIR:OUT;SFP:1101; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b277250c-68e0-4cf0-90f1-08d7fdb32502 X-MS-TrafficTypeDiagnostic: AM0PR08MB3394:|PR2PR08MB4716: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:9508;OLM:10000; X-Forefront-PRVS: 041032FF37 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: Epp3ESJHWdRtEAeSzMyEW4J2RLVzz8vJJWliqTHOT+IpuyIk7vzTGHkR50D3cI0xhfeDjbdIagR2NDxfjQeV3u03ZY7z2pVTtfcICzj9miJgjJHaqBd7Ku/JqydHt4tiuZDQkpEAyj7B3NHanQ8m8bRhiA4e4ePBQVzxvWQmXavYDIsftZPHpV+Ax6q+3Cg6tIzctAh4VVEAjRptA9nENyIScPfLyWXQdrn3P1bBxH/dWN8tQAMVg3G/yxmSdoA7qb7Sx1eCi3YWRbvLbpKUjaDLH39tUujr82UGby1xlKOoNUATjVeJ2PBvNtENZAOJkvQtX9+f343d9ZrSC4HLDFZp8qvwNpbHIHnM+MwD7HFEb28YnxJwdhpyka2+1tu5OUZTG0lI160RGFAE6Gv+SQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3394 Return-Path: Tomas.Pilar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT064.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)(376002)(396003)(39860400002)(136003)(346002)(46966005)(6666004)(26005)(107886003)(186003)(4326008)(6916009)(316002)(2906002)(36756003)(36906005)(54906003)(478600001)(8936002)(8676002)(5660300002)(70586007)(2616005)(426003)(1076003)(82740400003)(81166007)(47076004)(86362001)(336012)(82310400002)(70206006);DIR:OUT;SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: f251dd1c-57a1-4e40-8950-08d7fdb320cf X-Forefront-PRVS: 041032FF37 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WlFlmjWBCb16xlFQCbQS4xXGBeAq1BiKN3zTlxeIzN6r4wMfszVQZf7hb4Gd9DLFimRVnnCbtu1lG1WBPXTygVBhISw4mS+BD54qYSjoDx1TYvx0nWKz1JA/xVpL13A3cdyE9PCr5UBIsOCPaEmZ82GrHpAgB1ClKANbWDI2fHopLJM2GgC/uIneEqwKxQ4dmRartZXR+F4Z+SnVYUYcfmgNKEgFzkM7E/Sfx/LXNVPFc08G/7HArWGeOm2UI7D+gqeyeXawiTteJVWKIMYfgbebvBRlEnrJ4Vk5JKM5ugL6q+ilQq7MSADtGfYUXUZA6LRjqUFzUOsfRKf5d9hIVoOVEii2v6hpuBSBgF1FXnY9en6pkPqAYEQZNyspFTMcUbPayMdT6anRBij1rJoxIQ== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 May 2020 18:16:55.7543 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b277250c-68e0-4cf0-90f1-08d7fdb32502 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: PR2PR08MB4716 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 --- ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c = | 35 +---------------------------------- ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c= | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.h= | 17 +++++++++++++++++ 3 files changed, 76 insertions(+), 34 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c b/Shel= lPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c index a3160ed6f0a2..e866b84c6844 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c @@ -48,13 +48,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 =3D NULL; TransferBytes =3D Length; GetSelectedAcpiTable (&SelectedTable); @@ -66,39 +63,9 @@ DumpAcpiTableToFile ( mBinTableCount++ ); - 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); - 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 DumpFile (FileNameBuffer, Ptr, Length); return (Length =3D=3D TransferBytes); } diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiView= CommandLib.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiVi= ewCommandLib.c index c3942ad24e5b..adf3cce6cfe2 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommand= Lib.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommand= Lib.c @@ -98,6 +98,64 @@ RegisterAllParsers ( return Status; } +/** + Dump a buffer to a file + + @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 +DumpFile ( + 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. diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiView= CommandLib.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiVi= ewCommandLib.h index a3a29164004d..9dd39cf4b3f0 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommand= Lib.h +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommand= Lib.h @@ -10,6 +10,23 @@ extern EFI_HII_HANDLE gShellAcpiViewHiiHandle; +/** + Dump a buffer to a file + + @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 +DumpFile ( + IN CONST CHAR16* FileNameBuffer, + IN CONST VOID* Buffer, + IN CONST UINTN BufferSize + ); + /** Function for 'acpiview' command. -- 2.24.1.windows.2 IMPORTANT NOTICE: The contents of this email and any attachments are confid= ential and may also be privileged. If you are not the intended recipient, p= lease notify the sender immediately and do not disclose the contents to any= other person, use it for any purpose, or store or copy the information in = any medium. Thank you.