]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Fix 'mv' command to not attempt moving a file from write-protected media
authorChris Phillips <chrisp@hp.com>
Tue, 24 Jun 2014 18:39:15 +0000 (18:39 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 24 Jun 2014 18:39:15 +0000 (18:39 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chris Phillips <chrisp@hp.com>
Reviewed-by: Jaben Carsey <Jaben.carsey@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15584 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.uni

index 65e83ccc0f4336130f150df627acb0fec860a577..f9b83e6fa4565db8e3fc54dc52942c2bb4315d54 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Main file for mv shell level 2 function.\r
 \r
-  Copyright (c) 2013, Hewlett-Packard Development Company, L.P.\r
-  Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  (C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.\r
+  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -29,6 +29,7 @@
   @param Cwd      [in]    The current working directory\r
   @param DestPath [in]    The target location to move to\r
   @param Attribute[in]    The Attribute of the file\r
+  @param FileStatus[in]   The Status of the file when opened\r
 \r
   @retval TRUE        The move is valid\r
   @retval FALSE       The move is not\r
 BOOLEAN\r
 EFIAPI\r
 IsValidMove(\r
-  IN CONST CHAR16   *FullName,\r
-  IN CONST CHAR16   *Cwd,\r
-  IN CONST CHAR16   *DestPath,\r
-  IN CONST UINT64   Attribute\r
+  IN CONST CHAR16     *FullName,\r
+  IN CONST CHAR16     *Cwd,\r
+  IN CONST CHAR16     *DestPath,\r
+  IN CONST UINT64     Attribute,\r
+  IN CONST EFI_STATUS FileStatus\r
   )\r
 {\r
   CHAR16  *Test;\r
@@ -87,11 +89,11 @@ IsValidMove(
     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_SUB), gShellLevel2HiiHandle);\r
     return (FALSE);\r
   }\r
-  if ((Attribute & EFI_FILE_READ_ONLY) != 0) {\r
+  if (((Attribute & EFI_FILE_READ_ONLY) != 0) || (FileStatus == EFI_WRITE_PROTECTED)) {\r
     //\r
     // invalid to move read only\r
     //\r
-    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_RO), gShellLevel2HiiHandle);\r
+    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_RO), gShellLevel2HiiHandle, FullName);\r
     return (FALSE);\r
   }\r
   Test  = StrStr(FullName, L":");\r
@@ -290,7 +292,6 @@ ValidateAndMoveFiles(
   ASSERT  (DestPath     != NULL);\r
   ASSERT  (HiiResultOk  != NULL);\r
   ASSERT  (HiiOutput    != NULL);\r
-//  ASSERT  (Cwd          != NULL);\r
 \r
   //\r
   // Go through the list of files and directories to move...\r
@@ -302,8 +303,13 @@ ValidateAndMoveFiles(
     if (ShellGetExecutionBreakFlag()) {\r
       break;\r
     }\r
+\r
+    //\r
+    // These should never be NULL\r
+    //\r
     ASSERT(Node->FileName != NULL);\r
     ASSERT(Node->FullName != NULL);\r
+    ASSERT(Node->Info     != NULL);\r
 \r
     //\r
     // skip the directory traversing stuff...\r
@@ -315,7 +321,7 @@ ValidateAndMoveFiles(
     //\r
     // Validate that the move is valid\r
     //\r
-    if (!IsValidMove(Node->FullName, Cwd, DestPath, Node->Info->Attribute)) {\r
+    if (!IsValidMove(Node->FullName, Cwd, DestPath, Node->Info->Attribute, Node->Status)) {\r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
       continue;\r
     }\r
index 749d184a7a40fe021c01ac46343f817a74756378..51ec7e12670005e92fa4722f367a9470df4e3ccb 100644 (file)
Binary files a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.uni and b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.uni differ