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 #ifndef _SYS_STAT_H_
29 #define _SYS_STAT_H_
30
31 #include <sys/cdefs.h>
32 #include <sys/types.h>
33 #include <sys/time.h>
34 #include <linux/stat.h>
35
36 #include <endian.h>
37
38 __BEGIN_DECLS
39
40 #if defined(__aarch64__)
41 #define __STAT64_BODY \
42 unsigned long st_dev; \
43 unsigned long st_ino; \
44 unsigned int st_mode; \
45 unsigned int st_nlink; \
46 uid_t st_uid; \
47 gid_t st_gid; \
48 unsigned long st_rdev; \
49 unsigned long __pad1; \
50 long st_size; \
51 int st_blksize; \
52 int __pad2; \
53 long st_blocks; \
54 long st_atime; \
55 unsigned long st_atime_nsec; \
56 long st_mtime; \
57 unsigned long st_mtime_nsec; \
58 long st_ctime; \
59 unsigned long st_ctime_nsec; \
60 unsigned int __unused4; \
61 unsigned int __unused5; \
62
63 #elif defined(__mips__)
64 #define __STAT64_BODY \
65 unsigned int st_dev; \
66 unsigned int __pad0[3]; \
67 unsigned long long st_ino; \
68 unsigned int st_mode; \
69 unsigned int st_nlink; \
70 uid_t st_uid; \
71 gid_t st_gid; \
72 unsigned int st_rdev; \
73 unsigned int __pad1[3]; \
74 long long st_size; \
75 unsigned int st_atime; \
76 unsigned int st_atime_nsec; \
77 unsigned int st_mtime; \
78 unsigned int st_mtime_nsec; \
79 unsigned int st_ctime; \
80 unsigned int st_ctime_nsec; \
81 unsigned int st_blksize; \
82 unsigned int __pad2; \
83 unsigned long long st_blocks; \
84
85 #elif defined(__x86_64__)
86 #define __STAT64_BODY \
87 unsigned long st_dev; \
88 unsigned long st_ino; \
89 unsigned long st_nlink; \
90 unsigned int st_mode; \
91 uid_t st_uid; \
92 gid_t st_gid; \
93 unsigned int __pad0; \
94 unsigned long st_rdev; \
95 long st_size; \
96 long st_blksize; \
97 long st_blocks; \
98 unsigned long st_atime; \
99 unsigned long st_atime_nsec; \
100 unsigned long st_mtime; \
101 unsigned long st_mtime_nsec; \
102 unsigned long st_ctime; \
103 unsigned long st_ctime_nsec; \
104 long __pad3[3]; \
105
106 #else
107 #define __STAT64_BODY \
108 unsigned long long st_dev; \
109 unsigned char __pad0[4]; \
110 unsigned long __st_ino; \
111 unsigned int st_mode; \
112 unsigned int st_nlink; \
113 uid_t st_uid; \
114 gid_t st_gid; \
115 unsigned long long st_rdev; \
116 unsigned char __pad3[4]; \
117 long long st_size; \
118 unsigned long st_blksize; \
119 unsigned long long st_blocks; \
120 unsigned long st_atime; \
121 unsigned long st_atime_nsec; \
122 unsigned long st_mtime; \
123 unsigned long st_mtime_nsec; \
124 unsigned long st_ctime; \
125 unsigned long st_ctime_nsec; \
126 unsigned long long st_ino; \
127
128 #endif
129
130 struct stat { __STAT64_BODY };
131 struct stat64 { __STAT64_BODY };
132
133 #undef __STAT64_BODY
134
135 #define st_atimensec st_atime_nsec
136 #define st_mtimensec st_mtime_nsec
137 #define st_ctimensec st_ctime_nsec
138
139 #ifdef __USE_BSD
140 /* Permission macros provided by glibc for compatibility with BSDs. */
141 #define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */
142 #define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */
143 #define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */
144 #endif
145
146 extern int chmod(const char*, mode_t);
147 extern int fchmod(int, mode_t);
148 extern int mkdir(const char*, mode_t);
149
150 extern int fstat(int, struct stat*);
151 extern int fstat64(int, struct stat64*);
152 extern int fstatat(int, const char*, struct stat*, int);
153 extern int fstatat64(int, const char*, struct stat64*, int);
154 extern int lstat(const char*, struct stat*);
155 extern int lstat64(const char*, struct stat64*);
156 extern int stat(const char*, struct stat*);
157 extern int stat64(const char*, struct stat64*);
158
159 extern int mknod(const char*, mode_t, dev_t);
160 extern mode_t umask(mode_t);
161
162 extern mode_t __umask_chk(mode_t);
163 extern mode_t __umask_real(mode_t) __RENAME(umask);
164 __errordecl(__umask_invalid_mode, "umask called with invalid mode");
165
166 #if defined(__BIONIC_FORTIFY)
167
168 __BIONIC_FORTIFY_INLINE
umask(mode_t mode)169 mode_t umask(mode_t mode) {
170 #if !defined(__clang__)
171 if (__builtin_constant_p(mode)) {
172 if ((mode & 0777) != mode) {
173 __umask_invalid_mode();
174 }
175 return __umask_real(mode);
176 }
177 #endif
178 return __umask_chk(mode);
179 }
180 #endif /* defined(__BIONIC_FORTIFY) */
181
182 extern int mkfifo(const char*, mode_t);
183
184 extern int fchmodat(int, const char*, mode_t, int);
185 extern int mkdirat(int, const char*, mode_t);
186 extern int mknodat(int, const char*, mode_t, dev_t);
187
188 #define UTIME_NOW ((1L << 30) - 1L)
189 #define UTIME_OMIT ((1L << 30) - 2L)
190 extern int utimensat(int fd, const char *path, const struct timespec times[2], int flags);
191 extern int futimens(int fd, const struct timespec times[2]);
192
193 __END_DECLS
194
195 #endif /* _SYS_STAT_H_ */
196