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