]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StdLib/Include/sys/EfiSysCall.h
StdLib: Add multi-byte character support. The normal "narrow" character set is now...
[mirror_edk2.git] / StdLib / Include / sys / EfiSysCall.h
index 7b299108e6e7ff616068874694f29c91bc752535..6f4742875edac4335186e534bef7e5f2e0d42988 100644 (file)
@@ -1,17 +1,66 @@
 /** @file\r
   Function declarations for UEFI "system calls".\r
 \r
-  Concept derived from NetBSD's unistd.h file.\r
+    The following macros are defined in this file:<BR>\r
+@verbatim\r
+      STDIN_FILENO      0     standard input file descriptor\r
+      STDOUT_FILENO     1     standard output file descriptor\r
+      STDERR_FILENO     2     standard error file descriptor\r
+      SEEK_SET          0     set file offset to offset\r
+      SEEK_CUR          1     set file offset to current plus offset\r
+      SEEK_END          2     set file offset to EOF plus offset\r
+      VALID_OPEN        1\r
+      VALID_CLOSED      0\r
+      VALID_DONT_CARE  -1\r
+@endverbatim\r
 \r
-  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    The following types are defined in this file:<BR>\r
+@verbatim\r
+      struct stat;    Structure declared in <sys/stat.h>\r
+@endverbatim\r
+\r
+    The following functions are declared in this file:<BR>\r
+@verbatim\r
+      ###############  System Calls used in stdio.\r
+      int       close     (int fd);\r
+      ssize_t   read      (int fd, void *buf, size_t n);\r
+      ssize_t   write     (int fd, const void *buf, size_t n);\r
+      int       unlink    (const char *name);\r
+      int       dup2      (int, int);\r
+      int       rmdir     (const char *);\r
+      int       isatty    (int);\r
+\r
+      ###############  System Calls which are also declared in sys/fcntl.h.\r
+      int       open      (const char *name, int oflags, int mode);\r
+      int       creat     (const char *, mode_t);\r
+      int       fcntl     (int, int, ...);\r
+\r
+      ###############  System Calls which are also declared in stat.h.\r
+      int       mkdir     (const char *, mode_t);\r
+      int       fstat     (int, struct stat *);\r
+      int       lstat     (const char *, struct stat *);\r
+      int       stat      (const char *, void *);\r
+      int       chmod     (const char *, mode_t);\r
+\r
+      ###############  System Calls which are also declared in sys/types.h.\r
+      off_t     lseek     (int, off_t, int);\r
+      int       truncate  (const char *, off_t);\r
+      int       ftruncate (int, off_t);   //  IEEE Std 1003.1b-93\r
+\r
+      ###############  EFI-specific Functions.\r
+      int       DeleteOnClose (int fd);    Mark an open file to be deleted when closed.\r
+      int       FindFreeFD    (int MinFd);\r
+      BOOLEAN   ValidateFD    (int fd, int IsOpen);\r
+@endverbatim\r
+\r
+  Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials are licensed and made available under\r
   the terms and conditions of the BSD License that accompanies this distribution.\r
   The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php.\r
+  http://opensource.org/licenses/bsd-license.\r
 \r
   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
 **/\r
 #ifndef _EFI_SYS_CALL_H\r
 #define _EFI_SYS_CALL_H\r
 \r
 struct stat;  /* Structure declared in <sys/stat.h> */\r
 \r
-#define STDIN_FILENO  0 /* standard input file descriptor */\r
-#define STDOUT_FILENO 1 /* standard output file descriptor */\r
-#define STDERR_FILENO 2 /* standard error file descriptor */\r
-\r
-/* access function */\r
-#define F_OK       0  /* test for existence of file */\r
-#define X_OK    0x01  /* test for execute or search permission */\r
-#define W_OK    0x02  /* test for write permission */\r
-#define R_OK    0x04  /* test for read permission */\r
+#define STDIN_FILENO  0 /**< standard input file descriptor */\r
+#define STDOUT_FILENO 1 /**< standard output file descriptor */\r
+#define STDERR_FILENO 2 /**< standard error file descriptor */\r
 \r
 /* whence values for lseek(2)\r
    Always ensure that these are consistent with <stdio.h> and <unistd.h>!\r
 */\r
 #ifndef SEEK_SET\r
