blob: d6044aedcc125983907808fe606cb8e0b29caeb8 [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 Hughesb8104622014-08-19 09:18:03 -070032#include <features.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080033#include <sys/cdefs.h>
34#include <sys/types.h>
35#include <sys/time.h>
36#include <linux/stat.h>
37
38#include <endian.h>
39
40__BEGIN_DECLS
41
Elliott Hughesb8fa5b12013-12-19 16:50:22 -080042#if defined(__aarch64__)
Elliott Hughesdb1ea342014-01-17 18:42:49 -080043#define __STAT64_BODY \
44 unsigned long st_dev; \
45 unsigned long st_ino; \
46 unsigned int st_mode; \
47 unsigned int st_nlink; \
Elliott Hughes6b555932014-02-18 16:43:31 -080048 uid_t st_uid; \
49 gid_t st_gid; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080050 unsigned long st_rdev; \
51 unsigned long __pad1; \
52 long st_size; \
53 int st_blksize; \
54 int __pad2; \
55 long st_blocks; \
56 long st_atime; \
57 unsigned long st_atime_nsec; \
58 long st_mtime; \
59 unsigned long st_mtime_nsec; \
60 long st_ctime; \
61 unsigned long st_ctime_nsec; \
62 unsigned int __unused4; \
63 unsigned int __unused5; \
64
Elliott Hughesb8fa5b12013-12-19 16:50:22 -080065#elif defined(__mips__)
Elliott Hughesdb1ea342014-01-17 18:42:49 -080066#define __STAT64_BODY \
67 unsigned int st_dev; \
68 unsigned int __pad0[3]; \
69 unsigned long long st_ino; \
70 unsigned int st_mode; \
71 unsigned int st_nlink; \
Elliott Hughes6b555932014-02-18 16:43:31 -080072 uid_t st_uid; \
73 gid_t st_gid; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080074 unsigned int st_rdev; \
75 unsigned int __pad1[3]; \
76 long long st_size; \
77 unsigned int st_atime; \
78 unsigned int st_atime_nsec; \
79 unsigned int st_mtime; \
80 unsigned int st_mtime_nsec; \
81 unsigned int st_ctime; \
82 unsigned int st_ctime_nsec; \
83 unsigned int st_blksize; \
84 unsigned int __pad2; \
85 unsigned long long st_blocks; \
86
Elliott Hughesb8fa5b12013-12-19 16:50:22 -080087#elif defined(__x86_64__)
Elliott Hughesdb1ea342014-01-17 18:42:49 -080088#define __STAT64_BODY \
89 unsigned long st_dev; \
90 unsigned long st_ino; \
91 unsigned long st_nlink; \
92 unsigned int st_mode; \
Elliott Hughes6b555932014-02-18 16:43:31 -080093 uid_t st_uid; \
94 gid_t st_gid; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080095 unsigned int __pad0; \
96 unsigned long st_rdev; \
97 long st_size; \
98 long st_blksize; \
99 long st_blocks; \
100 unsigned long st_atime; \
101 unsigned long st_atime_nsec; \
102 unsigned long st_mtime; \
103 unsigned long st_mtime_nsec; \
104 unsigned long st_ctime; \
105 unsigned long st_ctime_nsec; \
106 long __pad3[3]; \
107
Raghu Gandham6437eac2012-08-02 16:50:10 -0700108#else
Elliott Hughesdb1ea342014-01-17 18:42:49 -0800109#define __STAT64_BODY \
110 unsigned long long st_dev; \
111 unsigned char __pad0[4]; \
112 unsigned long __st_ino; \
113 unsigned int st_mode; \
114 unsigned int st_nlink; \
Elliott Hughes6b555932014-02-18 16:43:31 -0800115 uid_t st_uid; \
116 gid_t st_gid; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -0800117 unsigned long long st_rdev; \
118 unsigned char __pad3[4]; \
119 long long st_size; \
120 unsigned long st_blksize; \
121 unsigned long long st_blocks; \
122 unsigned long st_atime; \
123 unsigned long st_atime_nsec; \
124 unsigned long st_mtime; \
125 unsigned long st_mtime_nsec; \
126 unsigned long st_ctime; \
127 unsigned long st_ctime_nsec; \
128 unsigned long long st_ino; \
129
Raghu Gandham6437eac2012-08-02 16:50:10 -0700130#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800131
Elliott Hughesdb1ea342014-01-17 18:42:49 -0800132struct stat { __STAT64_BODY };
133struct stat64 { __STAT64_BODY };
134
Calin Juravlef963da22014-05-13 11:01:11 +0100135#undef __STAT64_BODY
136
Elliott Hughesdb1ea342014-01-17 18:42:49 -0800137#define st_atimensec st_atime_nsec
138#define st_mtimensec st_mtime_nsec
139#define st_ctimensec st_ctime_nsec
David 'Digit' Turner09baf4e2009-06-22 12:16:06 +0200140
Hakan Kvistf27b7fb2012-10-10 08:32:52 +0200141#ifdef __USE_BSD
142/* Permission macros provided by glibc for compatibility with BSDs. */
143#define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */
144#define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */
145#define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */
146#endif
147
Elliott Hughesdb1ea342014-01-17 18:42:49 -0800148extern int chmod(const char*, mode_t);
149extern int fchmod(int, mode_t);
150extern int mkdir(const char*, mode_t);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800151
Elliott Hughesdb1ea342014-01-17 18:42:49 -0800152extern int fstat(int, struct stat*);
153extern int fstat64(int, struct stat64*);
154extern int fstatat(int, const char*, struct stat*, int);
155extern int fstatat64(int, const char*, struct stat64*, int);
156extern int lstat(const char*, struct stat*);
157extern int lstat64(const char*, struct stat64*);
158extern int stat(const char*, struct stat*);
159extern int stat64(const char*, struct stat64*);
160
161extern int mknod(const char*, mode_t, dev_t);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800162extern mode_t umask(mode_t);
163
Nick Kralevicha6cde392013-06-29 08:15:25 -0700164#if defined(__BIONIC_FORTIFY)
Nick Kralevichcd587702012-09-26 10:02:30 -0700165
166extern mode_t __umask_chk(mode_t);
Elliott Hughes2cfb4e82014-08-18 14:45:42 -0700167extern mode_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
170__BIONIC_FORTIFY_INLINE
171mode_t umask(mode_t mode) {
Nick Kralevicha6cde392013-06-29 08:15:25 -0700172#if !defined(__clang__)
Nick Kralevichcd587702012-09-26 10:02:30 -0700173 if (__builtin_constant_p(mode)) {
174 if ((mode & 0777) != mode) {
Nick Kralevicha641c182013-06-18 13:07:18 -0700175 __umask_invalid_mode();
Nick Kralevichcd587702012-09-26 10:02:30 -0700176 }
177 return __umask_real(mode);
178 }
Nick Kralevicha6cde392013-06-29 08:15:25 -0700179#endif
Nick Kralevichcd587702012-09-26 10:02:30 -0700180 return __umask_chk(mode);
181}
Nick Kralevicha6cde392013-06-29 08:15:25 -0700182#endif /* defined(__BIONIC_FORTIFY) */
Nick Kralevichcd587702012-09-26 10:02:30 -0700183
Elliott Hughes594b1a42013-10-22 10:54:11 -0700184extern int mkfifo(const char*, mode_t);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800185
Elliott Hughesf8fcfbc2013-10-22 13:28:46 -0700186extern int fchmodat(int, const char*, mode_t, int);
Elliott Hughesf8fcfbc2013-10-22 13:28:46 -0700187extern int mkdirat(int, const char*, mode_t);
188extern int mknodat(int, const char*, mode_t, dev_t);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800189
Elliott Hughesdb1ea342014-01-17 18:42:49 -0800190#define UTIME_NOW ((1L << 30) - 1L)
191#define UTIME_OMIT ((1L << 30) - 2L)
Elliott Hughesd0be7c82013-08-08 17:13:33 -0700192extern int utimensat(int fd, const char *path, const struct timespec times[2], int flags);
193extern int futimens(int fd, const struct timespec times[2]);
Ken Sumrallae2d5ba2011-03-18 11:55:12 -0700194
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800195__END_DECLS
196
197#endif /* _SYS_STAT_H_ */