* [PATCH 1/3] ShellPkg: Rename gShellCurDir to gShellCurMapping
2017-08-29 8:11 [PATCH 0/3] Update CWD and current mapping properly Ruiyu Ni
@ 2017-08-29 8:11 ` Ruiyu Ni
2017-08-29 8:11 ` [PATCH 2/3] ShellPkg: Fix bug that fails to change CWD after "map -r" Ruiyu Ni
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Ruiyu Ni @ 2017-08-29 8:11 UTC (permalink / raw)
To: edk2-devel; +Cc: Huajing Li
From: Huajing Li <huajing.li@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Huajing Li <huajing.li@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
---
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/Application/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 != NULL) {
- gShellCurDir = MapListItem;
+ gShellCurMapping = MapListItem;
}
} else {
- MapListItem = gShellCurDir;
+ MapListItem = gShellCurMapping;
}
if (MapListItem == NULL) {
@@ -3131,7 +3131,7 @@ EfiShellSetCurDir(
FreePool (DirectoryName);
return (EFI_INVALID_PARAMETER);
}
-// gShellCurDir = MapListItem;
+// gShellCurMapping = MapListItem;
if (DirectoryName != 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 == gShellCurDir) {
+ if (MapListItem == gShellCurMapping) {
Size = 0;
ASSERT((TempString == NULL && Size == 0) || (TempString != NULL));
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 application.
This library will not function if it is used for UEFI Shell 2.0 Applications.
- Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
(C) Copyright 2013-2014 Hewlett-Packard Development Company, L.P.<BR>
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;
/**
Returns the help MAN fileName for a given shell command.
diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/ShellPkg/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.
- Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
@@ -53,7 +53,7 @@ STATIC CONST CHAR8 Hex[] = {
// global variables required by library class.
EFI_UNICODE_COLLATION_PROTOCOL *gUnicodeCollation = NULL;
SHELL_MAP_LIST gShellMapList;
-SHELL_MAP_LIST *gShellCurDir = NULL;
+SHELL_MAP_LIST *gShellCurMapping = NULL;
CONST CHAR16* SupportLevel[] = {
L"Minimal",
@@ -229,7 +229,7 @@ ShellCommandLibDestructor (
}
gUnicodeCollation = NULL;
- gShellCurDir = NULL;
+ gShellCurMapping = NULL;
return (RETURN_SUCCESS);
}
--
2.12.2.windows.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] ShellPkg: Fix bug that fails to change CWD after "map -r".
2017-08-29 8:11 [PATCH 0/3] Update CWD and current mapping properly Ruiyu Ni
2017-08-29 8:11 ` [PATCH 1/3] ShellPkg: Rename gShellCurDir to gShellCurMapping Ruiyu Ni
@ 2017-08-29 8:11 ` Ruiyu Ni
2017-08-29 8:11 ` [PATCH 3/3] ShellPkg: Update CWD and current mapping when commands return Ruiyu Ni
2017-08-29 14:58 ` [PATCH 0/3] Update CWD and current mapping properly Carsey, Jaben
3 siblings, 0 replies; 5+ messages in thread
From: Ruiyu Ni @ 2017-08-29 8:11 UTC (permalink / raw)
To: edk2-devel; +Cc: Huajing Li
From: Huajing Li <huajing.li@intel.com>
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>
---
.../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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] ShellPkg: Update CWD and current mapping when commands return
2017-08-29 8:11 [PATCH 0/3] Update CWD and current mapping properly Ruiyu Ni
2017-08-29 8:11 ` [PATCH 1/3] ShellPkg: Rename gShellCurDir to gShellCurMapping Ruiyu Ni
2017-08-29 8:11 ` [PATCH 2/3] ShellPkg: Fix bug that fails to change CWD after "map -r" Ruiyu Ni
@ 2017-08-29 8:11 ` Ruiyu Ni
2017-08-29 14:58 ` [PATCH 0/3] Update CWD and current mapping properly Carsey, Jaben
3 siblings, 0 replies; 5+ messages in thread
From: Ruiyu Ni @ 2017-08-29 8:11 UTC (permalink / raw)
To: edk2-devel; +Cc: Huajing Li
From: Huajing Li <huajing.li@intel.com>
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 <huajing.li@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
---
ShellPkg/Application/Shell/Shell.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/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;
ASSERT(CmdLine != NULL);
if (StrLen(CmdLine) == 0) {
@@ -2705,7 +2706,22 @@ RunShellCommand(
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);
SetLastError(SHELL_NOT_FOUND);
}
-
+ //
+ // Check whether the current file system still exists. If not exist, we need update "cwd" and gShellCurMapping.
+ //
+ CurDir = EfiShellGetCurDir (NULL);
+ if (CurDir != 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" variable.
+ //
+ InternalEfiShellSetEnv (L"cwd", NULL, TRUE);
+ gShellCurMapping = NULL;
+ }
+ }
+
SHELL_FREE_NON_NULL(CleanOriginal);
SHELL_FREE_NON_NULL(FirstParameter);
--
2.12.2.windows.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] Update CWD and current mapping properly
2017-08-29 8:11 [PATCH 0/3] Update CWD and current mapping properly Ruiyu Ni
` (2 preceding siblings ...)
2017-08-29 8:11 ` [PATCH 3/3] ShellPkg: Update CWD and current mapping when commands return Ruiyu Ni
@ 2017-08-29 14:58 ` Carsey, Jaben
3 siblings, 0 replies; 5+ messages in thread
From: Carsey, Jaben @ 2017-08-29 14:58 UTC (permalink / raw)
To: Ni, Ruiyu, edk2-devel@lists.01.org
Series.
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ruiyu
> Ni
> Sent: Tuesday, August 29, 2017 1:11 AM
> To: edk2-devel@lists.01.org
> Subject: [edk2] [PATCH 0/3] Update CWD and current mapping properly
> Importance: High
>
> The patches fix several bugs that caused by not updating CWD and current
> mapping properly.
>
> Huajing Li (3):
> ShellPkg: Rename gShellCurDir to gShellCurMapping
> ShellPkg: Fix bug that fails to change CWD after "map -r".
> ShellPkg: Update CWD and current mapping when commands return
>
> ShellPkg/Application/Shell/Shell.c | 18 +++++++++-
> ShellPkg/Application/Shell/ShellProtocol.c | 8 ++---
> ShellPkg/Include/Library/ShellCommandLib.h | 4 +--
> .../UefiShellCommandLib/UefiShellCommandLib.c | 42
> +++++++++++++++++++---
> 4 files changed, 61 insertions(+), 11 deletions(-)
>
> --
> 2.12.2.windows.2
>
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
^ permalink raw reply [flat|nested] 5+ messages in thread