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 | |
| 32 | #include <sys/cdefs.h> |
| 33 | #include <sys/types.h> |
| 34 | #include <sys/time.h> |
| 35 | #include <linux/stat.h> |
| 36 | |
| 37 | #include <endian.h> |
| 38 | |
| 39 | __BEGIN_DECLS |
| 40 | |
Elliott Hughes | b8fa5b1 | 2013-12-19 16:50:22 -0800 | [diff] [blame] | 41 | #if defined(__aarch64__) |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 42 | #define __STAT64_BODY \ |
| 43 | unsigned long st_dev; \ |
| 44 | unsigned long st_ino; \ |
| 45 | unsigned int st_mode; \ |
| 46 | unsigned int st_nlink; \ |
Elliott Hughes | 6b55593 | 2014-02-18 16:43:31 -0800 | [diff] [blame] | 47 | uid_t st_uid; \ |
| 48 | gid_t st_gid; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 49 | unsigned long st_rdev; \ |
| 50 | unsigned long __pad1; \ |
| 51 | long st_size; \ |
| 52 | int st_blksize; \ |
| 53 | int __pad2; \ |
| 54 | long st_blocks; \ |
Elliott Hughes | 0ac0df8 | 2014-11-07 19:15:10 -0800 | [diff] [blame^] | 55 | struct timespec st_atim; \ |
| 56 | struct timespec st_mtim; \ |
| 57 | struct timespec st_ctim; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 58 | unsigned int __unused4; \ |
| 59 | unsigned int __unused5; \ |
| 60 | |
Elliott Hughes | b8fa5b1 | 2013-12-19 16:50:22 -0800 | [diff] [blame] | 61 | #elif defined(__mips__) |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 62 | #define __STAT64_BODY \ |
| 63 | unsigned int st_dev; \ |
| 64 | unsigned int __pad0[3]; \ |
| 65 | unsigned long long st_ino; \ |
| 66 | unsigned int st_mode; \ |
| 67 | unsigned int st_nlink; \ |
Elliott Hughes | 6b55593 | 2014-02-18 16:43:31 -0800 | [diff] [blame] | 68 | uid_t st_uid; \ |
| 69 | gid_t st_gid; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 70 | unsigned int st_rdev; \ |
| 71 | unsigned int __pad1[3]; \ |
| 72 | long long st_size; \ |
Elliott Hughes | 0ac0df8 | 2014-11-07 19:15:10 -0800 | [diff] [blame^] | 73 | struct timespec st_atim; \ |
| 74 | struct timespec st_mtim; \ |
| 75 | struct timespec st_ctim; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 76 | unsigned int st_blksize; \ |
| 77 | unsigned int __pad2; \ |
| 78 | unsigned long long st_blocks; \ |
| 79 | |
Elliott Hughes | b8fa5b1 | 2013-12-19 16:50:22 -0800 | [diff] [blame] | 80 | #elif defined(__x86_64__) |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 81 | #define __STAT64_BODY \ |
| 82 | unsigned long st_dev; \ |
| 83 | unsigned long st_ino; \ |
| 84 | unsigned long st_nlink; \ |
| 85 | unsigned int st_mode; \ |
Elliott Hughes | 6b55593 | 2014-02-18 16:43:31 -0800 | [diff] [blame] | 86 | uid_t st_uid; \ |
| 87 | gid_t st_gid; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 88 | unsigned int __pad0; \ |
| 89 | unsigned long st_rdev; \ |
| 90 | long st_size; \ |
| 91 | long st_blksize; \ |
| 92 | long st_blocks; \ |
Elliott Hughes | 0ac0df8 | 2014-11-07 19:15:10 -0800 | [diff] [blame^] | 93 | struct timespec st_atim; \ |
| 94 | struct timespec st_mtim; \ |
| 95 | struct timespec st_ctim; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 96 | long __pad3[3]; \ |
| 97 | |
Raghu Gandham | 6437eac | 2012-08-02 16:50:10 -0700 | [diff] [blame] | 98 | #else |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 99 | #define __STAT64_BODY \ |
| 100 | unsigned long long st_dev; \ |
| 101 | unsigned char __pad0[4]; \ |
| 102 | unsigned long __st_ino; \ |
| 103 | unsigned int st_mode; \ |
| 104 | unsigned int st_nlink; \ |
Elliott Hughes | 6b55593 | 2014-02-18 16:43:31 -0800 | [diff] [blame] | 105 | uid_t st_uid; \ |
| 106 | gid_t st_gid; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 107 | unsigned long long st_rdev; \ |
| 108 | unsigned char __pad3[4]; \ |
| 109 | long long st_size; \ |
| 110 | unsigned long st_blksize; \ |
| 111 | unsigned long long st_blocks; \ |
Elliott Hughes | 0ac0df8 | 2014-11-07 19:15:10 -0800 | [diff] [blame^] | 112 | struct timespec st_atim; \ |
| 113 | struct timespec st_mtim; \ |
| 114 | struct timespec st_ctim; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 115 | unsigned long long st_ino; \ |
| 116 | |
Raghu Gandham | 6437eac | 2012-08-02 16:50:10 -0700 | [diff] [blame] | 117 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 118 | |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 119 | struct stat { __STAT64_BODY }; |
| 120 | struct stat64 { __STAT64_BODY }; |
| 121 | |
Calin Juravle | f963da2 | 2014-05-13 11:01:11 +0100 | [diff] [blame] | 122 | #undef __STAT64_BODY |
| 123 | |
Elliott Hughes | 0ac0df8 | 2014-11-07 19:15:10 -0800 | [diff] [blame^] | 124 | /* Compatibility with older versions of POSIX. */ |
| 125 | #define st_atime st_atim.tv_sec |
| 126 | #define st_mtime st_mtim.tv_sec |
| 127 | #define st_ctime st_ctim.tv_sec |
| 128 | /* Compatibility with glibc. */ |
| 129 | #define st_atimensec st_atim.tv_nsec |
| 130 | #define st_mtimensec st_mtim.tv_nsec |
| 131 | #define st_ctimensec st_ctim.tv_nsec |
| 132 | /* Compatibility with the kernel and older versions of bionic. */ |
| 133 | #define st_atime_nsec st_atim.tv_nsec |
| 134 | #define st_mtime_nsec st_mtim.tv_nsec |
| 135 | #define st_ctime_nsec st_ctim.tv_nsec |
David 'Digit' Turner | 09baf4e | 2009-06-22 12:16:06 +0200 | [diff] [blame] | 136 | |
Hakan Kvist | f27b7fb | 2012-10-10 08:32:52 +0200 | [diff] [blame] | 137 | #ifdef __USE_BSD |
| 138 | /* Permission macros provided by glibc for compatibility with BSDs. */ |
| 139 | #define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */ |
| 140 | #define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */ |
| 141 | #define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */ |
| 142 | #endif |
| 143 | |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 144 | extern int chmod(const char*, mode_t); |
| 145 | extern int fchmod(int, mode_t); |
| 146 | extern int mkdir(const char*, mode_t); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 147 | |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 148 | extern int fstat(int, struct stat*); |
| 149 | extern int fstat64(int, struct stat64*); |
| 150 | extern int fstatat(int, const char*, struct stat*, int); |
| 151 | extern int fstatat64(int, const char*, struct stat64*, int); |
| 152 | extern int lstat(const char*, struct stat*); |
| 153 | extern int lstat64(const char*, struct stat64*); |
| 154 | extern int stat(const char*, struct stat*); |
| 155 | extern int stat64(const char*, struct stat64*); |
| 156 | |
| 157 | extern int mknod(const char*, mode_t, dev_t); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 158 | extern mode_t umask(mode_t); |
| 159 | |
Nick Kralevich | cd58770 | 2012-09-26 10:02:30 -0700 | [diff] [blame] | 160 | extern mode_t __umask_chk(mode_t); |
Elliott Hughes | 2cfb4e8 | 2014-08-18 14:45:42 -0700 | [diff] [blame] | 161 | extern mode_t __umask_real(mode_t) __RENAME(umask); |
Nick Kralevich | a641c18 | 2013-06-18 13:07:18 -0700 | [diff] [blame] | 162 | __errordecl(__umask_invalid_mode, "umask called with invalid mode"); |
Nick Kralevich | cd58770 | 2012-09-26 10:02:30 -0700 | [diff] [blame] | 163 | |
Dan Albert | 658727e | 2014-10-07 11:10:36 -0700 | [diff] [blame] | 164 | #if defined(__BIONIC_FORTIFY) |
| 165 | |
Nick Kralevich | cd58770 | 2012-09-26 10:02:30 -0700 | [diff] [blame] | 166 | __BIONIC_FORTIFY_INLINE |
| 167 | mode_t umask(mode_t mode) { |
Nick Kralevich | a6cde39 | 2013-06-29 08:15:25 -0700 | [diff] [blame] | 168 | #if !defined(__clang__) |
Nick Kralevich | cd58770 | 2012-09-26 10:02:30 -0700 | [diff] [blame] | 169 | if (__builtin_constant_p(mode)) { |
| 170 | if ((mode & 0777) != mode) { |
Nick Kralevich | a641c18 | 2013-06-18 13:07:18 -0700 | [diff] [blame] | 171 | __umask_invalid_mode(); |
Nick Kralevich | cd58770 | 2012-09-26 10:02:30 -0700 | [diff] [blame] | 172 | } |
| 173 | return __umask_real(mode); |
| 174 | } |
Nick Kralevich | a6cde39 | 2013-06-29 08:15:25 -0700 | [diff] [blame] | 175 | #endif |
Nick Kralevich | cd58770 | 2012-09-26 10:02:30 -0700 | [diff] [blame] | 176 | return __umask_chk(mode); |
| 177 | } |
Nick Kralevich | a6cde39 | 2013-06-29 08:15:25 -0700 | [diff] [blame] | 178 | #endif /* defined(__BIONIC_FORTIFY) */ |
Nick Kralevich | cd58770 | 2012-09-26 10:02:30 -0700 | [diff] [blame] | 179 | |
Elliott Hughes | 594b1a4 | 2013-10-22 10:54:11 -0700 | [diff] [blame] | 180 | extern int mkfifo(const char*, mode_t); |
Elliott Hughes | ca8e84c | 2014-10-23 19:10:23 -0700 | [diff] [blame] | 181 | extern int mkfifoat(int, const char*, mode_t); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 182 | |
Elliott Hughes | f8fcfbc | 2013-10-22 13:28:46 -0700 | [diff] [blame] | 183 | extern int fchmodat(int, const char*, mode_t, int); |
Elliott Hughes | f8fcfbc | 2013-10-22 13:28:46 -0700 | [diff] [blame] | 184 | extern int mkdirat(int, const char*, mode_t); |
| 185 | extern int mknodat(int, const char*, mode_t, dev_t); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 186 | |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 187 | #define UTIME_NOW ((1L << 30) - 1L) |
| 188 | #define UTIME_OMIT ((1L << 30) - 2L) |
Elliott Hughes | d0be7c8 | 2013-08-08 17:13:33 -0700 | [diff] [blame] | 189 | extern int utimensat(int fd, const char *path, const struct timespec times[2], int flags); |
| 190 | extern int futimens(int fd, const struct timespec times[2]); |
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 | |
| 194 | #endif /* _SYS_STAT_H_ */ |