-  #define SEEK_SET  0 /* set file offset to offset */\r
+  #define SEEK_SET  0 /**< set file offset to offset */\r
 #endif\r
 #ifndef SEEK_CUR\r
-  #define SEEK_CUR  1 /* set file offset to current plus offset */\r
+  #define SEEK_CUR  1 /**< set file offset to current plus offset */\r
 #endif\r
 #ifndef SEEK_END\r
-  #define SEEK_END  2 /* set file offset to EOF plus offset */\r
+  #define SEEK_END  2 /**< set file offset to EOF plus offset */\r
 #endif\r
 \r
 // Parameters for the ValidateFD function.\r
@@ -50,32 +93,199 @@ struct stat;  /* Structure declared in <sys/stat.h> */
 #define VALID_DONT_CARE   -1\r
 \r
 __BEGIN_DECLS\r
-\r
 /* EFI versions of BSD system calls used in stdio */\r
-int       close     (int fd);\r
-ssize_t   read      (int fd, void *buf, size_t n);\r
-ssize_t   write     (int fd, const void *buf, size_t n);\r
-int       unlink    (const char *name);\r
-int       dup2      (int, int);\r
-int       rmdir     (const char *);\r
-int       isatty    (int);\r
+\r
+  /** Close a file or device.\r
+\r
+    @param[in]  fd    File Descriptor for the file or device to close.\r
+\r
+    @retval   0   Successful completion.\r
+    @retval  -1   An error occurred, identified by errno.\r
+                    - EBADF fd is not a valid File Descriptor.\r
+                    - EINTR The function was interrupted by a signal.\r
+                    - EIO An I/O error occurred.\r
+  **/\r
+  int       close     (int fd);\r
+\r
+  /** Read from a file or device.\r
+\r
+    @param[in]  fd    File Descriptor for the file or device to read.\r
+    @param[in]  buf   Buffer to read data into.\r
+    @param[in]  N     Maximum number of bytes to read.\r
+\r
+    @return   On successful completion, read returns a non-negative integer\r
+              indicating the number of bytes actually read.  Otherwise, it\r
+              returns -1 and sets errno as follows:\r
+                - EAGAIN\r
+                - EWOULDBLOCK\r
+                - EBADF\r
+                - EBADMSG\r
+                - EINTR\r
+                - EINVAL\r
+                - EIO\r
+                - EISDIR\r
+                - EOVERFLOW\r
+                - ECONNRESET\r
+                - ENOTCONN\r
+                - ETIMEDOUT\r
+                - ENOBUFS\r
+                - ENOMEM\r
+                - ENXIO\r
+  **/\r
+  ssize_t   read      (int fd, void *buf, size_t n);\r
+\r
+  /** Write to a file or device.\r
+\r
+    @param[in]  fd    File Descriptor for the file or device to write.\r
+    @param[in]  buf   Buffer to write data from.\r
+    @param[in]  N     Maximum number of bytes to write.\r
+\r
+    @return   On successful completion, write returns a non-negative integer\r
+              indicating the number of bytes actually written.  Otherwise, it\r
+              returns -1 and sets errno as follows:\r
+                - EAGAIN\r
+                - EWOULDBLOCK\r
+                - EBADF\r
+                - EFBIG\r
+                - EINTR\r
+                - EINVAL\r
+                - EIO\r
+                - ENOSPC\r
+                - EPIPE\r
+                - ERANGE\r
+                - ECONNRESET\r
+                - ENOBUFS\r
+                - ENXIO\r
+                - ENETDOWN\r
+                - ENETUNREACH\r
+  **/\r
+  ssize_t   write     (int fd, const void *buf, size_t n);\r
+\r
+  /** Unlink (delete) a file.\r
+\r
+    @param[in]  name    The name of the file to be deleted.\r
+\r
+    @retval   0   Successful completion.\r
+    @retval  -1   Unable to perform operation, errno contains further\r
+                  information.  The file name is unchanged.\r
+  **/\r
+  int       unlink    (const char *name);\r
+\r
+  /** Make file descriptor Fd2 a duplicate of file descriptor Fd1.\r
+\r
+    @param[in]  Fd1   File descriptor to be duplicated\r
+    @param[in]  Fd2   File descriptor to become a duplicate of Fd1.\r
+\r
+    @retval   0   Successful completion.\r
+    @retval  -1   Unable to perform operation, errno contains further\r
+                  information.\r
+  **/\r
+  int       dup2      (int Fd1, int Fd2);\r
+\r
+  /** Remove a directory.\r
+\r
+    @param[in]  Path    Path to the directory to be deleted.\r
+\r
+    @retval   0   Successful completion.\r
+    @retval  -1   Unable to perform operation, errno contains further\r
+                  information.  The named directory remains unchanged.\r
+  **/\r
+  int       rmdir     (const char *Path);\r
+\r
+  /** Determine if fd refers to an interactive terminal device.\r
+\r
+    @param[in]  fd    The file descriptor to be tested.\r
+\r
+    @retval   0   The file descriptor, fd, is not for a terminal.  errno is set\r
+                  indicating the cause for failure.\r
+                    - EBADF   fd is not a valid open file descriptor.\r
+                    - ENOTTY  fd does not refer to a terminal.\r
+    @retval   1   The file descriptor, fd, is for a terminal.\r
+  **/\r
+  int       isatty    (int fd);\r
 \r
 /* These system calls are also declared in sys/fcntl.h */\r
 #ifndef __FCNTL_SYSCALLS_DECLARED\r
   #define __FCNTL_SYSCALLS_DECLARED\r
