From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR03-AM5-obe.outbound.protection.outlook.com (EUR03-AM5-obe.outbound.protection.outlook.com [40.107.3.46]) by mx.groups.io with SMTP id smtpd.web08.225.1631803580842709204 for ; Thu, 16 Sep 2021 07:46:21 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=7FfZDmI1; spf=pass (domain: arm.com, ip: 40.107.3.46, mailfrom: joey.gouly@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=Ot8rS2CH5oi1pRCwtzcdnx2Jbv1StEdTtchFe/5eFAQ=; b=7FfZDmI1jCMIcgNAu4IiBk1RgwT+BjeJ4zd+5u5sgLETc65Hmet54geZCgszEg4tVU6n1CqTYerbvWPmCeZWK6b27/KgWJnxiYwIRrLE2kBX3baGc3+MJDpssVfkLx55dbLRvu3Spa2ddFAEkS1NkewtAJejjoJe4Fob8K/8RNg= Received: from AM5PR0701CA0066.eurprd07.prod.outlook.com (2603:10a6:203:2::28) by DB8PR08MB3947.eurprd08.prod.outlook.com (2603:10a6:10:ae::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.15; Thu, 16 Sep 2021 14:46:16 +0000 Received: from VE1EUR03FT032.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:2:cafe::61) by AM5PR0701CA0066.outlook.office365.com (2603:10a6:203:2::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.6 via Frontend Transport; Thu, 16 Sep 2021 14:46:16 +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=pass 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 VE1EUR03FT032.mail.protection.outlook.com (10.152.18.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Thu, 16 Sep 2021 14:46:15 +0000 Received: ("Tessian outbound a8bfe25d7364:v103"); Thu, 16 Sep 2021 14:46:15 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 34271058d2fed4d7 X-CR-MTA-TID: 64aa7808 Received: from 497e6df1c115.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 39D8C5CE-8B1E-4B3B-A319-A493E076D030.1; Thu, 16 Sep 2021 14:46:08 +0000 Received: from EUR02-AM5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 497e6df1c115.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 16 Sep 2021 14:46:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BUY54hCd1OgKc7/yF8qc89eeSSSgd2WOmynYK9817wIhuhf933sWAmI8Iwijr3TmsYEKfFQaY0dsGw9MPsXRuY7LELkg5fRKZ9/c6uo6gHeUN09WIl/8lvWfwtzDzcH2BLmhWRdm9EO5q0gZ+iO7Vd0LzGC5y2trRKnOPZrkwy34e1gz4KAkIk2XBM2GVsaq2h6rCWmBwH2k6QZ6q7WT16t/KtCT0RTbN5OCwhFgeYEw4lAmWoxoLk1zzpNbpeABMWC163CF/XlkdieYKzeU2qp7f/VBdwzuHdVRHgBRG8TjvY2N4ud1cUF/p57VMcSNr7Ayh8PekL7UQQ14RVmPiQ== 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; bh=Ot8rS2CH5oi1pRCwtzcdnx2Jbv1StEdTtchFe/5eFAQ=; b=Ftt988BK5eNpdLn68/f8/1HBqEQ31Pic3yC/EQt7P2O8ZotqAWN0NvgiwxybrJ820fnpseo+ChI67ZkDRKDTwiMGf5XXDTbPxHOb22Z0W/zaboES/8j0eqYQ1BCVpxlNLVMveJkSsan5G8mkEXjVyscUYzX2SHK9cKf1iWeHaY2K7cf9hTG+EQbOSQIZMOReJomT4YPQDNvaojw5USZ39eUB2Nhoecsaqdm9s6rb2Iojf6RSnQNxAqe7IcfVkDUnpT3nojNKH21xB2U0mz9EdU+IKKufiiLVpdlltUNQ65vVNEJzCkrP9bD1j5+UKqf9no2ewvkVOCgHIbji/eYpbA== 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=pass (p=none sp=none pct=100) 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=Ot8rS2CH5oi1pRCwtzcdnx2Jbv1StEdTtchFe/5eFAQ=; b=7FfZDmI1jCMIcgNAu4IiBk1RgwT+BjeJ4zd+5u5sgLETc65Hmet54geZCgszEg4tVU6n1CqTYerbvWPmCeZWK6b27/KgWJnxiYwIRrLE2kBX3baGc3+MJDpssVfkLx55dbLRvu3Spa2ddFAEkS1NkewtAJejjoJe4Fob8K/8RNg= Received: from DU2PR04CA0233.eurprd04.prod.outlook.com (2603:10a6:10:2b1::28) by DBAPR08MB5750.eurprd08.prod.outlook.com (2603:10a6:10:1a6::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Thu, 16 Sep 2021 14:46:07 +0000 Received: from DB5EUR03FT020.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:2b1:cafe::ee) by DU2PR04CA0233.outlook.office365.com (2603:10a6:10:2b1::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.16 via Frontend Transport; Thu, 16 Sep 2021 14:46:07 +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=pass 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 DB5EUR03FT020.mail.protection.outlook.com (10.152.20.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4523.14 via Frontend Transport; Thu, 16 Sep 2021 14:46:07 +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.2308.14; Thu, 16 Sep 2021 14:46:14 +0000 Received: from e124191.cambridge.arm.com (10.11.7.12) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.14 via Frontend Transport; Thu, 16 Sep 2021 14:46:14 +0000 From: "Joey Gouly" To: CC: , , , , Subject: [PATCH v2 2/5] ShellPkg: add a helper function for getting a new file name Date: Thu, 16 Sep 2021 15:46:02 +0100 Message-ID: <20210916144605.42071-3-joey.gouly@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210916144605.42071-1-joey.gouly@arm.com> References: <20210916144605.42071-1-joey.gouly@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1580bfde-ea2e-4b03-f974-08d97920bc96 X-MS-TrafficTypeDiagnostic: DBAPR08MB5750:|DB8PR08MB3947: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:473;OLM:473; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: jHNytOYcfS2/AN/Vjc5KkIjGuOtGc6jF2rinu4eWbhVxx0Zq4YzNmpy893tJXOE5S9Dq7/fZ+Qs8P815EHia/TSeyJLDGVwGwtjIVEmQ+/J0KP+zEMTkWJnuXJpxBZPMz68ceIq6bFATIWhM5hrNwIcBKkt9xGv/mV+Er82Kutm8UbVaxXmIuxrPYlchz0WJ3kJz7HVtqtUatmzDWN80LSC3NEnI5Ee5OGQi1DtfmWpczmPCaWQXiAML9M1cqDoPtrY+i9kOJv+HuWMrvX02PIpA12ylFvulr+6yWQ4m4h/8uBp7yMLHRO6xm7nz/9AoS2/FO/04/+fvHnmcgbiuZ6bBRdsvEvng2/Y3d/fMTk8eJWtCbPUgcd3+S2ozxpCKYm2I3uBwUVTQX2wZ7yOBq4MNEX/vsP6wtgKbeBDD2k1otM8BvCdy93DtybOLgN18XgQBtiiIaLKcgEOCGXu65FLBLVwdWaY3kf2Imo4wGdBU6Mkq7Ozd1I5uOkiaKxSWs3yWJDoR8fLSKpSYavdIlgL2dRqYzL3wznGQp90uhkLJ8RkHraLSvNlpC6hU5QGRjWlc8241gd/nbq5ppIb1syxzxPvBHjGHYw5WWZ5EPwm82ParU8lMyt0M6uTYKWTHyHcoVrs4x9+F84tw1fE07K51npwiteS9IOyDPjLdFzBfAM34YeF1rcXr5vf+4d158bGyzPOfllMFBF3FfNUc++mJuoxewKS4myjsvQP5Rdvzpsbp6lty+XhebrKE5ilr+SVxb5rgY29tJWORmlQU9FkewSPg9b2dQnYUc+V2E2JmUEUfNC3YaRMjyGeb/VZA 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;SFS:(4636009)(376002)(396003)(39860400002)(136003)(346002)(36840700001)(46966006)(2616005)(70206006)(36860700001)(6916009)(70586007)(1076003)(4326008)(2906002)(426003)(47076005)(336012)(82310400003)(83380400001)(316002)(8676002)(36756003)(478600001)(356005)(6666004)(81166007)(8936002)(7696005)(82740400003)(5660300002)(26005)(86362001)(54906003)(186003)(44832011)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR08MB5750 Return-Path: Joey.Gouly@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT032.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 00ea9306-ab95-4f6c-c92c-08d97920b779 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /9D4/XVflPEXi41eAC8BqmlNuUf1ji9jvJvmBwGiV0aDoF7sfvCG3rSfm/gCu3a65fXVBMJsDhNNG94TUVZieaMB7xe38QmUPhrMvvzf73rrf/+S1KDO0Mfb2iA56sFUqKUhcWEWI/F3ZWPMQlHyIg6/NSEgkr1a6/cO+H7wfpk3xPh5Xd2Cne5tV+qtB4aWx9lajPwuDoPBc7FskK9jmr+AK5Ww7KbcZ6ABTVjEXRxqgPlTvC6DnK7xA14Ro0nyh4LpdsEXQ1H+rSIZA9iJ63OXRbSNG0moRINUhQybqznyY6su0+Mhs8lVPKB5OdGBefG55LsUv/b/nQwlu39wvCfSkbMDz67M6OLrJi7NCGFQOHABCmbti3UDyYCMhTrjbpzMoa0tBHcO0unJYVzgnK5E0w3qQf/LwemSdHTavvgztxWArDzoH7agmm5RdvtEDDKz3ue2f1MfGvl2qnqc89r7BVP2q29Jz6lncwZ8za9dovBkwzvKxQXYb9mTj+GCWkxRpxi1AcmZKdWP5ORfmVaEeRlQWIij+sdaK4nX5zsp3XCO3vtJkvn0SRruCcOWAFXhzRp8O3iDckt9RbZdfXkaVnMOJY4n8OsTg52fURVrFlgF5pAukJX3U3M7JPmY/5R1NgjM/IonL5Asr/OapmHD/hgg1NxXKOkwfuktHJzZuVZdF8Qx0IJtYyYLBj0F7U+CEkg2ipL4ZnQ6j7JO/qelOf1YpmsQasBkCNSvYJmrsBgPFsqJ9qwG+fO1MkQNMXkZwGnGpWeXRmZZPRCF1nezipNGMMClts3MVB51JBc= 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;SFS:(4636009)(36840700001)(46966006)(4326008)(82310400003)(44832011)(26005)(36756003)(81166007)(2616005)(6916009)(86362001)(316002)(70206006)(2906002)(336012)(508600001)(8676002)(70586007)(426003)(54906003)(83380400001)(47076005)(7696005)(36860700001)(1076003)(186003)(5660300002)(8936002)(6666004);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2021 14:46:15.8501 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1580bfde-ea2e-4b03-f974-08d97920bc96 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-AuthSource: VE1EUR03FT032.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB3947 Content-Type: text/plain From: Marc Moisson-Franckhauser Bugzilla: 3378 (https://bugzilla.tianocore.org/show_bug.cgi?id=3378) This new helper will not overwrite existing files, by appending a number to the end of the filename. Signed-off-by: Joey Gouly --- ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.h | 25 +++++- ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c | 80 ++++++++++++++++---- 2 files changed, 91 insertions(+), 14 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.h index d5b95f5ee707de18be1879b3cd235d6c5db11d9f..ae8a67b7681033d66d068341ae489ded67de8b44 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.h +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.h @@ -1,12 +1,13 @@ /** @file Header file for AcpiView - Copyright (c) 2016 - 2020, ARM Limited. All rights reserved. + Copyright (c) 2016 - 2021, Arm Limited. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ #ifndef ACPIVIEW_H_ #define ACPIVIEW_H_ +#include /** A macro to define the max file name length @@ -23,6 +24,28 @@ **/ #define RSDP_LENGTH_OFFSET 20 +/** + This function finds a filename not already used by adding a number in between + the BaseFileName and the extension. + + Make sure the buffer FileName is big enough before calling the function. A + size of MAX_FILE_NAME_LEN is recommended. + + @param [in] BaseFileName Start of the desired file name. + @param [in] Extension Extension of the desired file name + (without '.'). + @param [in, out] FileName Preallocated buffer for the returned file + name. + @param [in] FileNameBufferLen Size of FileName buffer.. +**/ +EFI_STATUS +GetNewFileName ( + IN CONST CHAR16* BaseFileName, + IN CONST CHAR16* Extension, + IN OUT CHAR16* FileName, + IN UINT32 FileNameBufferLen + ); + /** This function resets the ACPI table error counter to Zero. **/ diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c index a4242ba9d99b05d07c829520c4011439445aadb0..db7b2e2a30525cc85a333b93f5eb97ec3a517b37 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c @@ -27,8 +27,55 @@ #include "Arm/SbbrValidator.h" #endif -STATIC UINT32 mTableCount; -STATIC UINT32 mBinTableCount; +STATIC UINT32 mTableCount; + +/** + This function finds a filename not already used by adding a number in between + The BaseFileName and the extension. + + Make sure the buffer FileName is big enough before calling the function. A + size of MAX_FILE_NAME_LEN is recommended. + + @param [in] BaseFileName Start of the desired file name. + @param [in] Extension Extension of the desired file name + (without '.'). + @param [in, out] FileName Preallocated buffer for the returned file + name. + @param [in] FileNameBufferLen Size of FileName buffer.. +**/ +EFI_STATUS +GetNewFileName ( + IN CONST CHAR16* BaseFileName, + IN CONST CHAR16* Extension, + IN OUT CHAR16* FileName, + IN UINT32 FileNameBufferLen + ) +{ + UINT16 Index; + EFI_STATUS Status; + SHELL_FILE_HANDLE tmpFileHandle; + for (Index = 0; Index <= 99; Index++) { + UnicodeSPrint( + FileName, + FileNameBufferLen, + L"%s%02d.%s", + BaseFileName, + Index, + Extension + ); + Status = ShellOpenFileByName ( + FileName, + &tmpFileHandle, + EFI_FILE_MODE_READ, + 0 + ); + if (Status == EFI_NOT_FOUND) { + return EFI_SUCCESS; + } + ShellCloseFile (&tmpFileHandle); + } + return EFI_OUT_OF_RESOURCES; +} /** This function dumps the ACPI table to a file. @@ -46,19 +93,27 @@ DumpAcpiTableToFile ( IN CONST UINTN Length ) { - CHAR16 FileNameBuffer[MAX_FILE_NAME_LEN]; - UINTN TransferBytes; - SELECTED_ACPI_TABLE *SelectedTable; + CHAR16 FileNameBuffer[MAX_FILE_NAME_LEN]; + UINTN TransferBytes; + EFI_STATUS Status; + SELECTED_ACPI_TABLE* SelectedTable; GetSelectedAcpiTable (&SelectedTable); - UnicodeSPrint ( - FileNameBuffer, - sizeof (FileNameBuffer), - L".\\%s%04d.bin", - SelectedTable->Name, - mBinTableCount++ - ); + Status = GetNewFileName ( + SelectedTable->Name, + L"bin", + FileNameBuffer, + sizeof (FileNameBuffer) + ); + if (EFI_ERROR (Status)) { + Print ( + L"Error: Could not open bin file for %s table:\n" + L"Could not get a file name.", + SelectedTable->Name + ); + return FALSE; + } Print (L"Dumping ACPI table to : %s ... ", FileNameBuffer); @@ -207,7 +262,6 @@ AcpiView ( // Reset Table counts mTableCount = 0; - mBinTableCount = 0; // Reset The error/warning counters ResetErrorCount (); -- Guid("CE165669-3EF3-493F-B85D-6190EE5B9759")