sgx_file.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _SGX_FILE_H
  6. #define _SGX_FILE_H
  7. #include "sgx_time.h"
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #define F_DUPFD 0
  12. #define F_GETFD 1
  13. #define F_SETFD 2
  14. #define F_GETFL 3
  15. #define F_SETFL 4
  16. #define FD_CLOEXEC 1
  17. #define O_PATH 010000000
  18. #define O_SEARCH O_PATH
  19. #define O_EXEC O_PATH
  20. #define O_ACCMODE (03|O_SEARCH)
  21. #define O_RDONLY 00
  22. #define O_WRONLY 01
  23. #define O_RDWR 02
  24. #define O_CREAT 0100
  25. #define O_EXCL 0200
  26. #define O_NOCTTY 0400
  27. #define O_TRUNC 01000
  28. #define O_APPEND 02000
  29. #define O_NONBLOCK 04000
  30. #define O_DSYNC 010000
  31. #define O_SYNC 04010000
  32. #define O_RSYNC 04010000
  33. #define O_DIRECTORY 0200000
  34. #define O_NOFOLLOW 0400000
  35. #define O_CLOEXEC 02000000
  36. #define O_ASYNC 020000
  37. #define O_DIRECT 040000
  38. #define O_LARGEFILE 0
  39. #define O_NOATIME 01000000
  40. #define O_PATH 010000000
  41. #define O_TMPFILE 020200000
  42. #define O_NDELAY O_NONBLOCK
  43. #define S_IFMT 0170000
  44. #define S_IFDIR 0040000
  45. #define S_IFCHR 0020000
  46. #define S_IFBLK 0060000
  47. #define S_IFREG 0100000
  48. #define S_IFIFO 0010000
  49. #define S_IFLNK 0120000
  50. #define S_IFSOCK 0140000
  51. #define SEEK_SET 0
  52. #define SEEK_CUR 1
  53. #define SEEK_END 2
  54. #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
  55. #define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
  56. #define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
  57. #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
  58. #define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
  59. #define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
  60. #define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
  61. #define DT_UNKNOWN 0
  62. #define DT_FIFO 1
  63. #define DT_CHR 2
  64. #define DT_DIR 4
  65. #define DT_BLK 6
  66. #define DT_REG 8
  67. #define DT_LNK 10
  68. #define DT_SOCK 12
  69. #define DT_WHT 14
  70. #define AT_SYMLINK_NOFOLLOW 0x100
  71. #define AT_REMOVEDIR 0x200
  72. #define AT_SYMLINK_FOLLOW 0x400
  73. #define POLLIN 0x001
  74. #define POLLPRI 0x002
  75. #define POLLOUT 0x004
  76. #define POLLERR 0x008
  77. #define POLLHUP 0x010
  78. #define POLLNVAL 0x020
  79. #define POLLRDNORM 0x040
  80. #define POLLRDBAND 0x080
  81. #define POLLWRNORM 0x100
  82. #define POLLWRBAND 0x200
  83. #define FIONREAD 0x541B
  84. #define PATH_MAX 4096
  85. /* Special value used to indicate openat should use the current
  86. working directory. */
  87. #define AT_FDCWD -100
  88. typedef long __syscall_slong_t;
  89. typedef unsigned long dev_t;
  90. typedef unsigned long ino_t;
  91. typedef unsigned mode_t;
  92. typedef unsigned long nlink_t;
  93. typedef unsigned socklen_t;
  94. typedef long blksize_t;
  95. typedef long blkcnt_t;
  96. typedef int pid_t;
  97. typedef unsigned gid_t;
  98. typedef unsigned uid_t;
  99. typedef unsigned long nfds_t;
  100. typedef uintptr_t DIR;
  101. struct dirent {
  102. ino_t d_ino;
  103. off_t d_off;
  104. unsigned short d_reclen;
  105. unsigned char d_type;
  106. char d_name[256];
  107. };
  108. struct stat {
  109. dev_t st_dev;
  110. ino_t st_ino;
  111. nlink_t st_nlink;
  112. mode_t st_mode;
  113. uid_t st_uid;
  114. gid_t st_gid;
  115. unsigned int __pad0;
  116. dev_t st_rdev;
  117. off_t st_size;
  118. blksize_t st_blksize;
  119. blkcnt_t st_blocks;
  120. struct timespec st_atim;
  121. struct timespec st_mtim;
  122. struct timespec st_ctim;
  123. long __unused[3];
  124. };
  125. struct iovec {
  126. void *iov_base;
  127. size_t iov_len;
  128. };
  129. struct pollfd {
  130. int fd;
  131. short events;
  132. short revents;
  133. };
  134. int open(const char *pathname, int flags, ...);
  135. int openat(int dirfd, const char *pathname, int flags, ...);
  136. int close(int fd);
  137. DIR *fdopendir(int fd);
  138. int closedir(DIR *dirp);
  139. void rewinddir(DIR *dirp);
  140. void seekdir(DIR *dirp, long loc);
  141. struct dirent *readdir(DIR *dirp);
  142. long telldir(DIR *dirp);
  143. ssize_t read(int fd, void *buf, size_t count);
  144. ssize_t readv(int fd, const struct iovec *iov, int iovcnt);
  145. ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
  146. ssize_t preadv(int fd, const struct iovec *iov, int iovcnt,
  147. off_t offset);
  148. ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt,
  149. off_t offset);
  150. off_t lseek(int fd, off_t offset, int whence);
  151. int ftruncate(int fd, off_t length);
  152. int fstat(int fd, struct stat *statbuf);
  153. int fstatat(int dirfd, const char *pathname, struct stat *statbuf,
  154. int flags);
  155. int fsync(int fd);
  156. int fdatasync(int fd);
  157. int mkdirat(int dirfd, const char *pathname, mode_t mode);
  158. int link(const char *oldpath, const char *newpath);
  159. int linkat(int olddirfd, const char *oldpath,
  160. int newdirfd, const char *newpath, int flags);
  161. int unlinkat(int dirfd, const char *pathname, int flags);
  162. ssize_t readlinkat(int dirfd, const char *pathname,
  163. char *buf, size_t bufsiz);
  164. int symlinkat(const char *target, int newdirfd, const char *linkpath);
  165. int renameat(int olddirfd, const char *oldpath,
  166. int newdirfd, const char *newpath);
  167. int ioctl(int fd, unsigned long request, ...);
  168. int fcntl(int fd, int cmd, ... /* arg */ );
  169. int isatty(int fd);
  170. char *realpath(const char *path, char *resolved_path);
  171. int posix_fallocate(int fd, off_t offset, off_t len);
  172. int poll(struct pollfd *fds, nfds_t nfds, int timeout);
  173. int getopt(int argc, char * const argv[],
  174. const char *optstring);
  175. int sched_yield(void);
  176. ssize_t getrandom(void *buf, size_t buflen, unsigned int flags);
  177. int get_errno(void);
  178. #ifdef __cplusplus
  179. }
  180. #endif
  181. #endif /* end of _SGX_FILE_H */