summaryrefslogtreecommitdiffstats
path: root/ShellPkg/Library/UefiShellCommandLib
diff options
context:
space:
mode:
authorHuajing Li <huajing.li@intel.com>2017-08-28 11:47:52 +0800
committerRuiyu Ni <ruiyu.ni@intel.com>2017-08-30 11:42:49 +0800
commit055fafe1ce85013f1c868690ad06454a405c6af2 (patch)
treef20544312c5f6ca98c5696f4d5e3f983a07bf060 /ShellPkg/Library/UefiShellCommandLib
parent9cf45187023abda4e145ee66a493774b299d2d52 (diff)
downloadedk2-055fafe1ce85013f1c868690ad06454a405c6af2.tar.gz
edk2-055fafe1ce85013f1c868690ad06454a405c6af2.tar.bz2
edk2-055fafe1ce85013f1c868690ad06454a405c6af2.zip
ShellPkg: Fix bug that fails to change CWD after "map -r".
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 <huajing.li@intel.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by Jaben Carsey <jaben.carsey@intel.com>
Diffstat (limited to 'ShellPkg/Library/UefiShellCommandLib')
-rw-r--r--ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c36
1 files changed, 35 insertions, 1 deletions
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;
}