blob: ece44c64b317f9592014f9eb83545ec2b8148c7a [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
40/* really matches stat64 in the kernel, hence the padding
41 * Note: The kernel zero's the padded region because glibc might read them
42 * in the hope that the kernel has stretched to using larger sizes.
43 */
Raghu Gandham6437eac2012-08-02 16:50:10 -070044#ifdef __mips__
45struct stat {
46 unsigned long st_dev;
47 unsigned long __pad0[3];
48
49 unsigned long long st_ino;
50
51 unsigned int st_mode;
52 unsigned int st_nlink;
53
54 unsigned long st_uid;
55 unsigned long st_gid;
56
57 unsigned long st_rdev;
58 unsigned long __pad1[3];
59
60 long long st_size;
61
62 unsigned long st_atime;
63 unsigned long st_atime_nsec;
64
65 unsigned long st_mtime;
66 unsigned long st_mtime_nsec;
67
68 unsigned long st_ctime;
69 unsigned long st_ctime_nsec;
70
71 unsigned long st_blksize;
72 unsigned long __pad2;
73
74 unsigned long long st_blocks;
75};
Pavel Chupinf68fac82012-12-18 17:25:01 +040076
77#elif __x86_64__
78struct stat {
79 unsigned long st_dev;
80 unsigned long st_ino;
81 unsigned long st_nlink;
82 unsigned int st_mode;
83 unsigned int st_uid;
84 unsigned int st_gid;
85 unsigned int __pad0;
86 unsigned long st_rdev;
87 long st_size;
88 long st_blksize;
89 long st_blocks;
90 unsigned long st_atime;
91 unsigned long st_atime_nsec;
92 unsigned long st_mtime;
93 unsigned long st_mtime_nsec;
94 unsigned long st_ctime;
95 unsigned long st_ctime_nsec;
96 long __pad3[3];
97};
98
Raghu Gandham6437eac2012-08-02 16:50:10 -070099#else
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800100struct stat {
101 unsigned long long st_dev;
102 unsigned char __pad0[4];
103
104 unsigned long __st_ino;
105 unsigned int st_mode;
106 unsigned int st_nlink;
107
108 unsigned long st_uid;
109 unsigned long st_gid;
110
111 unsigned long long st_rdev;
112 unsigned char __pad3[4];
113
114 long long st_size;
115 unsigned long st_blksize;
116 unsigned long long st_blocks;
117
118 unsigned long st_atime;
119 unsigned long st_atime_nsec;
120
121 unsigned long st_mtime;
122 unsigned long st_mtime_nsec;
123
124 unsigned long st_ctime;
125 unsigned long st_ctime_nsec;
126
127 unsigned long long st_ino;
128};
Raghu Gandham6437eac2012-08-02 16:50:10 -0700129#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800130
David 'Digit' Turner09baf4e2009-06-22 12:16:06 +0200131/* For compatibility with GLibc, we provide macro aliases
132 * for the non-Posix nano-seconds accessors.
133 */
134#define st_atimensec st_atime_nsec
135#define st_mtimensec st_mtime_nsec
136#define st_ctimensec st_ctime_nsec
137
Hakan Kvistf27b7fb2012-10-10 08:32:52 +0200138#ifdef __USE_BSD
139/* Permission macros provided by glibc for compatibility with BSDs. */
140#define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */
141#define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */
142#define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */
143#endif
144
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800145extern int chmod(const char *, mode_t);
146extern int fchmod(int, mode_t);
147extern int mkdir(const char *, mode_t);
148
149extern int stat(const char *, struct stat *);
150extern int fstat(int, struct stat *);
151extern int lstat(const char *, struct stat *);
152extern int mknod(const char *, mode_t, dev_t);
153extern mode_t umask(mode_t);
154
Nick Kralevicha6cde392013-06-29 08:15:25 -0700155#if defined(__BIONIC_FORTIFY)
Nick Kralevichcd587702012-09-26 10:02:30 -0700156
157extern mode_t __umask_chk(mode_t);
158extern mode_t __umask_real(mode_t)
159 __asm__(__USER_LABEL_PREFIX__ "umask");
Nick Kralevicha641c182013-06-18 13:07:18 -0700160__errordecl(__umask_invalid_mode, "umask called with invalid mode");
Nick Kralevichcd587702012-09-26 10:02:30 -0700161
162__BIONIC_FORTIFY_INLINE
163mode_t umask(mode_t mode) {
Nick Kralevicha6cde392013-06-29 08:15:25 -0700164#if !defined(__clang__)
Nick Kralevichcd587702012-09-26 10:02:30 -0700165 if (__builtin_constant_p(mode)) {
166 if ((mode & 0777) != mode) {
Nick Kralevicha641c182013-06-18 13:07:18 -0700167 __umask_invalid_mode();
Nick Kralevichcd587702012-09-26 10:02:30 -0700168 }
169 return __umask_real(mode);
170 }
Nick Kralevicha6cde392013-06-29 08:15:25 -0700171#endif
Nick Kralevichcd587702012-09-26 10:02:30 -0700172 return __umask_chk(mode);
173}
Nick Kralevicha6cde392013-06-29 08:15:25 -0700174#endif /* defined(__BIONIC_FORTIFY) */
Nick Kralevichcd587702012-09-26 10:02:30 -0700175
176
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800177#define stat64 stat
178#define fstat64 fstat
179#define lstat64 lstat
180
Elliott Hughes594b1a42013-10-22 10:54:11 -0700181extern int mkfifo(const char*, mode_t);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800182
Elliott Hughesf8fcfbc2013-10-22 13:28:46 -0700183extern int fchmodat(int, const char*, mode_t, int);
184extern int fstatat(int, const char*, struct stat*, int);
185extern int mkdirat(int, const char*, mode_t);
186extern int mknodat(int, const char*, mode_t, dev_t);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800187
Ken Sumrallae2d5ba2011-03-18 11:55:12 -0700188# define UTIME_NOW ((1l << 30) - 1l)
189# define UTIME_OMIT ((1l << 30) - 2l)
Elliott Hughesd0be7c82013-08-08 17:13:33 -0700190extern int utimensat(int fd, const char *path, const struct timespec times[2], int flags);
191extern int futimens(int fd, const struct timespec times[2]);
Ken Sumrallae2d5ba2011-03-18 11:55:12 -0700192
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800193__END_DECLS
194
195#endif /* _SYS_STAT_H_ */