From nobody Mon Feb 9 18:44:25 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61606+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1592919822839133.3414792158609; Tue, 23 Jun 2020 06:43:42 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ZJ1mYY1788612x5fKQUFwdga; Tue, 23 Jun 2020 06:43:42 -0700 X-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 X-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 X-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 (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+61606+1787277+3901457@groups.io; helo=web01.groups.io; 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; X-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 X-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 X-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 X-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 X-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 X-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; X-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 X-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 X-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 X-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: [edk2-devel] [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> 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-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 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT058.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 304e9d9f-4c6b-4d26-b8f4-08d8177b6a1f 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 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,Tomas.Pilar@arm.com X-Gm-Message-State: iezbMMXSiIOGNsSOhbjwf11qx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1592919822; bh=7Cpe8nHlg0fDXm2KB84nMUp0+JTVDFCAOxCQYBHhJsE=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=YcIU3r9NQhM6CUzW0G/Xc6K+bVK0kVr920x8tBuQACh/kP34zJ2V3nAdypBIwoTS0ir lbQ0O9YrCnCESpH6A5yvNyRBCWF3AQofDDZ2axlOeIqNYSQHP2ACQpVzrJYnBG1jfshDf eO7q3JmB1uQeLrMUrczKL5JhuMtgFYQE4qw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: 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 e524fcb0b27a..d2240b2e89d5 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 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#61606): https://edk2.groups.io/g/devel/message/61606 Mute This Topic: https://groups.io/mt/75059846/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-