+\r
+  /** Open or create a file named by name.\r
+\r
+      The file name may be one of:\r
+        - An absolute path beginning with '/'.\r
+        - A relative path beginning with "." or ".." or a directory name\r
+        - A file name\r
+        - A mapped path which begins with a name followed by a colon, ':'.\r
+\r
+      Mapped paths are use to refer to specific mass storage volumes or devices.\r
+      In a Shell-hosted environment, the map command will list valid map names\r
+      for both file system and block devices.  Mapped paths can also refer to\r
+      devices such as the UEFI console.  Supported UEFI console mapped paths are:\r
+        - stdin:        Standard Input        (from the System Table)\r
+        - stdout:       Standard Output       (from the System Table)\r
+        - stderr:       Standard Error Output (from the System Table)\r
+\r
+    @param[in]  name      Name of file to open.\r
+    @param[in]  oflags    Flags as defined in fcntl.h.\r
+    @param[in]  mode      Access mode to use if creating the file.\r
+\r
+    @return   Returns -1 on failure, otherwise the file descriptor for the open file.\r
+  **/\r
   int     open      (const char *name, int oflags, int mode);\r
-  int     creat     (const char *, mode_t);\r
-  int     fcntl     (int, int, ...);\r
+\r
+  /** Create a new file or rewrite an existing one.\r
+\r
+      The creat() function behaves as if it is implemented as follows:\r
+\r
+        int creat(const char *path, mode_t mode)\r
+        {\r
+            return open(path, O_WRONLY|O_CREAT|O_TRUNC, mode);\r
+        }\r
+\r
+    @param[in]    Path    The name of the file to create.\r
+    @param[in]    Mode    Access mode (permissions) for the new file.\r
+\r
+    @return   Returns -1 on failure, otherwise the file descriptor for the open file.\r
+  **/\r
+  int     creat     (const char *Path, mode_t Mode);\r
+\r
+  /** File control\r
+\r
+      This function performs the operations described below and defined in <fcntl.h>.\r
+\r
+        - F_DUPFD: Return the lowest numbered file descriptor available that is >= the third argument.\r
+                   The new file descriptor refers to the same open file as Fd.\r
+\r
+        - F_SETFD: Set the file descriptor flags to the value specified by the third argument.\r
+        - F_GETFD: Get the file descriptor flags associated with Fd.\r
+        - F_SETFL: Set the file status flags based upon the value of the third argument.\r
+        - F_GETFL: Get the file status flags and access modes for file Fd.\r
+\r
+    @param[in]  Fd      File descriptor associated with the file to be controlled.\r
+    @param[in]  Cmd     Command to execute.\r
+    @param[in]  ...     Additional arguments, as needed by Cmd.\r
+\r
+    @return   A -1 is returned to indicate failure, otherwise the value\r
+              returned is positive and depends upon Cmd as follows:\r
+                - F_DUPFD: A new file descriptor.\r
+                - F_SETFD: files previous file descriptor flags.\r
+                - F_GETFD: The files file descriptor flags.\r
+                - F_SETFL: The old status flags and access mode of the file.\r
+                - F_GETFL: The status flags and access mode of the file.\r
+  **/\r
+  int     fcntl     (int Fd, int Cmd, ...);\r
 #endif  // __FCNTL_SYSCALLS_DECLARED\r
 \r
 /* These system calls are also declared in stat.h */\r
 #ifndef __STAT_SYSCALLS_DECLARED\r
   #define __STAT_SYSCALLS_DECLARED\r
