1 /* 2 * Copyright (c) 2008 The Native Client Authors. All rights reserved. 3 * Use of this source code is governed by a BSD-style license that can be 4 * found in the LICENSE file. 5 */ 6 7 /* 8 * NaCl Service Runtime API. 9 */ 10 11 #ifndef NATIVE_CLIENT_SRC_TRUSTED_SERVICE_RUNTIME_INCLUDE_BITS_STAT_H_ 12 #define NATIVE_CLIENT_SRC_TRUSTED_SERVICE_RUNTIME_INCLUDE_BITS_STAT_H_ 13 14 #if defined(NACL_IN_TOOLCHAIN_HEADERS) 15 #include <sys/types.h> 16 #include <stdint.h> 17 #else 18 #include "native_client/src/trusted/service_runtime/include/machine/_types.h" 19 #endif 20 21 /* 22 * nacl_abi_mode_t is uint32_t, so we have more bits to play with: 23 * 24 * 3 b/octal digit, 30 bits: 1234567890 25 */ 26 #define NACL_ABI_S_IFMT 0000370000 /* for now */ 27 /* Removed NACL_ABI_S_IFSHM_SYSV, which was 0000300000. */ 28 #define NACL_ABI_S_IFSEMA 0000270000 29 #define NACL_ABI_S_IFCOND 0000260000 30 #define NACL_ABI_S_IFMUTEX 0000250000 31 #define NACL_ABI_S_IFSHM 0000240000 32 #define NACL_ABI_S_IFBOUNDSOCK 0000230000 /* bound socket*/ 33 #define NACL_ABI_S_IFSOCKADDR 0000220000 /* socket address */ 34 #define NACL_ABI_S_IFDSOCK 0000210000 /* data-only, transferable socket*/ 35 36 #define NACL_ABI_S_IFSOCK 0000140000 /* data-and-descriptor socket*/ 37 #define NACL_ABI_S_IFLNK 0000120000 /* symbolic link */ 38 #define NACL_ABI_S_IFREG 0000100000 /* regular file */ 39 #define NACL_ABI_S_IFBLK 0000060000 /* block device */ 40 #define NACL_ABI_S_IFDIR 0000040000 /* directory */ 41 #define NACL_ABI_S_IFCHR 0000020000 /* character device */ 42 #define NACL_ABI_S_IFIFO 0000010000 /* fifo */ 43 44 #define NACL_ABI_S_UNSUP 0000370000 /* unsupported file type */ 45 /* 46 * NaCl does not support file system objects other than regular files 47 * and directories, and objects of other types will appear in the 48 * directory namespace but will be mapped to NACL_ABI_S_UNSUP when 49 * these objects are stat(2)ed. Opening these kinds of objects will 50 * fail. 51 * 52 * The ABI includes these bits so (library) code that use these 53 * preprocessor symbols will compile. The semantics of having a new 54 * "unsupported" file type should enable code to run in a reasonably 55 * sane way, but YMMV. 56 */ 57 58 #define NACL_ABI_S_ISUID 0004000 59 #define NACL_ABI_S_ISGID 0002000 60 #define NACL_ABI_S_ISVTX 0001000 61 62 #define NACL_ABI_S_IREAD 0400 63 #define NACL_ABI_S_IWRITE 0200 64 #define NACL_ABI_S_IEXEC 0100 65 66 #define NACL_ABI_S_IRWXU (NACL_ABI_S_IREAD|NACL_ABI_S_IWRITE|NACL_ABI_S_IEXEC) 67 #define NACL_ABI_S_IRUSR (NACL_ABI_S_IREAD) 68 #define NACL_ABI_S_IWUSR (NACL_ABI_S_IWRITE) 69 #define NACL_ABI_S_IXUSR (NACL_ABI_S_IEXEC) 70 71 #define NACL_ABI_S_IRWXG (NACL_ABI_S_IRWXU >> 3) 72 #define NACL_ABI_S_IRGRP (NACL_ABI_S_IREAD >> 3) 73 #define NACL_ABI_S_IWGRP (NACL_ABI_S_IWRITE >> 3) 74 #define NACL_ABI_S_IXGRP (NACL_ABI_S_IEXEC >> 3) 75 76 #define NACL_ABI_S_IRWXO (NACL_ABI_S_IRWXU >> 6) 77 #define NACL_ABI_S_IROTH (NACL_ABI_S_IREAD >> 6) 78 #define NACL_ABI_S_IWOTH (NACL_ABI_S_IWRITE >> 6) 79 #define NACL_ABI_S_IXOTH (NACL_ABI_S_IEXEC >> 6) 80 /* 81 * only user access bits are supported; the rest are cleared when set 82 * (effectively, umask of 077) and cleared when read. 83 */ 84 85 #define NACL_ABI_S_ISSOCK(m) (((m) & NACL_ABI_S_IFMT) == NACL_ABI_S_IFSOCK) 86 #define NACL_ABI_S_ISLNK(m) (((m) & NACL_ABI_S_IFMT) == NACL_ABI_S_IFLNK) 87 #define NACL_ABI_S_ISREG(m) (((m) & NACL_ABI_S_IFMT) == NACL_ABI_S_IFREG) 88 #define NACL_ABI_S_ISBLK(m) (((m) & NACL_ABI_S_IFMT) == NACL_ABI_S_IFBLK) 89 #define NACL_ABI_S_ISDIR(m) (((m) & NACL_ABI_S_IFMT) == NACL_ABI_S_IFDIR) 90 #define NACL_ABI_S_ISSOCKADDR(m) \ 91 (((m) & NACL_ABI_S_IFMT) == NACL_ABI_S_IFSOCKADDR) 92 #define NACL_ABI_S_ISCHR(m) (((m) & NACL_ABI_S_IFMT) == NACL_ABI_S_IFCHR) 93 #define NACL_ABI_S_ISFIFO(m) (((m) & NACL_ABI_S_IFMT) == NACL_ABI_S_IFIFO) 94 #define NACL_ABI_S_ISSHM(m) (((m) & NACL_ABI_S_IFMT) == NACL_ABI_S_IFSHM) 95 96 97 /* 98 * Linux <bit/stat.h> uses preprocessor to define st_atime to 99 * st_atim.tv_sec etc to widen the ABI to use a struct timespec rather 100 * than just have a time_t access/modification/inode-change times. 101 * this is unfortunate, since that symbol cannot be used as a struct 102 * member elsewhere (!). 103 * 104 * just like with type name conflicts, we avoid it by using nacl_abi_ 105 * as a prefix for struct members too. sigh. 106 */ 107 108 struct nacl_abi_stat { /* must be renamed when ABI is exported */ 109 nacl_abi_dev_t nacl_abi_st_dev; /* not implemented */ 110 nacl_abi_ino_t nacl_abi_st_ino; /* not implemented */ 111 nacl_abi_mode_t nacl_abi_st_mode; /* partially implemented. */ 112 nacl_abi_nlink_t nacl_abi_st_nlink; /* link count */ 113 nacl_abi_uid_t nacl_abi_st_uid; /* not implemented */ 114 nacl_abi_gid_t nacl_abi_st_gid; /* not implemented */ 115 nacl_abi_dev_t nacl_abi_st_rdev; /* not implemented */ 116 nacl_abi_off_t nacl_abi_st_size; /* object size */ 117 nacl_abi_blksize_t nacl_abi_st_blksize; /* not implemented */ 118 nacl_abi_blkcnt_t nacl_abi_st_blocks; /* not implemented */ 119 nacl_abi_time_t nacl_abi_st_atime; /* access time */ 120 int64_t nacl_abi_st_atimensec; /* possibly just pad */ 121 nacl_abi_time_t nacl_abi_st_mtime; /* modification time */ 122 int64_t nacl_abi_st_mtimensec; /* possibly just pad */ 123 nacl_abi_time_t nacl_abi_st_ctime; /* inode change time */ 124 int64_t nacl_abi_st_ctimensec; /* possibly just pad */ 125 }; 126 127 #endif 128