From: Ruiyu Ni <ruiyu.ni@intel.com>
To: edk2-devel@lists.01.org
Cc: Huajing Li <huajing.li@intel.com>
Subject: [PATCH 3/3] ShellPkg: Update CWD and current mapping when commands return
Date: Tue, 29 Aug 2017 16:11:07 +0800 [thread overview]
Message-ID: <20170829081107.442452-4-ruiyu.ni@intel.com> (raw)
In-Reply-To: <20170829081107.442452-1-ruiyu.ni@intel.com>
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
next prev parent reply other threads:[~2017-08-29 8:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2017-08-29 14:58 ` [PATCH 0/3] Update CWD and current mapping properly Carsey, Jaben
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170829081107.442452-4-ruiyu.ni@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox