From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web10.9353.1592875505928706769 for ; Mon, 22 Jun 2020 18:25:06 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=WPOHNHaF; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: zhichao.gao@intel.com) IronPort-SDR: 2r0qc/lpXR0vUtIlqHUGyALOy7kMNkEEH4RNFhMrVBH/WTB2lZLqCBTo2H33VJbhvcK+7l6zPt rFWeHHK1iqmg== X-IronPort-AV: E=McAfee;i="6000,8403,9660"; a="205420959" X-IronPort-AV: E=Sophos;i="5.75,268,1589266800"; d="scan'208";a="205420959" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2020 18:25:05 -0700 IronPort-SDR: 5Sm1QHm0W8qGPUuACt/x2TJvoXOzvTj/ySiSeVK4lMtOO/5MPcJIudP4nMQ/SQD8pU3Vq+KxTd yl6h+2+K596g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,268,1589266800"; d="scan'208";a="278947317" Received: from orsmsx110.amr.corp.intel.com ([10.22.240.8]) by orsmga006.jf.intel.com with ESMTP; 22 Jun 2020 18:25:04 -0700 Received: from ORSEDG001.ED.cps.intel.com (10.7.248.4) by ORSMSX110.amr.corp.intel.com (10.22.240.8) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 22 Jun 2020 18:25:03 -0700 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.173) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 22 Jun 2020 18:25:03 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Cjbk7WNvmi5gUaRosCYYcUmM0HM0X8jTg/hgL5G9/KlKgHSxBTxWqdgXDMRPfewrfxHHKYYyVvpRAVBRYlcRvEwgUU/hPfZb5axRql9nBzQf2Di9aVYcvoCiWWZscv5CBA4vFvCVmptg7NZp5R81+uixHOBQ/zqhYTJVX4bkMIhpa05FTzk+M3UG8t6Dt/ciND85whUU4z5n2JcFU11bfozNKoEc9tkI/uwqlOo36omcKfs+36IdR34VUDXP9vWjVRA4zDogaGlniXsnxpx/aOFhZftO9xIYKAEn+enp/e7tKha8bLtTB2t1M03bIci8AX4fyJ4IJEFZRMLL0dQW7Q== 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=3TrBtpqZQJWajPVIjIWOpe4AJnZMvqY0hzD6v9TwXHQ=; b=Mnph4Iu++RJkB7erYIlhmOUyOJS8bjkVTjhHRPcvEUytkDeQKq1ddfEZj4QYb1M0zfSWQUjlrEixj9r7DEWElR1x04aOJF0QYUIloqhMSNdtTsOd5YaVo2zPzqItxQ0ngRqXf3nh+Un8YoK/2Pa1p2mCvV6zZlQjM3VS6p1WksPCGsgiJ6O9RBFz7LGxmb97dW7LL/rEr0Cxeib2fBXW3eTZe7YfArN0EwloVVZg/0IkWlZ36Gk/zrfse30gdhCtcrNYAHW+yMBVNr9CyEX1MtVXkPRKCspwR78hq0obk4WXmlzHFu/eevWYxKcYaXezpzftqX3IKbnsvrbYI1OVAQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3TrBtpqZQJWajPVIjIWOpe4AJnZMvqY0hzD6v9TwXHQ=; b=WPOHNHaFQ115ibRqrygmVkOWe+Nsad1m1MvwXVCpud6607X819YxRERHH0dATUBYQ43tMn8uCJHWIcrr8G4gfLad7VXS1mCqACTfyqrVtjkErLn7O/XRJPUmOmMcfP8utDGWN1w7Js/lZ6Pc980wBLRcgo28XwLc5oRxGwUYpGY= Received: from DM6PR11MB4425.namprd11.prod.outlook.com (2603:10b6:5:1d9::31) by DM5PR11MB1594.namprd11.prod.outlook.com (2603:10b6:4:5::16) 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 01:25:01 +0000 Received: from DM6PR11MB4425.namprd11.prod.outlook.com ([fe80::ad34:e1fc:2e7b:d124]) by DM6PR11MB4425.namprd11.prod.outlook.com ([fe80::ad34:e1fc:2e7b:d124%3]) with mapi id 15.20.3109.027; Tue, 23 Jun 2020 01:25:01 +0000 From: "Gao, Zhichao" To: Tomas Pilar , "devel@edk2.groups.io" CC: "nd@arm.com" , "Ni, Ray" Subject: Re: [PATCH v3 5/7] ShellPkg/AcpiView: Refactor DumpAcpiTableToFile Thread-Topic: [PATCH v3 5/7] ShellPkg/AcpiView: Refactor DumpAcpiTableToFile Thread-Index: AQHWQx38Oaw9Xiu0mUqF9ybbxMl5BKjlc98A Date: Tue, 23 Jun 2020 01:25:01 +0000 Message-ID: References: <20200615140351.1725-1-Tomas.Pilar@arm.com> <20200615140351.1725-6-Tomas.Pilar@arm.com> In-Reply-To: <20200615140351.1725-6-Tomas.Pilar@arm.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.2.0.6 authentication-results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.102.204.45] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 6502355e-7246-4fba-d281-08d81714405f x-ms-traffictypediagnostic: DM5PR11MB1594: x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-forefront-prvs: 04433051BF x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: G+YipKMsKx5gzcjUk0CcVvvgmkWf6Br+TCFD+Mb6/Ph7E0XWBaoefdZh8dkknA+k/xg2g2QirnEEs3pLo8YoYJQ7IepvHC7016q2aDoauMDZjXdp/4++PtJlFL9Jgv6UDJHXTYfu/FMLKZyn0RAz9aSXLSDdKw6arSJpz9gkck52/liokrsaUa2UCsIYMqDdRpVCaicQME4GwqL+VPSTiE0jsFWPmlG7zp/4HIuKC/FwMNWIMHrUpe+BeEB3edhY5iVvmOgdaGB+aYvXdW33ykCVL4iat/pKAtylVGo1XaaCs8069j4p9UFrfuvdGeRW8MQuXQPnxbXTCuZsKunmvw== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR11MB4425.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(6029001)(4636009)(396003)(136003)(376002)(39860400002)(346002)(366004)(52536014)(53546011)(6506007)(186003)(83380400001)(86362001)(5660300002)(26005)(76116006)(66946007)(110136005)(478600001)(2906002)(66476007)(66556008)(64756008)(66446008)(33656002)(7696005)(55016002)(4326008)(71200400001)(316002)(8936002)(9686003)(8676002)(54906003)(107886003);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: yOX4AWGaxy/PGsXRg2AAV7iz+jqzfNKGAbfLmuFbS6k+XlwFH9DpZwtr2wT3mM+fQjR5S6lL0R4XIzU0uWL0n1TB0dGigPHkyfMSeV2kQcGCT7RgYgNitSml7190zJFpD93DZ3hvMQ+xMd8huEmD2lv3VO6RYdbKlauFXUMHr0K1N9hOWSwJE3f0D+KkwfeQkbS1NEVJ7bYF9RDtjRQXAIQI1+XvnPqPYIpFXG6/eXK2oWZgAQOP9MN85HQwJIUaTtzR0syeYWBzLSA9qAfahEJ0WSW/o5V7GmC27hPLXcISvZUjdGsqu4Zlz+sWj9y7iDKeijIg8wK6giM0E9rJTSgubsAOLJUvIVPB4tdKAhv7lH/+TWq4L205IzCg1CKA5S07bhbrD4F4hNHGVEy3BmT/ieQDj+vnnykuep6zxFXk1B0iVWMlUAfH88f8q5zTezprGuScMYlWMEJGizIXj2lvyV0XVpxn+dr+Q6+lUlLAxIiXG1bqaZOVzizrYLCS MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 6502355e-7246-4fba-d281-08d81714405f X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Jun 2020 01:25:01.8502 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: JnB5zBiHlU4bh67JF67jVWy+hcCoL422xKne0LrEWJe78nH25JqoViuz6aWxtqSnV+MW83Yy77apkqVfDa6q6Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR11MB1594 Return-Path: zhichao.gao@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Zhichao Gao Thanks, Zhichao > -----Original Message----- > From: Tomas Pilar > Sent: Monday, June 15, 2020 10:04 PM > To: devel@edk2.groups.io > Cc: nd@arm.com; Ni, Ray ; Gao, Zhichao > > Subject: [PATCH v3 5/7] ShellPkg/AcpiView: Refactor DumpAcpiTableToFile >=20 > 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 c= ore code > after the core code determined the appropriate filename to be used. >=20 > This improves the modular design. >=20 > 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(-) >=20 > 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 >=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_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); >=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/UefiShellAcpiViewCommandLi > b.c > b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLi > b.c > index c3942ad24e5b..e6a65d5bc5f7 100644 > --- > a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLi > b.c > +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewComm > +++ andLib.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 creat= ed. > + > + @param[in] FileName The filename that shall be created to contain th= e 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_CREATE, > + 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/UefiShellAcpiViewCommandLi > b.h > b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLi > b.h > index a3a29164004d..b1b1ffe63e28 100644 > --- > a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLi > b.h > +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewComm > +++ andLib.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 creat= ed. > + > + @param[in] FileName The filename that shall be created to contain th= e 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. > -- > 2.24.1.windows.2 >=20