blob: cc9dd9196694c980a29f5b8bec54c099048fd8b6 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
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 Hughesb8104622014-08-19 09:18:03 -070028
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080029#ifndef _SYS_STAT_H_
30#define _SYS_STAT_H_
31
Elliott Hughes5704c422016-01-25 18:06:24 -080032#include <bits/timespec.h>
Yabin Cuidb499032014-12-09 20:15:48 -080033#include <linux/stat.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080034#include <sys/cdefs.h>
35#include <sys/types.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080036
37__BEGIN_DECLS
38
Raghu Gandham86d2fee2015-01-15 11:12:22 -080039#if defined(__aarch64__) || (defined(__mips__) && defined(__LP64__))
Elliott Hughesdb1ea342014-01-17 18:42:49 -080040#define __STAT64_BODY \
Elliott Hughes9257c472014-12-18 15:17:42 -080041 dev_t st_dev; \
42 ino_t st_ino; \
43 mode_t st_mode; \
44 nlink_t st_nlink; \
Elliott Hughes6b555932014-02-18 16:43:31 -080045 uid_t st_uid; \
46 gid_t st_gid; \
Elliott Hughes9257c472014-12-18 15:17:42 -080047 dev_t st_rdev; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080048 unsigned long __pad1; \
Elliott Hughes9257c472014-12-18 15:17:42 -080049 off_t st_size; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080050 int st_blksize; \
51 int __pad2; \
52 long st_blocks; \
Elliott Hughes0ac0df82014-11-07 19:15:10 -080053 struct timespec st_atim; \
54 struct timespec st_mtim; \
55 struct timespec st_ctim; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080056 unsigned int __unused4; \
57 unsigned int __unused5; \
58
Raghu Gandham86d2fee2015-01-15 11:12:22 -080059#elif defined(__mips__) && !defined(__LP64__)
Elliott Hughesdb1ea342014-01-17 18:42:49 -080060#define __STAT64_BODY \
61 unsigned int st_dev; \
62 unsigned int __pad0[3]; \
63 unsigned long long st_ino; \
Elliott Hughes9257c472014-12-18 15:17:42 -080064 mode_t st_mode; \
65 nlink_t st_nlink; \
Elliott Hughes6b555932014-02-18 16:43:31 -080066 uid_t st_uid; \
67 gid_t st_gid; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080068 unsigned int st_rdev; \
69 unsigned int __pad1[3]; \
70 long long st_size; \
Elliott Hughes0ac0df82014-11-07 19:15:10 -080071 struct timespec st_atim; \
72 struct timespec st_mtim; \
73 struct timespec st_ctim; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080074 unsigned int st_blksize; \
75 unsigned int __pad2; \
76 unsigned long long st_blocks; \
77
Elliott Hughesb8fa5b12013-12-19 16:50:22 -080078#elif defined(__x86_64__)
Elliott Hughesdb1ea342014-01-17 18:42:49 -080079#define __STAT64_BODY \
Elliott Hughes1c52e6c2014-12-18 12:38:44 -080080 dev_t st_dev; \
81 ino_t st_ino; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080082 unsigned long st_nlink; \
Elliott Hughes1c52e6c2014-12-18 12:38:44 -080083 mode_t st_mode; \
Elliott Hughes6b555932014-02-18 16:43:31 -080084 uid_t st_uid; \
85 gid_t st_gid; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080086 unsigned int __pad0; \
Elliott Hughes1c52e6c2014-12-18 12:38:44 -080087 dev_t st_rdev; \
88 off_t st_size; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080089 long st_blksize; \
90 long st_blocks; \
Elliott Hughes0ac0df82014-11-07 19:15:10 -080091 struct timespec st_atim; \
92 struct timespec st_mtim; \
93 struct timespec st_ctim; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080094 long __pad3[3]; \
95
Elliott Hughes9257c472014-12-18 15:17:42 -080096#else /* __arm__ || __i386__ */
Elliott Hughesdb1ea342014-01-17 18:42:49 -080097#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 Hughes9257c472014-12-18 15:17:42 -0800102 nlink_t st_nlink; \
Elliott Hughes6b555932014-02-18 16:43:31 -0800103 uid_t st_uid; \
104 gid_t st_gid; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -0800105 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 Hughes0ac0df82014-11-07 19:15:10 -0800110 struct timespec st_atim; \
111 struct timespec st_mtim; \
112 struct timespec st_ctim; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -0800113 unsigned long long st_ino; \
114
Raghu Gandham6437eac2012-08-02 16:50:10 -0700115#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800116
Elliott Hughesdb1ea342014-01-17 18:42:49 -0800117struct stat { __STAT64_BODY };
118struct stat64 { __STAT64_BODY };
119
Calin Juravlef963da22014-05-13 11:01:11 +0100120#undef __STAT64_BODY
121
Elliott Hughes0ac0df82014-11-07 19:15:10 -0800122/* 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
David 'Digit' Turner09baf4e2009-06-22 12:16:06 +0200130
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700131#if defined(__USE_BSD)
Hakan Kvistf27b7fb2012-10-10 08:32:52 +0200132/* Permission macros provided by glibc for compatibility with BSDs. */
133#define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */
134#define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */
135#define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */
136#endif
137
Elliott Hughes1f1a51a2016-03-31 17:05:30 -0700138#if defined(__USE_BSD) || defined(__USE_GNU)
139#define S_IREAD S_IRUSR
140#define S_IWRITE S_IWUSR
141#define S_IEXEC S_IXUSR
142#endif
143
Elliott Hughes92887612016-08-16 13:26:35 -0700144/* POSIX mandates these, but Linux doesn't implement them as distinct file types. */
145#define S_TYPEISMQ(__sb) 0
146#define S_TYPEISSEM(__sb) 0
147#define S_TYPEISSHM(__sb) 0
148#define S_TYPEISTMO(__sb) 0
149
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700150int chmod(const char*, mode_t);
151int fchmod(int, mode_t);
152int mkdir(const char*, mode_t);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800153
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700154int fstat(int, struct stat*);
155int fstat64(int, struct stat64*) __INTRODUCED_IN(21);
156int fstatat(int, const char*, struct stat*, int);
157int fstatat64(int, const char*, struct stat64*, int) __INTRODUCED_IN(21);
158int lstat(const char*, struct stat*);
159int lstat64(const char*, struct stat64*) __INTRODUCED_IN(21);
160int stat(const char*, struct stat*);
161int stat64(const char*, struct stat64*) __INTRODUCED_IN(21);
Elliott Hughesdb1ea342014-01-17 18:42:49 -0800162
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700163int mknod(const char*, mode_t, dev_t);
164mode_t umask(mode_t);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800165
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700166mode_t __umask_chk(mode_t) __INTRODUCED_IN(18);
167mode_t __umask_real(mode_t) __RENAME(umask);
Nick Kralevicha641c182013-06-18 13:07:18 -0700168__errordecl(__umask_invalid_mode, "umask called with invalid mode");
Nick Kralevichcd587702012-09-26 10:02:30 -0700169
Dan Albert658727e2014-10-07 11:10:36 -0700170#if defined(__BIONIC_FORTIFY)
171
Dan Albertdfa6bbb2016-08-02 15:08:32 -0700172#if __ANDROID_API__ >= 18
Nick Kralevichcd587702012-09-26 10:02:30 -0700173__BIONIC_FORTIFY_INLINE
174mode_t umask(mode_t mode) {
Nick Kralevicha6cde392013-06-29 08:15:25 -0700175#if !defined(__clang__)
Nick Kralevichcd587702012-09-26 10:02:30 -0700176 if (__builtin_constant_p(mode)) {
177 if ((mode & 0777) != mode) {
Nick Kralevicha641c182013-06-18 13:07:18 -0700178 __umask_invalid_mode();
Nick Kralevichcd587702012-09-26 10:02:30 -0700179 }
180 return __umask_real(mode);
181 }
Nick Kralevicha6cde392013-06-29 08:15:25 -0700182#endif
Nick Kralevichcd587702012-09-26 10:02:30 -0700183 return __umask_chk(mode);
184}
Dan Albertdfa6bbb2016-08-02 15:08:32 -0700185#endif /* __ANDROID_API__ >= 18 */
186
Nick Kralevicha6cde392013-06-29 08:15:25 -0700187#endif /* defined(__BIONIC_FORTIFY) */
Nick Kralevichcd587702012-09-26 10:02:30 -0700188
Josh Gao8778d642016-07-22 15:26:36 -0700189#if __ANDROID_API__ >= 21
Josh Gaob6a4a4c2016-07-26 16:34:40 -0700190int mkfifo(const char*, mode_t) __INTRODUCED_IN(21);
Josh Gao8778d642016-07-22 15:26:36 -0700191#else
192// Implemented as a static inline before 21.
193#endif
194
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700195int mkfifoat(int, const char*, mode_t) __INTRODUCED_IN(23);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800196
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700197int fchmodat(int, const char*, mode_t, int);
198int mkdirat(int, const char*, mode_t);
199int mknodat(int, const char*, mode_t, dev_t) __INTRODUCED_IN(21);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800200
Elliott Hughesdb1ea342014-01-17 18:42:49 -0800201#define UTIME_NOW ((1L << 30) - 1L)
202#define UTIME_OMIT ((1L << 30) - 2L)
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700203int utimensat(int fd, const char* path, const struct timespec times[2], int flags)
Josh Gao14adff12016-04-29 12:00:55 -0700204 __INTRODUCED_IN(12);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700205int futimens(int fd, const struct timespec times[2]) __INTRODUCED_IN(19);
Ken Sumrallae2d5ba2011-03-18 11:55:12 -0700206
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800207__END_DECLS
208
Josh Gaob8e1b7052016-04-13 17:18:20 -0700209#include <android/legacy_sys_stat_inlines.h>
210
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800211#endif /* _SYS_STAT_H_ */