public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Ruiyu Ni <ruiyu.ni@intel.com>
To: edk2-devel@lists.01.org
Cc: Huajing Li <huajing.li@intel.com>
Subject: [PATCH 2/3] ShellPkg: Fix bug that fails to change CWD after "map -r".
Date: Tue, 29 Aug 2017 16:11:06 +0800	[thread overview]
Message-ID: <20170829081107.442452-3-ruiyu.ni@intel.com> (raw)
In-Reply-To: <20170829081107.442452-1-ruiyu.ni@intel.com>

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



  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 ` Ruiyu Ni [this message]
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

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-3-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