1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in 12 * the documentation and/or other materials provided with the 13 * distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #ifndef _SYS_STAT_H_ 30 #define _SYS_STAT_H_ 31 32 #include <bits/timespec.h> 33 #include <linux/stat.h> 34 #include <sys/cdefs.h> 35 #include <sys/types.h> 36 37 __BEGIN_DECLS 38 39 #if defined(__aarch64__) || (defined(__mips__) && defined(__LP64__)) 40 #define __STAT64_BODY \ 41 dev_t st_dev; \ 42 ino_t st_ino; \ 43 mode_t st_mode; \ 44 nlink_t st_nlink; \ 45 uid_t st_uid; \ 46 gid_t st_gid; \ 47 dev_t st_rdev; \ 48 unsigned long __pad1; \ 49 off_t st_size; \ 50 int st_blksize; \ 51 int __pad2; \ 52 long st_blocks; \ 53 struct timespec st_atim; \ 54 struct timespec st_mtim; \ 55 struct timespec st_ctim; \ 56 unsigned int __unused4; \ 57 unsigned int __unused5; \ 58 59 #elif defined(__mips__) && !defined(__LP64__) 60 #define __STAT64_BODY \ 61 unsigned int st_dev; \ 62 unsigned int __pad0[3]; \ 63 unsigned long long st_ino; \ 64 mode_t st_mode; \ 65 nlink_t st_nlink; \ 66 uid_t st_uid; \ 67 gid_t st_gid; \ 68 unsigned int st_rdev; \ 69 unsigned int __pad1[3]; \ 70 long long st_size; \ 71 struct timespec st_atim; \ 72 struct timespec st_mtim; \ 73 struct timespec st_ctim; \ 74 unsigned int st_blksize; \ 75 unsigned int __pad2; \ 76 unsigned long long st_blocks; \ 77 78 #elif defined(__x86_64__) 79 #define __STAT64_BODY \ 80 dev_t st_dev; \ 81 ino_t st_ino; \ 82 unsigned long st_nlink; \ 83 mode_t st_mode; \ 84 uid_t st_uid; \ 85 gid_t st_gid; \ 86 unsigned int __pad0; \ 87 dev_t st_rdev; \ 88 off_t st_size; \ 89 long st_blksize; \ 90 long st_blocks; \ 91 struct timespec st_atim; \ 92 struct timespec st_mtim; \ 93 struct timespec st_ctim; \ 94 long __pad3[3]; \ 95 96 #else /* __arm__ || __i386__ */ 97 #define __STAT64_BODY \ 98 unsigned long long st_dev; \ 99 unsigned char __pad0[4]; \ 100 unsigned long __st_ino; \ 101 unsigned int st_mode; \ 102 nlink_t st_nlink; \ 103 uid_t st_uid; \ 104 gid_t st_gid; \ 105 unsigned long long st_rdev; \ 106 unsigned char __pad3[4]; \ 107 long long st_size; \ 108 unsigned long st_blksize; \ 109 unsigned long long st_blocks; \ 110 struct timespec st_atim; \ 111 struct timespec st_mtim; \ 112 struct timespec st_ctim; \ 113 unsigned long long st_ino; \ 114 115 #endif 116 117 struct stat { __STAT64_BODY }; 118 struct stat64 { __STAT64_BODY }; 119 120 #undef __STAT64_BODY 121 122 /* Compatibility with older versions of POSIX. */ 123 #define st_atime st_atim.tv_sec 124 #define st_mtime st_mtim.tv_sec 125 #define st_ctime st_ctim.tv_sec 126 /* Compatibility with glibc. */ 127 #define st_atimensec st_atim.tv_nsec 128 #define st_mtimensec st_mtim.tv_nsec 129 #define st_ctimensec st_ctim.tv_nsec 130 /* Compatibility with Linux headers and old NDKs. */ 131 #define st_atime_nsec st_atim.tv_nsec 132 #define st_mtime_nsec st_mtim.tv_nsec 133 #define st_ctime_nsec st_ctim.tv_nsec 134 135 #if defined(__USE_BSD) 136 /* Permission macros provided by glibc for compatibility with BSDs. */ 137 #define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */ 138 #define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */ 139 #define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */ 140 #endif 141 142 #if defined(__USE_BSD) || defined(__USE_GNU) 143 #define S_IREAD S_IRUSR 144 #define S_IWRITE S_IWUSR 145 #define S_IEXEC S_IXUSR 146 #endif 147 148 /* POSIX mandates these, but Linux doesn't implement them as distinct file types. */ 149 #define S_TYPEISMQ(__sb) 0 150 #define S_TYPEISSEM(__sb) 0 151 #define S_TYPEISSHM(__sb) 0 152 #define S_TYPEISTMO(__sb) 0 153 154 int chmod(const char*, mode_t); 155 int fchmod(int, mode_t); 156 int mkdir(const char*, mode_t); 157 158 int fstat(int, struct stat*); 159 int fstat64(int, struct stat64*) __INTRODUCED_IN(21); 160 int fstatat(int, const char*, struct stat*, int); 161 int fstatat64(int, const char*, struct stat64*, int) __INTRODUCED_IN(21); 162 int lstat(const char*, struct stat*); 163 int lstat64(const char*, struct stat64*) __INTRODUCED_IN(21); 164 int stat(const char*, struct stat*); 165 int stat64(const char*, struct stat64*) __INTRODUCED_IN(21); 166 167 int mknod(const char*, mode_t, dev_t); 168 mode_t umask(mode_t) __overloadable __RENAME_CLANG(umask); 169 170 mode_t __umask_chk(mode_t) __INTRODUCED_IN(18); 171 172 #if defined(__BIONIC_FORTIFY) 173 #define __umask_invalid_mode_str "umask called with invalid mode" 174 175 #if defined(__clang__) 176 177 #if __ANDROID_API__ >= __ANDROID_API_J_MR2__ 178 /* 179 * Abuse enable_if to make these be seen as overloads of umask, rather than 180 * definitions. 181 */ 182 __BIONIC_ERROR_FUNCTION_VISIBILITY 183 mode_t umask(mode_t mode) __overloadable 184 __enable_if(1, "") 185 __enable_if(mode & ~0777, __umask_invalid_mode_str) 186 __errorattr(__umask_invalid_mode_str); 187 188 __BIONIC_FORTIFY_INLINE 189 mode_t umask(mode_t mode) __enable_if(1, "") __overloadable { 190 return __umask_chk(mode); 191 } 192 #endif /* __ANDROID_API__ >= __ANDROID_API_J_MR2__ */ 193 194 #else /* defined(__clang__) */ 195 __errordecl(__umask_invalid_mode, __umask_invalid_mode_str); 196 extern mode_t __umask_real(mode_t) __RENAME(umask); 197 198 #if __ANDROID_API__ >= __ANDROID_API_J_MR2__ 199 __BIONIC_FORTIFY_INLINE 200 mode_t umask(mode_t mode) { 201 if (__builtin_constant_p(mode)) { 202 if ((mode & 0777) != mode) { 203 __umask_invalid_mode(); 204 } 205 return __umask_real(mode); 206 } 207 return __umask_chk(mode); 208 } 209 #endif /* __ANDROID_API__ >= __ANDROID_API_J_MR2__ */ 210 211 #endif /* defined(__clang__) */ 212 #undef __umask_invalid_mode_str 213 214 #endif /* defined(__BIONIC_FORTIFY) */ 215 216 #if __ANDROID_API__ >= __ANDROID_API_L__ 217 int mkfifo(const char*, mode_t) __INTRODUCED_IN(21); 218 #else 219 // Implemented as a static inline before 21. 220 #endif 221 222 int mkfifoat(int, const char*, mode_t) __INTRODUCED_IN(23); 223 224 int fchmodat(int, const char*, mode_t, int); 225 int mkdirat(int, const char*, mode_t); 226 int mknodat(int, const char*, mode_t, dev_t) __INTRODUCED_IN(21); 227 228 #define UTIME_NOW ((1L << 30) - 1L) 229 #define UTIME_OMIT ((1L << 30) - 2L) 230 int utimensat(int fd, const char* path, const struct timespec times[2], int flags) 231 __INTRODUCED_IN(12); 232 int futimens(int fd, const struct timespec times[2]) __INTRODUCED_IN(19); 233 234 __END_DECLS 235 236 #include <android/legacy_sys_stat_inlines.h> 237 238 #endif /* _SYS_STAT_H_ */ 239