]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg:?cd \? command fails to go back to the root directory of a file system
authorTapan Shah <tapandshah@hpe.com>
Fri, 7 Oct 2016 20:59:34 +0000 (13:59 -0700)
committerJaben Carsey <jaben.carsey@intel.com>
Wed, 12 Oct 2016 17:24:35 +0000 (10:24 -0700)
Allows cd command to go back to the root directory when 'cd \' executed in system.

This change prevents last PathRemoveLastItem() call which truncates '\' from 'fs0:\'
in desired root path which is required to set CWD to the root directory.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Tapan Shah <tapandshah@hpe.com>
Reviewed-by: Jaben Carsey <Jaben.carsey@intel.com>
ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c

index 2e51b4cb4dd152e18e6daeda11e0fe83a65ff488..0967bc7c521026317253734bc6f96ac18244b8fe 100644 (file)
@@ -1,6 +1,7 @@
 /** @file\r
   Main file for attrib shell level 2 function.\r
 \r
+  (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
   (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
   Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
@@ -164,7 +165,16 @@ ShellCommandRunCd (
               StrCpyS (Cwd, StrSize (Directory) / sizeof (CHAR16) + 1, Directory);\r
               StrCatS (Cwd, StrSize (Directory) / sizeof (CHAR16) + 1, L"\\");\r
               Drive = GetFullyQualifiedPath (Cwd);\r
-              while (PathRemoveLastItem (Drive));\r
+              while (PathRemoveLastItem (Drive)) {\r
+                //\r
+                // Check if Drive contains 'fsx:\' only or still points to a sub-directory.\r
+                // Don't remove trailing '\' from Drive if it points to the root directory.\r
+                //\r
+                Path = StrStr (Drive, L":\\");\r
+                if ((Path != NULL) && (*(Path + 2) == CHAR_NULL)) {\r
+                  break;\r
+                }\r
+              }\r
               FreePool (Cwd);\r
             }\r
           }\r