From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,444,1498546800"; d="scan'208";a="1189250912" 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 From: Ruiyu Ni To: edk2-devel@lists.01.org Cc: Huajing Li 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: [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: , X-List-Received-Date: Tue, 29 Aug 2017 08:08:33 -0000 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 --- .../UefiShellCommandLib/UefiShellCommandLib.c | 36 +++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/ShellPkg/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 = NULL; + MapName = NULL; + MapListItem = NULL; HandleList = NULL; // @@ -1354,6 +1361,33 @@ ShellCommandCreateInitialMappingsAndPaths( SHELL_FREE_NON_NULL(DevicePathList); HandleList = NULL; + + // + //gShellCurMapping point to node of current file system in the gShellMapList. When reset all mappings, + //all nodes in the gShellMapList will be free. Then gShellCurMapping will be a dangling pointer, So, + //after created new mappings, we should reset the gShellCurMapping pointer back to node of current file system. + // + if (gShellCurMapping != NULL) { + gShellCurMapping = NULL; + CurDir = gEfiShellProtocol->GetEnv(L"cwd"); + if (CurDir != NULL) { + MapName = AllocateCopyPool (StrSize(CurDir), CurDir); + if (MapName == NULL) { + return EFI_OUT_OF_RESOURCES; + } + SplitCurDir = StrStr (MapName, L":"); + if (SplitCurDir == NULL) { + SHELL_FREE_NON_NULL (MapName); + return EFI_UNSUPPORTED; + } + *(SplitCurDir + 1) = CHAR_NULL; + MapListItem = ShellCommandFindMapItem (MapName); + if (MapListItem != NULL) { + gShellCurMapping = MapListItem; + } + SHELL_FREE_NON_NULL (MapName); + } + } } else { Count = (UINTN)-1; } -- 2.12.2.windows.2