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 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 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,444,1498546800"; d="scan'208";a="1189250917" 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 From: Ruiyu Ni To: edk2-devel@lists.01.org Cc: Huajing Li 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: [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: , X-List-Received-Date: Tue, 29 Aug 2017 08:08:34 -0000 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 --- 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