]> git.proxmox.com Git - mirror_edk2.git/blame - 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
CommitLineData
2aa62f2b 1/** @file\r
2 Function declarations for UEFI "system calls".\r
3\r
61403bd7 4 The following macros are defined in this file:<BR>\r
5@verbatim\r
6 STDIN_FILENO 0 standard input file descriptor\r
7 STDOUT_FILENO 1 standard output file descriptor\r
8 STDERR_FILENO 2 standard error file descriptor\r
61403bd7 9 SEEK_SET 0 set file offset to offset\r
10 SEEK_CUR 1 set file offset to current plus offset\r
11 SEEK_END 2 set file offset to EOF plus offset\r
12 VALID_OPEN 1\r
13 VALID_CLOSED 0\r
14 VALID_DONT_CARE -1\r
15@endverbatim\r
16\r
17 The following types are defined in this file:<BR>\r
18@verbatim\r
19 struct stat; Structure declared in <sys/stat.h>\r
20@endverbatim\r
21\r
22 The following functions are declared in this file:<BR>\r
23@verbatim\r
24 ############### System Calls used in stdio.\r
25 int close (int fd);\r
26 ssize_t read (int fd, void *buf, size_t n);\r
27 ssize_t write (int fd, const void *buf, size_t n);\r
28 int unlink (const char *name);\r
29 int dup2 (int, int);\r
30 int rmdir (const char *);\r
31 int isatty (int);\r
32\r
33 ############### System Calls which are also declared in sys/fcntl.h.\r
34 int open (const char *name, int oflags, int mode);\r
35 int creat (const char *, mode_t);\r
36 int fcntl (int, int, ...);\r
37\r
38 ############### System Calls which are also declared in stat.h.\r
39 int mkdir (const char *, mode_t);\r
40 int fstat (int, struct stat *);\r
41 int lstat (const char *, struct stat *);\r
42 int stat (const char *, void *);\r
43 int chmod (const char *, mode_t);\r
44\r
45 ############### System Calls which are also declared in sys/types.h.\r
46 off_t lseek (int, off_t, int);\r
47 int truncate (const char *, off_t);\r
48 int ftruncate (int, off_t); // IEEE Std 1003.1b-93\r
49\r
50 ############### EFI-specific Functions.\r
51 int DeleteOnClose (int fd); Mark an open file to be deleted when closed.\r
52 int FindFreeFD (int MinFd);\r
53 BOOLEAN ValidateFD (int fd, int IsOpen);\r
61403bd7 54@endverbatim\r
2aa62f2b 55\r
a7a8363d 56 Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r
2aa62f2b 57 This program and the accompanying materials are licensed and made available under\r
58 the terms and conditions of the BSD License that accompanies this distribution.\r
59 The full text of the license may be found at\r
61403bd7 60 http://opensource.org/licenses/bsd-license.\r
2aa62f2b 61\r
62 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
63 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
2aa62f2b 64**/\r
65#ifndef _EFI_SYS_CALL_H\r
66#define _EFI_SYS_CALL_H\r
67\r
68#include <sys/EfiCdefs.h>\r
69#include <sys/types.h>\r
70\r
53e1e5c6 71struct stat; /* Structure declared in <sys/stat.h> */\r
2aa62f2b 72\r
61403bd7 73#define STDIN_FILENO 0 /**< standard input file descriptor */\r
74#define STDOUT_FILENO 1 /**< standard output file descriptor */\r
75#define STDERR_FILENO 2 /**< standard error file descriptor */\r
2aa62f2b 76\r
53e1e5c6 77/* whence values for lseek(2)\r
78 Always ensure that these are consistent with <stdio.h> and <unistd.h>!\r
79*/\r
80#ifndef SEEK_SET\r
61403bd7 81 #define SEEK_SET 0 /**< set file offset to offset */\r
53e1e5c6 82#endif\r
83#ifndef SEEK_CUR\r
61403bd7 84 #define SEEK_CUR 1 /**< set file offset to current plus offset */\r
53e1e5c6 85#endif\r
86#ifndef SEEK_END\r
61403bd7 87 #define SEEK_END 2 /**< set file offset to EOF plus offset */\r
53e1e5c6 88#endif\r
89\r
90// Parameters for the ValidateFD function.\r
91#define VALID_OPEN 1\r
92#define VALID_CLOSED 0\r
93#define VALID_DONT_CARE -1\r
2aa62f2b 94\r
95__BEGIN_DECLS\r
2aa62f2b 96/* EFI versions of BSD system calls used in stdio */\r
61403bd7 97\r
98 /** Close a file or device.\r
99\r
100 @param[in] fd File Descriptor for the file or device to close.\r
101\r
102 @retval 0 Successful completion.\r
103 @retval -1 An error occurred, identified by errno.\r
104 - EBADF fd is not a valid File Descriptor.\r
105 - EINTR The function was interrupted by a signal.\r
106 - EIO An I/O error occurred.\r
107 **/\r
108 int close (int fd);\r
109\r
110 /** Read from a file or device.\r
111\r
112 @param[in] fd File Descriptor for the file or device to read.\r
113 @param[in] buf Buffer to read data into.\r
114 @param[in] N Maximum number of bytes to read.\r
115\r
116 @return On successful completion, read returns a non-negative integer\r
117 indicating the number of bytes actually read. Otherwise, it\r
118 returns -1 and sets errno as follows:\r
119 - EAGAIN\r
120 - EWOULDBLOCK\r
121 - EBADF\r
122 - EBADMSG\r
123 - EINTR\r
124 - EINVAL\r
125 - EIO\r
126 - EISDIR\r
127 - EOVERFLOW\r
128 - ECONNRESET\r
129 - ENOTCONN\r
130 - ETIMEDOUT\r
131 - ENOBUFS\r
132 - ENOMEM\r
133 - ENXIO\r
134 **/\r
135 ssize_t read (int fd, void *buf, size_t n);\r
136\r
137 /** Write to a file or device.\r
138\r
139 @param[in] fd File Descriptor for the file or device to write.\r
140 @param[in] buf Buffer to write data from.\r
141 @param[in] N Maximum number of bytes to write.\r
142\r
143 @return On successful completion, write returns a non-negative integer\r
144 indicating the number of bytes actually written. Otherwise, it\r
145 returns -1 and sets errno as follows:\r
146 - EAGAIN\r
147 - EWOULDBLOCK\r
148 - EBADF\r
149 - EFBIG\r
150 - EINTR\r
151 - EINVAL\r
152 - EIO\r
153 - ENOSPC\r
154 - EPIPE\r
155 - ERANGE\r
156 - ECONNRESET\r
157 - ENOBUFS\r
158 - ENXIO\r
159 - ENETDOWN\r
160 - ENETUNREACH\r
161 **/\r
162 ssize_t write (int fd, const void *buf, size_t n);\r
163\r
164 /** Unlink (delete) a file.\r
165\r
166 @param[in] name The name of the file to be deleted.\r
167\r
168 @retval 0 Successful completion.\r
169 @retval -1 Unable to perform operation, errno contains further\r
170 information. The file name is unchanged.\r
171 **/\r
172 int unlink (const char *name);\r
173\r
174 /** Make file descriptor Fd2 a duplicate of file descriptor Fd1.\r
175\r
176 @param[in] Fd1 File descriptor to be duplicated\r
177 @param[in] Fd2 File descriptor to become a duplicate of Fd1.\r
178\r
179 @retval 0 Successful completion.\r
180 @retval -1 Unable to perform operation, errno contains further\r
181 information.\r
182 **/\r
183 int dup2 (int Fd1, int Fd2);\r
184\r
185 /** Remove a directory.\r
186\r
187 @param[in] Path Path to the directory to be deleted.\r
188\r
189 @retval 0 Successful completion.\r
190 @retval -1 Unable to perform operation, errno contains further\r
191 information. The named directory remains unchanged.\r
192 **/\r
193 int rmdir (const char *Path);\r
194\r
195 /** Determine if fd refers to an interactive terminal device.\r
196\r
197 @param[in] fd The file descriptor to be tested.\r
198\r
199 @retval 0 The file descriptor, fd, is not for a terminal. errno is set\r
200 indicating the cause for failure.\r
201 - EBADF fd is not a valid open file descriptor.\r
202 - ENOTTY fd does not refer to a terminal.\r
203 @retval 1 The file descriptor, fd, is for a terminal.\r
204 **/\r
205 int isatty (int fd);\r
2aa62f2b 206\r
207/* These system calls are also declared in sys/fcntl.h */\r
208#ifndef __FCNTL_SYSCALLS_DECLARED\r
209 #define __FCNTL_SYSCALLS_DECLARED\r
61403bd7 210\r
211 /** Open or create a file named by name.\r
212\r
213 The file name may be one of:\r
214 - An absolute path beginning with '/'.\r
215 - A relative path beginning with "." or ".." or a directory name\r
216 - A file name\r
217 - A mapped path which begins with a name followed by a colon, ':'.\r
218\r
219 Mapped paths are use to refer to specific mass storage volumes or devices.\r
220 In a Shell-hosted environment, the map command will list valid map names\r
221 for both file system and block devices. Mapped paths can also refer to\r
222 devices such as the UEFI console. Supported UEFI console mapped paths are:\r
223 - stdin: Standard Input (from the System Table)\r
224 - stdout: Standard Output (from the System Table)\r
225 - stderr: Standard Error Output (from the System Table)\r
226\r
0c1992fb 227 @param[in] name Name of file to open.\r
228 @param[in] oflags Flags as defined in fcntl.h.\r
229 @param[in] mode Access mode to use if creating the file.\r
61403bd7 230\r
0c1992fb 231 @return Returns -1 on failure, otherwise the file descriptor for the open file.\r
61403bd7 232 **/\r
53e1e5c6 233 int open (const char *name, int oflags, int mode);\r
61403bd7 234\r
0c1992fb 235 /** Create a new file or rewrite an existing one.\r
236\r
237 The creat() function behaves as if it is implemented as follows:\r
61403bd7 238\r
0c1992fb 239 int creat(const char *path, mode_t mode)\r
240 {\r
241 return open(path, O_WRONLY|O_CREAT|O_TRUNC, mode);\r
242 }\r
243\r
244 @param[in] Path The name of the file to create.\r
245 @param[in] Mode Access mode (permissions) for the new file.\r
246\r
247 @return Returns -1 on failure, otherwise the file descriptor for the open file.\r
61403bd7 248 **/\r
0c1992fb 249 int creat (const char *Path, mode_t Mode);\r
250\r
251 /** File control\r
61403bd7 252\r
0c1992fb 253 This function performs the operations described below and defined in <fcntl.h>.\r
61403bd7 254\r
0c1992fb 255 - F_DUPFD: Return the lowest numbered file descriptor available that is >= the third argument.\r
256 The new file descriptor refers to the same open file as Fd.\r
257\r
258 - F_SETFD: Set the file descriptor flags to the value specified by the third argument.\r
259 - F_GETFD: Get the file descriptor flags associated with Fd.\r
260 - F_SETFL: Set the file status flags based upon the value of the third argument.\r
261 - F_GETFL: Get the file status flags and access modes for file Fd.\r
262\r
263 @param[in] Fd File descriptor associated with the file to be controlled.\r
264 @param[in] Cmd Command to execute.\r
265 @param[in] ... Additional arguments, as needed by Cmd.\r
266\r
267 @return A -1 is returned to indicate failure, otherwise the value\r
268 returned is positive and depends upon Cmd as follows:\r
269 - F_DUPFD: A new file descriptor.\r
270 - F_SETFD: files previous file descriptor flags.\r
271 - F_GETFD: The files file descriptor flags.\r
272 - F_SETFL: The old status flags and access mode of the file.\r
273 - F_GETFL: The status flags and access mode of the file.\r
61403bd7 274 **/\r
0c1992fb 275 int fcntl (int Fd, int Cmd, ...);\r
2aa62f2b 276#endif // __FCNTL_SYSCALLS_DECLARED\r
277\r
278/* These system calls are also declared in stat.h */\r
279#ifndef __STAT_SYSCALLS_DECLARED\r
280 #define __STAT_SYSCALLS_DECLARED\r
61403bd7 281\r
53e1e5c6 282 int mkdir (const char *, mode_t);\r
283 int fstat (int, struct stat *);\r
284 int lstat (const char *, struct stat *);\r
41b152c5 285 int stat (const char *, struct stat *);\r
d7ce7006 286 int chmod (const char *, mode_t);\r
0c1992fb 287 mode_t umask (mode_t cmask);\r
288\r
2aa62f2b 289#endif // __STAT_SYSCALLS_DECLARED\r
290\r
291// These are also declared in sys/types.h\r
292#ifndef __OFF_T_SYSCALLS_DECLARED\r
293 #define __OFF_T_SYSCALLS_DECLARED\r
53e1e5c6 294 off_t lseek (int, off_t, int);\r
295 int truncate (const char *, off_t);\r
296 int ftruncate (int, off_t); // IEEE Std 1003.1b-93\r
2aa62f2b 297#endif /* __OFF_T_SYSCALLS_DECLARED */\r
298\r
53e1e5c6 299/* EFI-specific Functions. */\r
61403bd7 300\r
0c1992fb 301 /** Mark an open file to be deleted when it is closed.\r
302\r
303 @param[in] fd File descriptor for the open file.\r
61403bd7 304\r
0c1992fb 305 @retval 0 The flag was set successfully.\r
306 @retval -1 An invalid fd was specified.\r
61403bd7 307 **/\r
0c1992fb 308 int DeleteOnClose(int fd);\r
53e1e5c6 309\r
0c1992fb 310 /** Find and reserve a free File Descriptor.\r
53e1e5c6 311\r
312 Returns the first free File Descriptor greater than or equal to the,\r
313 already validated, fd specified by Minfd.\r
314\r
315 @return Returns -1 if there are no free FDs. Otherwise returns the\r
316 found fd.\r
0c1992fb 317 */\r
61403bd7 318 int FindFreeFD (int MinFd);\r
53e1e5c6 319\r
0c1992fb 320 /** Validate that fd refers to a valid file descriptor.\r
53e1e5c6 321 IsOpen is interpreted as follows:\r
322 - Positive fd must be OPEN\r
323 - Zero fd must be CLOSED\r
324 - Negative fd may be OPEN or CLOSED\r
325\r
326 @retval TRUE fd is VALID\r
327 @retval FALSE fd is INVALID\r
0c1992fb 328 */\r
61403bd7 329 BOOLEAN ValidateFD (int fd, int IsOpen);\r
53e1e5c6 330\r
d7ce7006 331\r
61403bd7 332/* These system calls don't YET have EFI implementations. */\r
61403bd7 333 int reboot (int, char *);\r
2aa62f2b 334__END_DECLS\r
335\r
a7a8363d 336/* The console output stream, stdout, supports cursor positioning via the\r
337 lseek() function call. The following entities facilitate packing the\r
338 X and Y coordinates into the offset parameter of the lseek call.\r
339*/\r
340typedef struct {\r
341 UINT32 Column;\r
342 UINT32 Row;\r
343} CURSOR_XY;\r
344\r
345typedef union {\r
346 UINT64 Offset;\r
347 CURSOR_XY XYpos;\r
348} XY_OFFSET;\r
349\r
2aa62f2b 350#endif /* _EFI_SYS_CALL_H */\r