The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 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 | */ |
Elliott Hughes | b810462 | 2014-08-19 09:18:03 -0700 | [diff] [blame] | 28 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 29 | #ifndef _SYS_STAT_H_ |
| 30 | #define _SYS_STAT_H_ |
| 31 | |
Elliott Hughes | 5704c42 | 2016-01-25 18:06:24 -0800 | [diff] [blame] | 32 | #include <bits/timespec.h> |
Yabin Cui | db49903 | 2014-12-09 20:15:48 -0800 | [diff] [blame] | 33 | #include <linux/stat.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 34 | #include <sys/cdefs.h> |
| 35 | #include <sys/types.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 36 | |
| 37 | __BEGIN_DECLS |
| 38 | |
Raghu Gandham | 86d2fee | 2015-01-15 11:12:22 -0800 | [diff] [blame] | 39 | #if defined(__aarch64__) || (defined(__mips__) && defined(__LP64__)) |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 40 | #define __STAT64_BODY \ |
Elliott Hughes | 9257c47 | 2014-12-18 15:17:42 -0800 | [diff] [blame] | 41 | dev_t st_dev; \ |
| 42 | ino_t st_ino; \ |
| 43 | mode_t st_mode; \ |
| 44 | nlink_t st_nlink; \ |
Elliott Hughes | 6b55593 | 2014-02-18 16:43:31 -0800 | [diff] [blame] | 45 | uid_t st_uid; \ |
| 46 | gid_t st_gid; \ |
Elliott Hughes | 9257c47 | 2014-12-18 15:17:42 -0800 | [diff] [blame] | 47 | dev_t st_rdev; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 48 | unsigned long __pad1; \ |
Elliott Hughes | 9257c47 | 2014-12-18 15:17:42 -0800 | [diff] [blame] | 49 | off_t st_size; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 50 | int st_blksize; \ |
| 51 | int __pad2; \ |
| 52 | long st_blocks; \ |
Elliott Hughes | 0ac0df8 | 2014-11-07 19:15:10 -0800 | [diff] [blame] | 53 | struct timespec st_atim; \ |
| 54 | struct timespec st_mtim; \ |
| 55 | struct timespec st_ctim; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 56 | unsigned int __unused4; \ |
| 57 | unsigned int __unused5; \ |
| 58 | |
Raghu Gandham | 86d2fee | 2015-01-15 11:12:22 -0800 | [diff] [blame] | 59 | #elif defined(__mips__) && !defined(__LP64__) |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 60 | #define __STAT64_BODY \ |
| 61 | unsigned int st_dev; \ |
| 62 | unsigned int __pad0[3]; \ |
| 63 | unsigned long long st_ino; \ |
Elliott Hughes | 9257c47 | 2014-12-18 15:17:42 -0800 | [diff] [blame] | 64 | mode_t st_mode; \ |
| 65 | nlink_t st_nlink; \ |
Elliott Hughes | 6b55593 | 2014-02-18 16:43:31 -0800 | [diff] [blame] | 66 | uid_t st_uid; \ |
| 67 | gid_t st_gid; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 68 | unsigned int st_rdev; \ |
| 69 | unsigned int __pad1[3]; \ |
| 70 | long long st_size; \ |
Elliott Hughes | 0ac0df8 | 2014-11-07 19:15:10 -0800 | [diff] [blame] | 71 | struct timespec st_atim; \ |
| 72 | struct timespec st_mtim; \ |
| 73 | struct timespec st_ctim; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 74 | unsigned int st_blksize; \ |
| 75 | unsigned int __pad2; \ |
| 76 | unsigned long long st_blocks; \ |
| 77 | |
Elliott Hughes | b8fa5b1 | 2013-12-19 16:50:22 -0800 | [diff] [blame] | 78 | #elif defined(__x86_64__) |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 79 | #define __STAT64_BODY \ |
Elliott Hughes | 1c52e6c | 2014-12-18 12:38:44 -0800 | [diff] [blame] | 80 | dev_t st_dev; \ |
| 81 | ino_t st_ino; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 82 | unsigned long st_nlink; \ |
Elliott Hughes | 1c52e6c | 2014-12-18 12:38:44 -0800 | [diff] [blame] | 83 | mode_t st_mode; \ |
Elliott Hughes | 6b55593 | 2014-02-18 16:43:31 -0800 | [diff] [blame] | 84 | uid_t st_uid; \ |
| 85 | gid_t st_gid; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 86 | unsigned int __pad0; \ |
Elliott Hughes | 1c52e6c | 2014-12-18 12:38:44 -0800 | [diff] [blame] | 87 | dev_t st_rdev; \ |
| 88 | off_t st_size; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 89 | long st_blksize; \ |
| 90 | long st_blocks; \ |
Elliott Hughes | 0ac0df8 | 2014-11-07 19:15:10 -0800 | [diff] [blame] | 91 | struct timespec st_atim; \ |
| 92 | struct timespec st_mtim; \ |
| 93 | struct timespec st_ctim; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 94 | long __pad3[3]; \ |
| 95 | |
Elliott Hughes | 9257c47 | 2014-12-18 15:17:42 -0800 | [diff] [blame] | 96 | #else /* __arm__ || __i386__ */ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 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; \ |
Elliott Hughes | 9257c47 | 2014-12-18 15:17:42 -0800 | [diff] [blame] | 102 | nlink_t st_nlink; \ |
Elliott Hughes | 6b55593 | 2014-02-18 16:43:31 -0800 | [diff] [blame] | 103 | uid_t st_uid; \ |
| 104 | gid_t st_gid; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 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; \ |
Elliott Hughes | 0ac0df8 | 2014-11-07 19:15:10 -0800 | [diff] [blame] | 110 | struct timespec st_atim; \ |
| 111 | struct timespec st_mtim; \ |
| 112 | struct timespec st_ctim; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 113 | unsigned long long st_ino; \ |
| 114 | |
Raghu Gandham | 6437eac | 2012-08-02 16:50:10 -0700 | [diff] [blame] | 115 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 116 | |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 117 | struct stat { __STAT64_BODY }; |
| 118 | struct stat64 { __STAT64_BODY }; |
| 119 | |
Calin Juravle | f963da2 | 2014-05-13 11:01:11 +0100 | [diff] [blame] | 120 | #undef __STAT64_BODY |
| 121 | |
Elliott Hughes | 0ac0df8 | 2014-11-07 19:15:10 -0800 | [diff] [blame] | 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 |
Dan Albert | a4e774c | 2017-06-12 14:59:38 -0700 | [diff] [blame] | 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 |
David 'Digit' Turner | 09baf4e | 2009-06-22 12:16:06 +0200 | [diff] [blame] | 134 | |
Elliott Hughes | 3ba55f8 | 2016-06-08 18:11:23 -0700 | [diff] [blame] | 135 | #if defined(__USE_BSD) |
Hakan Kvist | f27b7fb | 2012-10-10 08:32:52 +0200 | [diff] [blame] | 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 | |
Elliott Hughes | 1f1a51a | 2016-03-31 17:05:30 -0700 | [diff] [blame] | 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 | |
Elliott Hughes | 9288761 | 2016-08-16 13:26:35 -0700 | [diff] [blame] | 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 | |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame^] | 154 | int chmod(const char* __path, mode_t __mode); |
| 155 | int fchmod(int __fd, mode_t __mode); |
| 156 | int mkdir(const char* __path, mode_t __mode); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 157 | |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame^] | 158 | int fstat(int __fd, struct stat* __buf); |
| 159 | int fstat64(int __fd, struct stat64* __buf) __INTRODUCED_IN(21); |
| 160 | int fstatat(int __dir_fd, const char* __path, struct stat* __buf, int __flags); |
| 161 | int fstatat64(int __dir_fd, const char* __path, struct stat64* __buf, int __flags) __INTRODUCED_IN(21); |
| 162 | int lstat(const char* __path, struct stat* __buf); |
| 163 | int lstat64(const char* __path, struct stat64* __buf) __INTRODUCED_IN(21); |
| 164 | int stat(const char* __path, struct stat* __buf); |
| 165 | int stat64(const char* __path, struct stat64* __buf) __INTRODUCED_IN(21); |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 166 | |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame^] | 167 | int mknod(const char* __path, mode_t __mode, dev_t __dev); |
| 168 | mode_t umask(mode_t __mask) __overloadable __RENAME_CLANG(umask); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 169 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 170 | #if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS) |
| 171 | #include <bits/fortify/stat.h> |
| 172 | #endif |
Nick Kralevich | cd58770 | 2012-09-26 10:02:30 -0700 | [diff] [blame] | 173 | |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 174 | #if __ANDROID_API__ >= __ANDROID_API_L__ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame^] | 175 | int mkfifo(const char* __path, mode_t __mode) __INTRODUCED_IN(21); |
Josh Gao | 8778d64 | 2016-07-22 15:26:36 -0700 | [diff] [blame] | 176 | #else |
| 177 | // Implemented as a static inline before 21. |
| 178 | #endif |
| 179 | |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame^] | 180 | int mkfifoat(int __dir_fd, const char* __path, mode_t __mode) __INTRODUCED_IN(23); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 181 | |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame^] | 182 | int fchmodat(int __dir_fd, const char* __path, mode_t __mode, int __flags); |
| 183 | int mkdirat(int __dir_fd, const char* __path, mode_t __mode); |
| 184 | int mknodat(int __dir_fd, const char* __path, mode_t __mode, dev_t __dev) __INTRODUCED_IN(21); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 185 | |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 186 | #define UTIME_NOW ((1L << 30) - 1L) |
| 187 | #define UTIME_OMIT ((1L << 30) - 2L) |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame^] | 188 | int utimensat(int __dir_fd, const char* __path, const struct timespec __times[2], int __flags) |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 189 | __INTRODUCED_IN(12); |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame^] | 190 | int futimens(int __dir_fd, const struct timespec __times[2]) __INTRODUCED_IN(19); |
Ken Sumrall | ae2d5ba | 2011-03-18 11:55:12 -0700 | [diff] [blame] | 191 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 192 | __END_DECLS |
| 193 | |
Josh Gao | b8e1b705 | 2016-04-13 17:18:20 -0700 | [diff] [blame] | 194 | #include <android/legacy_sys_stat_inlines.h> |
| 195 | |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame^] | 196 | #endif |