From nobody Thu May 2 02:13:47 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1503994278093225.8800028856656; Tue, 29 Aug 2017 01:11:18 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id AEF8521E2BE58; Tue, 29 Aug 2017 01:08:33 -0700 (PDT) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 77A2C21C9127B for ; Tue, 29 Aug 2017 01:08:32 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Aug 2017 01:11:12 -0700 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.2]) by fmsmga001.fm.intel.com with ESMTP; 29 Aug 2017 01:11:11 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,444,1498546800"; d="scan'208";a="1189250906" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Tue, 29 Aug 2017 16:11:05 +0800 Message-Id: <20170829081107.442452-2-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.12.2.windows.2 In-Reply-To: <20170829081107.442452-1-ruiyu.ni@intel.com> References: <20170829081107.442452-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 1/3] ShellPkg: Rename gShellCurDir to gShellCurMapping X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Huajing Li MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Huajing Li Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Huajing Li Reviewed-by: Ruiyu Ni Reviewed-by: Jaben Carsey --- ShellPkg/Application/Shell/ShellProtocol.c | 8 ++++---- ShellPkg/Include/Library/ShellCommandLib.h | 4 ++-- ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ShellPkg/Application/Shell/ShellProtocol.c b/ShellPkg/Applicat= ion/Shell/ShellProtocol.c index 991fb58ca7..40e5e653ae 100644 --- a/ShellPkg/Application/Shell/ShellProtocol.c +++ b/ShellPkg/Application/Shell/ShellProtocol.c @@ -3079,10 +3079,10 @@ EfiShellSetCurDir( // make that the current file system mapping // if (MapListItem !=3D NULL) { - gShellCurDir =3D MapListItem; + gShellCurMapping =3D MapListItem; } } else { - MapListItem =3D gShellCurDir; + MapListItem =3D gShellCurMapping; } =20 if (MapListItem =3D=3D NULL) { @@ -3131,7 +3131,7 @@ EfiShellSetCurDir( FreePool (DirectoryName); return (EFI_INVALID_PARAMETER); } -// gShellCurDir =3D MapListItem; +// gShellCurMapping =3D MapListItem; if (DirectoryName !=3D NULL) { // // change current dir on that file system @@ -3157,7 +3157,7 @@ EfiShellSetCurDir( // // if updated the current directory then update the environment variable // - if (MapListItem =3D=3D gShellCurDir) { + if (MapListItem =3D=3D gShellCurMapping) { Size =3D 0; ASSERT((TempString =3D=3D NULL && Size =3D=3D 0) || (TempString !=3D N= ULL)); StrnCatGrow(&TempString, &Size, MapListItem->MapName, 0); diff --git a/ShellPkg/Include/Library/ShellCommandLib.h b/ShellPkg/Include/= Library/ShellCommandLib.h index c11d81d506..616b0d3267 100644 --- a/ShellPkg/Include/Library/ShellCommandLib.h +++ b/ShellPkg/Include/Library/ShellCommandLib.h @@ -4,7 +4,7 @@ This library is for use ONLY by shell commands linked into the shell app= lication. This library will not function if it is used for UEFI Shell 2.0 Applicat= ions. =20 - Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
(C) Copyright 2016 Hewlett Packard Enterprise Development LP
(C) Copyright 2013-2014 Hewlett-Packard Development Company, L.P.
This program and the accompanying materials @@ -48,7 +48,7 @@ typedef struct { /// List of Mappings - DeviceName and Drive Letter(ism). extern SHELL_MAP_LIST gShellMapList; /// Pointer to node of current directory in the mMapList. -extern SHELL_MAP_LIST *gShellCurDir; +extern SHELL_MAP_LIST *gShellCurMapping; =20 /** Returns the help MAN fileName for a given shell command. diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/S= hellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c index bd14878052..b9158d1243 100644 --- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c +++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c @@ -1,7 +1,7 @@ /** @file Provides interface to shell internal functions for shell commands. =20 - Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
(C) Copyright 2016 Hewlett Packard Enterprise Development LP
=20 @@ -53,7 +53,7 @@ STATIC CONST CHAR8 Hex[] =3D { // global variables required by library class. EFI_UNICODE_COLLATION_PROTOCOL *gUnicodeCollation =3D NULL; SHELL_MAP_LIST gShellMapList; -SHELL_MAP_LIST *gShellCurDir =3D NULL; +SHELL_MAP_LIST *gShellCurMapping =3D NULL; =20 CONST CHAR16* SupportLevel[] =3D { L"Minimal", @@ -229,7 +229,7 @@ ShellCommandLibDestructor ( } =20 gUnicodeCollation =3D NULL; - gShellCurDir =3D NULL; + gShellCurMapping =3D NULL; =20 return (RETURN_SUCCESS); } --=20 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 02:13:47 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1503994280671425.1425196034701; Tue, 29 Aug 2017 01:11:20 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E966F21E2BE52; Tue, 29 Aug 2017 01:08:35 -0700 (PDT) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5D3CC21E2BE46 for ; Tue, 29 Aug 2017 01:08:33 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Aug 2017 01:11:13 -0700 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.2]) by fmsmga001.fm.intel.com with ESMTP; 29 Aug 2017 01:11:12 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,444,1498546800"; d="scan'208";a="1189250912" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Tue, 29 Aug 2017 16:11:06 +0800 Message-Id: <20170829081107.442452-3-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.12.2.windows.2 In-Reply-To: <20170829081107.442452-1-ruiyu.ni@intel.com> References: <20170829081107.442452-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 2/3] ShellPkg: Fix bug that fails to change CWD after "map -r". X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Huajing Li MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Huajing Li When "map -r" runs, the mapping list is re-created but gShellCurMapping still points to the old mapping list which is already destroyed. The patch updates the gShellCurMapping to point to the correct location in the new mapping list. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Huajing Li Reviewed-by: Ruiyu Ni Reviewed-by: Jaben Carsey --- .../UefiShellCommandLib/UefiShellCommandLib.c | 36 ++++++++++++++++++= +++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/S= hellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c index b9158d1243..c7984f11b2 100644 --- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c +++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c @@ -1268,7 +1268,14 @@ ShellCommandCreateInitialMappingsAndPaths( CHAR16 *NewConsistName; EFI_DEVICE_PATH_PROTOCOL **ConsistMappingTable; SHELL_MAP_LIST *MapListNode; - + CONST CHAR16 *CurDir; + CHAR16 *SplitCurDir; + CHAR16 *MapName; + SHELL_MAP_LIST *MapListItem; + + SplitCurDir =3D NULL; + MapName =3D NULL; + MapListItem =3D NULL; HandleList =3D NULL; =20 // @@ -1354,6 +1361,33 @@ ShellCommandCreateInitialMappingsAndPaths( SHELL_FREE_NON_NULL(DevicePathList); =20 HandleList =3D NULL; + + // + //gShellCurMapping point to node of current file system in the gShellM= apList. When reset all mappings, + //all nodes in the gShellMapList will be free. Then gShellCurMapping w= ill be a dangling pointer, So, + //after created new mappings, we should reset the gShellCurMapping poi= nter back to node of current file system. + // + if (gShellCurMapping !=3D NULL) { + gShellCurMapping =3D NULL; + CurDir =3D gEfiShellProtocol->GetEnv(L"cwd"); + if (CurDir !=3D NULL) { + MapName =3D AllocateCopyPool (StrSize(CurDir), CurDir); + if (MapName =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + SplitCurDir =3D StrStr (MapName, L":"); + if (SplitCurDir =3D=3D NULL) { + SHELL_FREE_NON_NULL (MapName); + return EFI_UNSUPPORTED; + } + *(SplitCurDir + 1) =3D CHAR_NULL; + MapListItem =3D ShellCommandFindMapItem (MapName); + if (MapListItem !=3D NULL) { + gShellCurMapping =3D MapListItem; + } + SHELL_FREE_NON_NULL (MapName); + } + } } else { Count =3D (UINTN)-1; } --=20 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 02:13:47 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1503994284005347.9459316343624; Tue, 29 Aug 2017 01:11:24 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2DA3021E2BE5E; Tue, 29 Aug 2017 01:08:36 -0700 (PDT) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3E9E721D2E640 for ; Tue, 29 Aug 2017 01:08:34 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Aug 2017 01:11:14 -0700 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.2]) by fmsmga001.fm.intel.com with ESMTP; 29 Aug 2017 01:11:13 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,444,1498546800"; d="scan'208";a="1189250917" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Tue, 29 Aug 2017 16:11:07 +0800 Message-Id: <20170829081107.442452-4-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.12.2.windows.2 In-Reply-To: <20170829081107.442452-1-ruiyu.ni@intel.com> References: <20170829081107.442452-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 3/3] ShellPkg: Update CWD and current mapping when commands return X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Huajing Li MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Huajing Li Some commands may cause current directory or even current mapping become invalid. For example, "MAP" after unplugging the USB thumb key may cause current mapping "FS0:" disappear. This patch updates the CWD and current mapping when commands return. It also causes the command prompt change to default "Shell>". Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Huajing Li Reviewed-by: Ruiyu Ni Reviewed-by: Jaben Carsey --- ShellPkg/Application/Shell/Shell.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shel= l/Shell.c index fcf47b5c73..5471930ba1 100644 --- a/ShellPkg/Application/Shell/Shell.c +++ b/ShellPkg/Application/Shell/Shell.c @@ -2614,6 +2614,7 @@ RunShellCommand( CHAR16 *FirstParameter; CHAR16 *TempWalker; SHELL_OPERATION_TYPES Type; + CONST CHAR16 *CurDir; =20 ASSERT(CmdLine !=3D NULL); if (StrLen(CmdLine) =3D=3D 0) { @@ -2705,7 +2706,22 @@ RunShellCommand( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), Shel= lInfoObject.HiiHandle, FirstParameter); SetLastError(SHELL_NOT_FOUND); } -=20 + // + // Check whether the current file system still exists. If not exist, we = need update "cwd" and gShellCurMapping. + // + CurDir =3D EfiShellGetCurDir (NULL); + if (CurDir !=3D NULL) { + if (EFI_ERROR(ShellFileExists (CurDir))) { + // + // EfiShellSetCurDir() cannot set current directory to NULL. + // EfiShellSetEnv() is not allowed to set the "cwd" variable. + // Only InternalEfiShellSetEnv () is allowed setting the "cwd" varia= ble. + // + InternalEfiShellSetEnv (L"cwd", NULL, TRUE); + gShellCurMapping =3D NULL; + } + } + SHELL_FREE_NON_NULL(CleanOriginal); SHELL_FREE_NON_NULL(FirstParameter); =20 --=20 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel