]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Filesystem/SemihostFs/Arm/SemihostFs.c
ArmPkg/SemihostFs: Use Unicode to Ascii function for the conversion
[mirror_edk2.git] / ArmPkg / Filesystem / SemihostFs / Arm / SemihostFs.c
index a9d1c37c5cb9e3910a135ed46c6255361a439f6c..6443a7bf44a7695290525c8136f88dd64048ab9b 100644 (file)
@@ -2,7 +2,8 @@
   Support a Semi Host file system over a debuggers JTAG\r
 \r
   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
-  \r
+  Portions copyright (c) 2011, 2012, 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
@@ -73,7 +74,7 @@ typedef struct {
   EFI_FILE    File;\r
   CHAR8       *FileName;\r
   UINT32      Position;\r
-  UINT32      SemihostHandle;\r
+  UINT      SemihostHandle;\r
   BOOLEAN     IsRoot;\r
 } SEMIHOST_FCB;\r
 \r
@@ -152,10 +153,8 @@ FileOpen (
 {\r
   SEMIHOST_FCB  *FileFcb = NULL;\r
   EFI_STATUS    Status   = EFI_SUCCESS;\r
-  UINT32        SemihostHandle;\r
+  UINT        SemihostHandle;\r
   CHAR8         *AsciiFileName;\r
-  CHAR8         *AsciiPtr;\r
-  UINTN         Length;\r
   UINT32        SemihostMode;\r
   BOOLEAN       IsRoot;\r
 \r
@@ -163,22 +162,18 @@ FileOpen (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  // Semihost interface requires ASCII filesnames\r
-  Length = StrSize (FileName);\r
-\r
-  AsciiFileName = AllocatePool (Length);\r
+  // Semihost interface requires ASCII filenames\r
+  AsciiFileName = AllocatePool ((StrLen (FileName) + 1) * sizeof (CHAR8));\r
   if (AsciiFileName == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
+  UnicodeStrToAsciiStr (FileName, AsciiFileName);\r
 \r
-  AsciiPtr = AsciiFileName;\r
-\r
-  while (Length--) {\r
-    *AsciiPtr++ = *FileName++ & 0xFF;\r
-  }\r
-\r
-  if ((AsciiStrCmp (AsciiFileName, "\\") == 0) || (AsciiStrCmp (AsciiFileName, "/") == 0) || (AsciiStrCmp (AsciiFileName, "") == 0)) {\r
-    // Opening '/', '\', or the NULL pathname is trying to open the root directory\r
+  if ((AsciiStrCmp (AsciiFileName, "\\") == 0) ||\r
+      (AsciiStrCmp (AsciiFileName, "/")  == 0) ||\r
+      (AsciiStrCmp (AsciiFileName, "")   == 0) ||\r
+      (AsciiStrCmp (AsciiFileName, ".")  == 0)) {\r
+    // Opening '/', '\', '.', or the NULL pathname is trying to open the root directory\r
     IsRoot = TRUE;\r
 \r
     // Root directory node doesn't have a name.\r
@@ -263,18 +258,22 @@ FileDelete (
 \r
   Fcb = SEMIHOST_FCB_FROM_THIS(File);\r
 \r
-  // Get the filename from the Fcb\r
-  NameSize = AsciiStrLen (Fcb->FileName);\r
-  FileName = AllocatePool (NameSize + 1);\r
+  if (!Fcb->IsRoot) {\r
+    // Get the filename from the Fcb\r
+    NameSize = AsciiStrLen (Fcb->FileName);\r
+    FileName = AllocatePool (NameSize + 1);\r
 \r
-  AsciiStrCpy (FileName, Fcb->FileName);\r
+    AsciiStrCpy (FileName, Fcb->FileName);\r
 \r
-  // Close the file if it's open.  Disregard return status,\r
-  // since it might give an error if the file isn't open.\r
-  File->Close (File);\r
-    \r
-  // Call the semihost interface to delete the file.\r
-  Status = SemihostFileRemove (FileName);\r
+    // Close the file if it's open.  Disregard return status,\r
+    // since it might give an error if the file isn't open.\r
+    File->Close (File);\r
+\r
+    // Call the semihost interface to delete the file.\r
+    Status = SemihostFileRemove (FileName);\r
+  } else {\r
+    Status = EFI_UNSUPPORTED;\r
+  }\r
 \r
   return Status;\r
 }\r
@@ -353,19 +352,24 @@ FileSetPosition (
   )\r
 {\r
   SEMIHOST_FCB *Fcb    = NULL;\r
-  UINT32       Length;\r
+  UINT       Length;\r
   EFI_STATUS   Status;\r
 \r
   Fcb = SEMIHOST_FCB_FROM_THIS(File);\r
 \r
-  Status = SemihostFileLength (Fcb->SemihostHandle, &Length);\r
-  if (!EFI_ERROR(Status) && (Length < Position)) {\r
-    Position = Length;\r
-  }\r
+  if (!Fcb->IsRoot) {\r
+    Status = SemihostFileLength (Fcb->SemihostHandle, &Length);\r
+    if (!EFI_ERROR(Status) && (Length < Position)) {\r
+      Position = Length;\r
+    }\r
 \r
-  Status = SemihostFileSeek (Fcb->SemihostHandle, (UINT32)Position);\r
-  if (!EFI_ERROR(Status)) {\r
+    Status = SemihostFileSeek (Fcb->SemihostHandle, (UINT32)Position);\r
+    if (!EFI_ERROR(Status)) {\r
+      Fcb->Position = Position;\r
+    }\r
+  } else {\r
     Fcb->Position = Position;\r
+    Status = EFI_SUCCESS;\r
   }\r
 \r
   return Status;\r
@@ -383,7 +387,7 @@ GetFileInfo (
   UINTN           NameSize = 0;\r
   UINTN           ResultSize;\r
   UINTN           Index;\r
-  UINT32          Length;\r
+  UINT          Length;\r
   EFI_STATUS      Status;\r
 \r
   if (Fcb->IsRoot == TRUE) {\r