blob: 3d754c0581a130a9127439a315aeaf7dc991debb [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 */
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
Elliott Hughesb8fa5b12013-12-19 16:50:22 -080040#if defined(__aarch64__)
Raghu Gandham6437eac2012-08-02 16:50:10 -070041struct stat {
Elliott Hughesb8fa5b12013-12-19 16:50:22 -080042 unsigned long st_dev;
43 unsigned long st_ino;
44 unsigned int st_mode;
45 unsigned int st_nlink;
46 unsigned int st_uid;
47 unsigned int 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;
Raghu Gandham6437eac2012-08-02 16:50:10 -070062};
Elliott Hughesb8fa5b12013-12-19 16:50:22 -080063#elif defined(__mips__)
Pavel Chupinf68fac82012-12-18 17:25:01 +040064struct stat {
Elliott Hughesb8fa5b12013-12-19 16:50:22 -080065 unsigned long st_dev;
66 unsigned long __pad0[3];
67 unsigned long long st_ino;
68 unsigned int st_mode;
69 unsigned int st_nlink;
70 unsigned long st_uid;
71 unsigned long st_gid;
72 unsigned long st_rdev;
73 unsigned long __pad1[3];
74 long long st_size;
75 unsigned long st_atime;
76 unsigned long st_atime_nsec;
77 unsigned long st_mtime;
78 unsigned long st_mtime_nsec;
79 unsigned long st_ctime;
80 unsigned long st_ctime_nsec;
81 unsigned long st_blksize;
82 unsigned long __pad2;
83 unsigned long long st_blocks;
Pavel Chupinf68fac82012-12-18 17:25:01 +040084};
Elliott Hughesb8fa5b12013-12-19 16:50:22 -080085#elif defined(__x86_64__)
86struct stat {
87 unsigned long st_dev;
88 unsigned long st_ino;
89 unsigned long st_nlink;
90 unsigned int st_mode;
91 unsigned int st_uid;
92 unsigned int 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};
Raghu Gandham6437eac2012-08-02 16:50:10 -0700106#else
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800107struct stat {
Elliott Hughesb8fa5b12013-12-19 16:50:22 -0800108 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 unsigned long st_uid;
114 unsigned long 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;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800127};
Raghu Gandham6437eac2012-08-02 16:50:10 -0700128#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800129
David 'Digit' Turner09baf4e2009-06-22 12:16:06 +0200130/* For compatibility with GLibc, we provide macro aliases
131 * for the non-Posix nano-seconds accessors.
132 */
133#define st_atimensec st_atime_nsec
134#define st_mtimensec st_mtime_nsec
135#define st_ctimensec st_ctime_nsec
136
Hakan Kvistf27b7fb2012-10-10 08:32:52 +0200137#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
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800144extern int chmod(const char *, mode_t);
145extern int fchmod(int, mode_t);
146extern int mkdir(const char *, mode_t);
147
148extern int stat(const char *, struct stat *);
149extern int fstat(int, struct stat *);
150extern int lstat(const char *, struct stat *);
151extern int mknod(const char *, mode_t, dev_t);
152extern mode_t umask(mode_t);
153
Nick Kralevicha6cde392013-06-29 08:15:25 -0700154#if defined(__BIONIC_FORTIFY)
Nick Kralevichcd587702012-09-26 10:02:30 -0700155
156extern mode_t __umask_chk(mode_t);
157extern mode_t __umask_real(mode_t)
158 __asm__(__USER_LABEL_PREFIX__ "umask");
Nick Kralevicha641c182013-06-18 13:07:18 -0700159__errordecl(__umask_invalid_mode, "umask called with invalid mode");
Nick Kralevichcd587702012-09-26 10:02:30 -0700160
161__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
175
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800176#define stat64 stat
177#define fstat64 fstat
178#define lstat64 lstat
179
Elliott Hughes594b1a42013-10-22 10:54:11 -0700180extern int mkfifo(const char*, mode_t);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800181
Elliott Hughesf8fcfbc2013-10-22 13:28:46 -0700182extern int fchmodat(int, const char*, mode_t, int);
183extern int fstatat(int, const char*, struct stat*, int);
184extern int mkdirat(int, const char*, mode_t);
185extern int mknodat(int, const char*, mode_t, dev_t);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800186
Ken Sumrallae2d5ba2011-03-18 11:55:12 -0700187# define UTIME_NOW ((1l << 30) - 1l)
188# define UTIME_OMIT ((1l << 30) - 2l)
Elliott Hughesd0be7c82013-08-08 17:13:33 -0700189extern int utimensat(int fd, const char *path, const struct timespec times[2], int flags);
190extern int futimens(int fd, const struct timespec times[2]);
Ken Sumrallae2d5ba2011-03-18 11:55:12 -0700191
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800192__END_DECLS
193
194#endif /* _SYS_STAT_H_ */