]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Library/SemihostLib/SemihostLib.c
ArmPkg/SemihostFs: Various fixes for the file system
[mirror_edk2.git] / ArmPkg / Library / SemihostLib / SemihostLib.c
index 87c0379d6b3a34eddd9cfea8a48bd86451d97bdf..53405edd7a330ad0d08409ff8b434bb6c121e605 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
 \r
   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
 /** @file\r
 \r
   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
-  \r
+  Copyright (c) 2013 - 2014, ARM Ltd. All rights reserved.<BR>\r
+\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
   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
@@ -73,10 +74,12 @@ SemihostFileSeek (
 \r
   Result = Semihost_SYS_SEEK(&SeekBlock);\r
 \r
 \r
   Result = Semihost_SYS_SEEK(&SeekBlock);\r
 \r
-  if (Result == 0) {\r
-    return RETURN_SUCCESS;\r
-  } else {\r
+  // Semihosting does not behave as documented. It returns the offset on\r
+  // success.\r
+  if (Result < 0) {\r
     return RETURN_ABORTED;\r
     return RETURN_ABORTED;\r
+  } else {\r
+    return RETURN_SUCCESS;\r
   }\r
 }\r
 \r
   }\r
 }\r
 \r
@@ -100,7 +103,7 @@ SemihostFileRead (
 \r
   Result = Semihost_SYS_READ(&ReadBlock);\r
 \r
 \r
   Result = Semihost_SYS_READ(&ReadBlock);\r
 \r
-  if (Result == *Length) {\r
+  if ((*Length != 0) && (Result == *Length)) {\r
     return RETURN_ABORTED;\r
   } else {\r
     *Length -= Result;\r
     return RETURN_ABORTED;\r
   } else {\r
     *Length -= Result;\r
@@ -126,8 +129,11 @@ SemihostFileWrite (
   WriteBlock.Length = *Length;\r
 \r
   *Length = Semihost_SYS_WRITE(&WriteBlock);\r
   WriteBlock.Length = *Length;\r
 \r
   *Length = Semihost_SYS_WRITE(&WriteBlock);\r
-  \r
-  return RETURN_SUCCESS;\r
+\r
+  if (*Length != 0)\r
+    return RETURN_ABORTED;\r
+  else\r
+    return RETURN_SUCCESS;\r
 }\r
 \r
 RETURN_STATUS\r
 }\r
 \r
 RETURN_STATUS\r
@@ -174,6 +180,11 @@ SemihostFileRemove (
   SEMIHOST_FILE_REMOVE_BLOCK  RemoveBlock;\r
   UINT32                      Result;\r
 \r
   SEMIHOST_FILE_REMOVE_BLOCK  RemoveBlock;\r
   UINT32                      Result;\r
 \r
+  // Remove any leading separator (e.g.: '\'). EFI Shell adds one.\r
+  if (*FileName == '\\') {\r
+    FileName++;\r
+  }\r
+\r
   RemoveBlock.FileName    = FileName;\r
   RemoveBlock.NameLength  = AsciiStrLen(FileName);\r
 \r
   RemoveBlock.FileName    = FileName;\r
   RemoveBlock.NameLength  = AsciiStrLen(FileName);\r
 \r