]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StdLib/LibC/Uefi/SysCalls.c
Add Socket Libraries.
[mirror_edk2.git] / StdLib / LibC / Uefi / SysCalls.c
index b3ca5b89b4993ad958e525f76b37da1099d13b45..d2fb0c6af68fd84957231e835c2fe0103a6f28d7 100644 (file)
@@ -524,7 +524,7 @@ mkdir (const char *path, __mode_t perms)
   int                 Instance  = 0;\r
   int                 retval = 0;\r
 \r
-  Status = ParsePath(path, &NewPath, &Node, &Instance);\r
+  Status = ParsePath(path, &NewPath, &Node, &Instance, NULL);\r
   if(Status == RETURN_SUCCESS) {\r
     GenI = Node->InstanceList;\r
     if(GenI == NULL) {\r
@@ -532,7 +532,7 @@ mkdir (const char *path, __mode_t perms)
       retval  = -1;\r
       }\r
     else {\r
-      GenI += (Instance * Node->InstanceSize);\r
+      //GenI += (Instance * Node->InstanceSize);\r
       retval = ((GenericInstance *)GenI)->Abstraction.fo_mkdir( path, perms);\r
       }\r
     free(NewPath);\r
@@ -567,11 +567,15 @@ mkdir (const char *path, __mode_t perms)
     O_EXCL        -- if O_CREAT is also set, open will fail if the file already exists.\r
 **/\r
 int\r
-open   (const char *path, int oflags, int mode)\r
+open(\r
+  const char *path,\r
+  int oflags,\r
+  int mode\r
+  )\r
 {\r
   wchar_t              *NewPath;\r
+  wchar_t              *MPath;\r
   DeviceNode           *Node;\r
-  char                 *GenI = NULL;\r
   struct __filedes     *filp;\r
   int                   Instance  = 0;\r
   RETURN_STATUS         Status;\r
@@ -579,10 +583,10 @@ open   (const char *path, int oflags, int mode)
   int                   fd = -1;\r
   int                   doresult;\r
 \r
-  Status = ParsePath(path, &NewPath, &Node, &Instance);\r
+  Status = ParsePath(path, &NewPath, &Node, &Instance, &MPath);\r
   if(Status == RETURN_SUCCESS) {\r
-    if((Node != NULL)                       &&\r
-       ((GenI = Node->InstanceList) == NULL)) {\r
+    if((Node == NULL)               ||\r
+       (Node->InstanceList == NULL)) {\r
       errno   = EPERM;\r
   }\r
     else {\r
@@ -595,15 +599,14 @@ open   (const char *path, int oflags, int mode)
   if( fd < 0 ) {\r
     // All available FDs are in use\r
     errno = EMFILE;\r
-    return -1;\r
   }\r
+      else {\r
       filp = &gMD->fdarray[fd];\r
       // Save the flags and mode in the File Descriptor\r
       filp->Oflags = oflags;\r
       filp->Omode = mode;\r
 \r
-      GenI += (Instance * Node->InstanceSize);\r
-      doresult = Node->OpenFunc(filp, GenI, NewPath, NULL);\r
+        doresult = Node->OpenFunc(Node, filp, Instance, NewPath, MPath);\r
       if(doresult < 0) {\r
         filp->f_iflags = 0;   // Release this FD\r
         fd = -1;              // Indicate an error\r
@@ -618,8 +621,14 @@ open   (const char *path, int oflags, int mode)
         FILE_SET_MATURE(filp);\r
       }\r
           }\r
+    }\r
+    if(NewPath != NULL) {\r
     free(NewPath);\r
         }\r
+  }\r
+  if(MPath != NULL) {\r
+    free(MPath);    // We don't need this any more.\r
+  }\r
   // return the fd of our now open file\r
   return fd;\r
 }\r
@@ -748,6 +757,7 @@ poll (
     }\r
     } while (( 0 == SelectedFDs )\r
         && ( EFI_SUCCESS == Status ));\r
+\r
     //\r
     //  Stop the timer\r
     //\r
@@ -776,7 +786,6 @@ poll (
 }\r
 \r
 \r
-\r
 /** The rename() function changes the name of a file.\r
     The old argument points to the pathname of the file to be renamed. The new\r
     argument points to the new pathname of the file.\r
@@ -807,7 +816,6 @@ poll (
               shall be changed or created.\r
 **/\r
 int\r
-EFIAPI\r
 rename(\r
   const char *from,\r
   const char *to\r
@@ -820,7 +828,7 @@ rename(
   RETURN_STATUS       Status;\r
   int                 retval      = -1;\r
 \r
-  Status = ParsePath(from, &FromPath, &FromNode, &Instance);\r
+  Status = ParsePath(from, &FromPath, &FromNode, &Instance, NULL);\r
   if(Status == RETURN_SUCCESS) {\r
     GenI = FromNode->InstanceList;\r
     if(GenI == NULL) {\r
@@ -828,7 +836,7 @@ rename(
       retval  = -1;\r
       }\r
       else {\r
-      GenI += (Instance * FromNode->InstanceSize);\r
+      //GenI += (Instance * FromNode->InstanceSize);\r
       retval = ((GenericInstance *)GenI)->Abstraction.fo_rename( from, to);\r
               }\r
     free(FromPath);\r
@@ -839,7 +847,6 @@ rename(
 /**\r
 **/\r
 int\r
-EFIAPI\r
 rmdir(\r
   const char *path\r
   )\r
@@ -1006,13 +1013,13 @@ ioctl(
     from a file associated with a terminal may return one typed line of data.\r
 \r
     If fildes does not refer to a directory, the function reads the requested\r
-    number of bytes from the file at the file\92s current position and returns\r
+    number of bytes from the file at the file's current position and returns\r
     them in buf. If the read goes beyond the end of the file, the read\r
-    length is truncated to the end of the file. The file\92s current position is\r
+    length is truncated to the end of the file. The file's current position is\r
     increased by the number of bytes returned.\r
 \r
     If fildes refers to a directory, the function reads the directory entry at\r
-    the file\92s current position and returns the entry in buf. If buf\r
+    the file's current position and returns the entry in buf. If buf\r
     is not large enough to hold the current directory entry, then\r
     errno is set to EBUFSIZE, EFIerrno is set to EFI_BUFFER_TOO_SMALL, and the\r
     current file position is not updated. The size of the buffer needed to read\r
@@ -1129,3 +1136,56 @@ char
   \r
   return (UnicodeStrToAsciiStr(Cwd, buf));\r
 }\r
+\r
+/** Change the current working directory.\r
+\r
+  The chdir() function shall cause the directory named by the pathname\r
+  pointed to by the path argument to become the current working directory;\r
+  that is, the starting point for path searches for pathnames not beginning\r
+  with '/'.\r
+\r
+  @param[in] path   The new path to set.\r
+\r
+  @todo Add non-shell CWD changing.\r
+**/\r
+int\r
+chdir (const char *path)\r
+{\r
+  CONST CHAR16 *Cwd;\r
+  EFI_STATUS   Status;\r
+  CHAR16       *UnicodePath;\r
+\r
+  Cwd = ShellGetCurrentDir(NULL);\r
+  if (Cwd != NULL) {\r
+    /* We have shell support */\r
+    UnicodePath = AllocatePool(((AsciiStrLen (path) + 1) * sizeof (CHAR16)));\r
+    if (UnicodePath == NULL) {\r
+      errno = ENOMEM;\r
+      return -1;\r
+    }\r
+    AsciiStrToUnicodeStr(path, UnicodePath);\r
+    Status = gEfiShellProtocol->SetCurDir(NULL, UnicodePath);\r
+    FreePool(UnicodePath);\r
+    if (EFI_ERROR(Status)) {\r
+      errno = EACCES;\r
+      return -1;\r
+    } else {\r
+      return 0;\r
+    }\r
+  }\r
+\r
+  /* Add here for non-shell */\r
+  errno = EACCES;\r
+  return -1;\r
+}\r
+\r
+pid_t tcgetpgrp (int x)\r
+{\r
+  return ((pid_t)(UINTN)(gImageHandle));\r
+}\r
+\r
+pid_t getpgrp(void)\r
+{\r
+  return ((pid_t)(UINTN)(gImageHandle));\r
+}\r
+\r