blob: 9fed170a559a82f1192adb5b3db22e9c5346e33c [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
Yabin Cuidb499032014-12-09 20:15:48 -080032#include <endian.h>
33#include <linux/stat.h>
34#include <machine/timespec.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080035#include <sys/cdefs.h>
36#include <sys/types.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080037
38__BEGIN_DECLS
39
Elliott Hughesb8fa5b12013-12-19 16:50:22 -080040#if defined(__aarch64__)
Elliott Hughesdb1ea342014-01-17 18:42:49 -080041#define __STAT64_BODY \
Elliott Hughes9257c472014-12-18 15:17:42 -080042 dev_t st_dev; \
43 ino_t st_ino; \
44 mode_t st_mode; \
45 nlink_t st_nlink; \
Elliott Hughes6b555932014-02-18 16:43:31 -080046 uid_t st_uid; \
47 gid_t st_gid; \
Elliott Hughes9257c472014-12-18 15:17:42 -080048 dev_t st_rdev; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080049 unsigned long __pad1; \
Elliott Hughes9257c472014-12-18 15:17:42 -080050 off_t st_size; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080051 int st_blksize; \
52 int __pad2; \
53 long st_blocks; \
Elliott Hughes0ac0df82014-11-07 19:15:10 -080054 struct timespec st_atim; \
55 struct timespec st_mtim; \
56 struct timespec st_ctim; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080057 unsigned int __unused4; \
58 unsigned int __unused5; \
59
Elliott Hughes9257c472014-12-18 15:17:42 -080060#elif defined(__mips__) /* and mips64 */
Elliott Hughesdb1ea342014-01-17 18:42:49 -080061#define __STAT64_BODY \
62 unsigned int st_dev; \
63 unsigned int __pad0[3]; \
64 unsigned long long st_ino; \
Elliott Hughes9257c472014-12-18 15:17:42 -080065 mode_t st_mode; \
66 nlink_t st_nlink; \
Elliott Hughes6b555932014-02-18 16:43:31 -080067 uid_t st_uid; \
68 gid_t st_gid; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080069 unsigned int st_rdev; \
70 unsigned int __pad1[3]; \
71 long long st_size; \
Elliott Hughes0ac0df82014-11-07 19:15:10 -080072 struct timespec st_atim; \
73 struct timespec st_mtim; \
74 struct timespec st_ctim; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080075 unsigned int st_blksize; \
76 unsigned int __pad2; \
77 unsigned long long st_blocks; \
78
Elliott Hughesb8fa5b12013-12-19 16:50:22 -080079#elif defined(__x86_64__)
Elliott Hughesdb1ea342014-01-17 18:42:49 -080080#define __STAT64_BODY \
Elliott Hughes1c52e6c2014-12-18 12:38:44 -080081 dev_t st_dev; \
82 ino_t st_ino; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080083 unsigned long st_nlink; \
Elliott Hughes1c52e6c2014-12-18 12:38:44 -080084 mode_t st_mode; \
Elliott Hughes6b555932014-02-18 16:43:31 -080085 uid_t st_uid; \
86 gid_t st_gid; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080087 unsigned int __pad0; \
Elliott Hughes1c52e6c2014-12-18 12:38:44 -080088 dev_t st_rdev; \
89 off_t st_size; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080090 long st_blksize; \
91 long st_blocks; \
Elliott Hughes0ac0df82014-11-07 19:15:10 -080092 struct timespec st_atim; \
93 struct timespec st_mtim; \
94 struct timespec st_ctim; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080095 long __pad3[3]; \
96
Elliott Hughes9257c472014-12-18 15:17:42 -080097#else /* __arm__ || __i386__ */
Elliott Hughesdb1ea342014-01-17 18:42:49 -080098#define __STAT64_BODY \
99 unsigned long long st_dev; \
100 unsigned char __pad0[4]; \
101 unsigned long __st_ino; \
102 unsigned int st_mode; \
Elliott Hughes9257c472014-12-18 15:17:42 -0800103 nlink_t st_nlink; \
Elliott Hughes6b555932014-02-18 16:43:31 -0800104 uid_t st_uid; \
105 gid_t st_gid; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -0800106 unsigned long long st_rdev; \
107 unsigned char __pad3[4]; \
108 long long st_size; \
109 unsigned long st_blksize; \
110 unsigned long long st_blocks; \
Elliott Hughes0ac0df82014-11-07 19:15:10 -0800111 struct timespec st_atim; \
112 struct timespec st_mtim; \
113 struct timespec st_ctim; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -0800114 unsigned long long st_ino; \
115
Raghu Gandham6437eac2012-08-02 16:50:10 -0700116#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800117
Elliott Hughesdb1ea342014-01-17 18:42:49 -0800118struct stat { __STAT64_BODY };
119struct stat64 { __STAT64_BODY };
120
Calin Juravlef963da22014-05-13 11:01:11 +0100121#undef __STAT64_BODY
122
Elliott Hughes0ac0df82014-11-07 19:15:10 -0800123/* Compatibility with older versions of POSIX. */
124#define st_atime st_atim.tv_sec
125#define st_mtime st_mtim.tv_sec
126#define st_ctime st_ctim.tv_sec
127/* Compatibility with glibc. */
128#define st_atimensec st_atim.tv_nsec
129#define st_mtimensec st_mtim.tv_nsec
130#define st_ctimensec st_ctim.tv_nsec
David 'Digit' Turner09baf4e2009-06-22 12:16:06 +0200131
Hakan Kvistf27b7fb2012-10-10 08:32:52 +0200132#ifdef __USE_BSD
133/* Permission macros provided by glibc for compatibility with BSDs. */
134#define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */
135#define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */
136#define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */
137#endif
138
Elliott Hughesdb1ea342014-01-17 18:42:49 -0800139extern int chmod(const char*, mode_t);
140extern int fchmod(int, mode_t);
141extern int mkdir(const char*, mode_t);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800142
Elliott Hughesdb1ea342014-01-17 18:42:49 -0800143extern int fstat(int, struct stat*);
144extern int fstat64(int, struct stat64*);
145extern int fstatat(int, const char*, struct stat*, int);
146extern int fstatat64(int, const char*, struct stat64*, int);
147extern int lstat(const char*, struct stat*);
148extern int lstat64(const char*, struct stat64*);
149extern int stat(const char*, struct stat*);
150extern int stat64(const char*, struct stat64*);
151
152extern int mknod(const char*, mode_t, dev_t);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800153extern mode_t umask(mode_t);
154
Nick Kralevichcd587702012-09-26 10:02:30 -0700155extern mode_t __umask_chk(mode_t);
Elliott Hughes2cfb4e82014-08-18 14:45:42 -0700156extern mode_t __umask_real(mode_t) __RENAME(umask);
Nick Kralevicha641c182013-06-18 13:07:18 -0700157__errordecl(__umask_invalid_mode, "umask called with invalid mode");
Nick Kralevichcd587702012-09-26 10:02:30 -0700158
Dan Albert658727e2014-10-07 11:10:36 -0700159#if defined(__BIONIC_FORTIFY)
160
Nick Kralevichcd587702012-09-26 10:02:30 -0700161__BIONIC_FORTIFY_INLINE
162mode_t umask(mode_t mode) {
Nick Kralevicha6cde392013-06-29 08:15:25 -0700163#if !defined(__clang__)
Nick Kralevichcd587702012-09-26 10:02:30 -0700164 if (__builtin_constant_p(mode)) {
165 if ((mode & 0777) != mode) {
Nick Kralevicha641c182013-06-18 13:07:18 -0700166 __umask_invalid_mode();
Nick Kralevichcd587702012-09-26 10:02:30 -0700167 }
168 return __umask_real(mode);
169 }
Nick Kralevicha6cde392013-06-29 08:15:25 -0700170#endif
Nick Kralevichcd587702012-09-26 10:02:30 -0700171 return __umask_chk(mode);
172}
Nick Kralevicha6cde392013-06-29 08:15:25 -0700173#endif /* defined(__BIONIC_FORTIFY) */
Nick Kralevichcd587702012-09-26 10:02:30 -0700174
Elliott Hughes594b1a42013-10-22 10:54:11 -0700175extern int mkfifo(const char*, mode_t);
Elliott Hughesca8e84c2014-10-23 19:10:23 -0700176extern int mkfifoat(int, const char*, mode_t);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800177
Elliott Hughesf8fcfbc2013-10-22 13:28:46 -0700178extern int fchmodat(int, const char*, mode_t, int);
Elliott Hughesf8fcfbc2013-10-22 13:28:46 -0700179extern int mkdirat(int, const char*, mode_t);
180extern int mknodat(int, const char*, mode_t, dev_t);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800181
Elliott Hughesdb1ea342014-01-17 18:42:49 -0800182#define UTIME_NOW ((1L << 30) - 1L)
183#define UTIME_OMIT ((1L << 30) - 2L)
Elliott Hughesd0be7c82013-08-08 17:13:33 -0700184extern int utimensat(int fd, const char *path, const struct timespec times[2], int flags);
185extern int futimens(int fd, const struct timespec times[2]);
Ken Sumrallae2d5ba2011-03-18 11:55:12 -0700186
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800187__END_DECLS
188
189#endif /* _SYS_STAT_H_ */