From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (EUR05-DB8-obe.outbound.protection.outlook.com [40.107.20.59]) by mx.groups.io with SMTP id smtpd.web08.8403.1620383916546275757 for ; Fri, 07 May 2021 03:38:37 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=Rf3s83KT; spf=pass (domain: arm.com, ip: 40.107.20.59, 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=3WVCME9ZvQqgj3CjaN/eEK1K4UYoKAO06zu/P2hKcIw=; b=Rf3s83KTU8M0CTBqafEOlTAW68UDJim8gzDGZdBRJ0Fje/kcyx0RTfJ2DAcESmdtlaXB8NhP5wRf4NkbcjgbD2DkUMJsbQS8h+aeRJyIkaU5crBLWEEkRC+Nozl7zn61BSgTKJUkfErAdT07YwlXHnwlc2XQ8WOr3wmWRZsNKqM= Received: from DB6PR0402CA0008.eurprd04.prod.outlook.com (2603:10a6:4:91::18) by AM0PR08MB3507.eurprd08.prod.outlook.com (2603:10a6:208:dc::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25; Fri, 7 May 2021 10:38:30 +0000 Received: from DB5EUR03FT020.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:91:cafe::3) by DB6PR0402CA0008.outlook.office365.com (2603:10a6:4:91::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Fri, 7 May 2021 10:38:30 +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 DB5EUR03FT020.mail.protection.outlook.com (10.152.20.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Fri, 7 May 2021 10:38:30 +0000 Received: ("Tessian outbound 6c4b4bc1cefb:v91"); Fri, 07 May 2021 10:38:30 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 1e570dba06be487a X-CR-MTA-TID: 64aa7808 Received: from 915c9ee77e01.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 0B9726B1-EFDB-4F55-96D5-CF9FC7CD3F62.1; Fri, 07 May 2021 10:38:22 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 915c9ee77e01.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 07 May 2021 10:38:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BKJ/GMQPjvUla4kxWsiklGRNxz/Pca2BP11TERs5d5EhgJg6q5vhRC2NmJZ1AUwypN1zG1y6z2WgwWHkXzhIn77oU11xHyy9dbT2er2J+iGawoXEHq9OguoTG6S0b+xEfnpMlxR1K8tW0sfRF9HTTVdUiq59sY01E9YqXvRtTW2KVHL48KxZr8g3CC3QNHjePACR/00cdU+OO6HidP1VldQQpKt0Y1YIgqd5/QgKLpl/7XT1HFF0nuYqy0SJDIHQsm5unbFCErmytIyng0PwWg4levG1wSFjdJU3yPXBQnKIU5QAarnKUvi9QZDqoUmWue82MfGcl4ScbLGTaftAiA== 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=3WVCME9ZvQqgj3CjaN/eEK1K4UYoKAO06zu/P2hKcIw=; b=QbNAGcWLz81fMZP/udHsG7LVg7xQtD+9XDsPdDclzen5F6uJ2VhpcERFEAOqHCTtg21xkZAA/agDwRUM2ywwEBwgUjWjnhdMdIrtlb9v3+EYWzVAHwIMS0sX8sAzUEa1tWDhQdjBYcnivU4B1OJDvEDpd5g9yx80FYa8cPkUK5fHqaYoxpfi3yg4y0tu/76Y15O/ghzG+qVuD5dLH9jNExCX4lF+sp/Nu7wpxbtW7heE9BrhA90iyRbcB3Xdy5SLd0ViJPmLAO7wJPusKkSD7jUPgbkyPye6KysVLrkD9s79jras7dfxgatvSDwb3SjTF4jfaTv/HUwiY56eDbGmnQ== 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=3WVCME9ZvQqgj3CjaN/eEK1K4UYoKAO06zu/P2hKcIw=; b=Rf3s83KTU8M0CTBqafEOlTAW68UDJim8gzDGZdBRJ0Fje/kcyx0RTfJ2DAcESmdtlaXB8NhP5wRf4NkbcjgbD2DkUMJsbQS8h+aeRJyIkaU5crBLWEEkRC+Nozl7zn61BSgTKJUkfErAdT07YwlXHnwlc2XQ8WOr3wmWRZsNKqM= Received: from AM6PR0202CA0046.eurprd02.prod.outlook.com (2603:10a6:20b:3a::23) by AS8PR08MB6103.eurprd08.prod.outlook.com (2603:10a6:20b:296::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.26; Fri, 7 May 2021 10:38:14 +0000 Received: from AM5EUR03FT033.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:3a:cafe::6b) by AM6PR0202CA0046.outlook.office365.com (2603:10a6:20b:3a::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.24 via Frontend Transport; Fri, 7 May 2021 10:38:14 +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 AM5EUR03FT033.mail.protection.outlook.com (10.152.16.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4108.25 via Frontend Transport; Fri, 7 May 2021 10:38:13 +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.2176.2; Fri, 7 May 2021 10:38:05 +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.2176.2 via Frontend Transport; Fri, 7 May 2021 10:38:04 +0000 From: "Joey Gouly" To: CC: , , , , Subject: [PATCH v1 2/5] ShellPkg: add a helper function for getting a new file name Date: Fri, 7 May 2021 11:38:01 +0100 Message-ID: <20210507103804.8131-3-joey.gouly@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210507103804.8131-1-joey.gouly@arm.com> References: <20210507103804.8131-1-joey.gouly@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: beccfa80-ffe8-4c8c-4e6d-08d91144417a X-MS-TrafficTypeDiagnostic: AS8PR08MB6103:|AM0PR08MB3507: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:473;OLM:473; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 4Z0Pvz0QXwX9eESfkZhbgIobYC9+AO86DTVqZxrtNADrmXfkyDQwnYg7RRKC6up86W13HEqeDRQtQb/WCeOsYcPCNfT9dWsCmgCsAjCg6fOx2NQeXwiDKSUJU2Fo9oEms4SW9+35fC8edqttwGlSRheyVRb0row8hEyUzv76Im+J+FZp4/4WughRye2NGRCcVeo49L4f3uPxnPKS+fsTJJtGLWcPQRAzmCjTzoBgC2TSpJCkw98JYnxkZnIJlnDbz08ylSfCYaBYltuV6Lt6b3zZg3dwA5F6AUEVqIdzP8elTQK3DExwNJ1JpKrFXf5YWunKf9awZMYPZClQQImEY3PHVqCj/FGKOrfEMthc9H80U6ca4jJdiWX8ZfVTtRjTSlFS1Q86LiF56pTgjycscxVLHaeE+GVuFTtl2CZFbWxYpNxHpgAXcIyY+4rtMM8HuXe6UrqqSZLo9o78l1mTLlyrCUvo58+G/GVFKv4xYCz0+ioAeZpW/h3uV6bqW2SQg3mWlmbh3s/z3J0d+VIPpOBisKr+EhARrOyGbHJv8zTyUAJAsK+NVNhYl7EV1B9dooGtUkADSGZXk5MrrzZ2GXV4gVz1q/wdu5FzqoexOAT2aNUH2nI4pJfx/gePtznVFB/6FwqJ0SeLIxn7X68EcXr/h/yrpi2kQM8B7cpPiHjXtdn1Ibl6UECjIdqvy8UUtf5tMoGcH28CkbZSAY8NYabUkV53rtUGw3d+OWuHzIHoC/lqh6m4/pw70sx/HsqRC78XmqgDmozflGkXg5kY3w== 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)(39850400004)(376002)(136003)(346002)(396003)(36840700001)(46966006)(336012)(82310400003)(7696005)(8676002)(2906002)(26005)(6666004)(47076005)(83380400001)(36860700001)(81166007)(316002)(54906003)(4326008)(186003)(70586007)(2616005)(6916009)(1076003)(36756003)(5660300002)(82740400003)(478600001)(86362001)(44832011)(356005)(426003)(70206006)(8936002)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6103 Return-Path: Joey.Gouly@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT020.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 6bbe18c4-bf58-4593-e59d-08d9114437a6 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3S5YBdL+sNmAydZEvC7tu63Zyb4MdZgBeP2U3crNLH77Mha0ebL+aPMHjku4uPMEuo8BKCReqn0WVAghu1kN0hR3eIC1LFMfhHEMZHFJEAH86xCXDdTycWdRLUsqvSUAF2MUjun6h8gTRrAt1xlztChwp6D8q3WGvMfFJBpEZIhbGOySGfg8FYD7lTae3GslS7qZszDv/aCqdIlNyNcSTKkZhfDrEBqk4ioA+0lHA0XuOy+9n45QSUBjYZSl5zcfMxlb18tSY0KO6tXJvzoH+cVvtKtvj9YCTDxPyCQLYc5FwP8cz491korXXg9GH/cgK+lCTUWxGo7hozGEOMmq2TV5LwArTq18l1pqjNxrMcwL518TjvcYXV2LNuoXhk50Z9J0EO8fSHFIJ0iKOoFGUGF5QkOCPsKjZvHx8nTn8QHavloDotxdswPB24SUVo6EnpIdz/U6iwxvbVnYe3COxLAuKEMHzLJ9rI3EGTNDAm1uwrx6tYqc4kBSdFrLkdqtW4KafvqhIoq2n0XcMUEzuAVXXf9K7VCPV9X7h0gIAxdg0nRuBGV2b5WZoROrmbvW8VKD6LRal2VOIfzC+Dgop/eI6KSlrLlcuY1pTBUdzh/U3dKh8P5WgDBPmQyfz8HlJo2gQf5xHNF6yfZ7r738Xb9JIpWAT0gCHyGIIf+7XcE/S72PGrGsgzQsKOafGHfHzP8sTzid0Ve3yF9Yq7xbV76howq+S5RrkyYT6gfbkgI= 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)(39850400004)(396003)(136003)(346002)(376002)(46966006)(36840700001)(86362001)(44832011)(8936002)(7696005)(316002)(83380400001)(47076005)(2616005)(82740400003)(36756003)(26005)(70206006)(478600001)(426003)(6916009)(36860700001)(81166007)(5660300002)(82310400003)(2906002)(6666004)(1076003)(336012)(186003)(4326008)(54906003)(8676002)(70586007);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2021 10:38:30.3548 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: beccfa80-ffe8-4c8c-4e6d-08d91144417a 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: DB5EUR03FT020.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3507 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: Marc Moisson-Franckhauser 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")