+\r
   int     mkdir     (const char *, mode_t);\r
   int     fstat     (int, struct stat *);\r
   int     lstat     (const char *, struct stat *);\r
-  int     stat      (const char *, void *);\r
-//  int      chmod     (const char *, mode_t);\r
+  int     stat      (const char *, struct stat *);\r
+  int     chmod     (const char *, mode_t);\r
+  mode_t  umask     (mode_t cmask);\r
+\r
 #endif  // __STAT_SYSCALLS_DECLARED\r
 \r
 // These are also declared in sys/types.h\r
@@ -87,19 +297,27 @@ int       isatty    (int);
 #endif /* __OFF_T_SYSCALLS_DECLARED */\r
 \r
 /* EFI-specific Functions. */\r
-int       DeleteOnClose(int fd);    /* Mark an open file to be deleted when closed. */\r
 \r
-/* Find and reserve a free File Descriptor.\r
+  /** Mark an open file to be deleted when it is closed.\r
+\r
+    @param[in]  fd    File descriptor for the open file.\r
+\r
+    @retval   0   The flag was set successfully.\r
+    @retval  -1   An invalid fd was specified.\r
+  **/\r
+  int       DeleteOnClose(int fd);\r
+\r
+  /** Find and reserve a free File Descriptor.\r
 \r
   Returns the first free File Descriptor greater than or equal to the,\r
   already validated, fd specified by Minfd.\r
 \r
   @return   Returns -1 if there are no free FDs.  Otherwise returns the\r
             found fd.\r
-*/\r
-int       FindFreeFD  (int MinFd);\r
+  */\r
+  int       FindFreeFD  (int MinFd);\r
 \r
-/*  Validate that fd refers to a valid file descriptor.\r
+  /** Validate that fd refers to a valid file descriptor.\r
     IsOpen is interpreted as follows:\r
       - Positive  fd must be OPEN\r
       - Zero      fd must be CLOSED\r
@@ -107,15 +325,26 @@ int       FindFreeFD  (int MinFd);
 \r
     @retval TRUE  fd is VALID\r
     @retval FALSE fd is INVALID\r
-*/\r
-BOOLEAN   ValidateFD (int fd, int IsOpen);\r
+  */\r
+  BOOLEAN   ValidateFD (int fd, int IsOpen);\r
 \r
-/* These system calls don't YET have EFI implementations. */\r
-int       access    (const char *path, int amode);\r
-int       chdir     (const char *);\r
-char     *getcwd    (char *, size_t);\r
-int       reboot    (int, char *);\r
 \r
+/* These system calls don't YET have EFI implementations. */\r
+  int       reboot    (int, char *);\r
 __END_DECLS\r
 \r
+/*  The console output stream, stdout, supports cursor positioning via the\r
+    lseek() function call.  The following entities facilitate packing the\r
+    X and Y coordinates into the offset parameter of the lseek call.\r
+*/\r
+typedef struct {\r
+  UINT32    Column;\r
+  UINT32    Row;\r
+} CURSOR_XY;\r
+\r
+typedef union {\r
+  UINT64      Offset;\r
+  CURSOR_XY   XYpos;\r
+} XY_OFFSET;\r
+\r
 #endif  /* _EFI_SYS_CALL_H */\r