blob: a6c73b7d98b663c0b1f368a208e816e68b831114 [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
Elliott Hughes5ac438e2020-02-13 15:56:31 -080039#if defined(__aarch64__)
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
Elliott Hughesb8fa5b12013-12-19 16:50:22 -080059#elif defined(__x86_64__)
Elliott Hughesdb1ea342014-01-17 18:42:49 -080060#define __STAT64_BODY \
Elliott Hughes1c52e6c2014-12-18 12:38:44 -080061 dev_t st_dev; \
62 ino_t st_ino; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080063 unsigned long st_nlink; \
Elliott Hughes1c52e6c2014-12-18 12:38:44 -080064 mode_t st_mode; \
Elliott Hughes6b555932014-02-18 16:43:31 -080065 uid_t st_uid; \
66 gid_t st_gid; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080067 unsigned int __pad0; \
Elliott Hughes1c52e6c2014-12-18 12:38:44 -080068 dev_t st_rdev; \
69 off_t st_size; \
Elliott Hughesdb1ea342014-01-17 18:42:49 -080070 long st_blksize; \
71 long st_blocks; \
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 long __pad3[3]; \
76
Elliott Hughes9257c472014-12-18 15:17:42 -080077#else /* __arm__ || __i386__ */
Elliott Hughesdb1ea342014-01-17 18:42:49 -080078#define __STAT64_BODY \
79 unsigned long long st_dev; \
80 unsigned char __pad0[4]; \
81 unsigned long __st_ino; \
82 unsigned int st_mode; \
Elliott Hughes9257c472014-12-18 15:17:42 -080083 nlink_t st_nlink; \
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 long long st_rdev; \
87 unsigned char __pad3[4]; \
88 long long st_size; \
89 unsigned long st_blksize; \
90 unsigned long 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 unsigned long long st_ino; \
95
Raghu Gandham6437eac2012-08-02 16:50:10 -070096#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080097
Elliott Hughesdb1ea342014-01-17 18:42:49 -080098struct stat { __STAT64_BODY };
99struct stat64 { __STAT64_BODY };
100
Calin Juravlef963da22014-05-13 11:01:11 +0100101#undef __STAT64_BODY
102
Elliott Hughes0ac0df82014-11-07 19:15:10 -0800103/* Compatibility with older versions of POSIX. */
104#define st_atime st_atim.tv_sec
105#define st_mtime st_mtim.tv_sec
106#define st_ctime st_ctim.tv_sec
107/* Compatibility with glibc. */
108#define st_atimensec st_atim.tv_nsec
109#define st_mtimensec st_mtim.tv_nsec
110#define st_ctimensec st_ctim.tv_nsec
Dan Alberta4e774c2017-06-12 14:59:38 -0700111/* Compatibility with Linux headers and old NDKs. */
112#define st_atime_nsec st_atim.tv_nsec
113#define st_mtime_nsec st_mtim.tv_nsec
114#define st_ctime_nsec st_ctim.tv_nsec
David 'Digit' Turner09baf4e2009-06-22 12:16:06 +0200115
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700116#if defined(__USE_BSD)
Hakan Kvistf27b7fb2012-10-10 08:32:52 +0200117/* Permission macros provided by glibc for compatibility with BSDs. */
118#define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */
119#define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */
120#define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */
121#endif
122
Elliott Hughes1f1a51a2016-03-31 17:05:30 -0700123#if defined(__USE_BSD) || defined(__USE_GNU)
124#define S_IREAD S_IRUSR
125#define S_IWRITE S_IWUSR
126#define S_IEXEC S_IXUSR
127#endif
128
Elliott Hughes92887612016-08-16 13:26:35 -0700129/* POSIX mandates these, but Linux doesn't implement them as distinct file types. */
130#define S_TYPEISMQ(__sb) 0
131#define S_TYPEISSEM(__sb) 0
132#define S_TYPEISSHM(__sb) 0
133#define S_TYPEISTMO(__sb) 0
134
Elliott Hughesff26a162017-08-17 22:34:21 +0000135int chmod(const char* __path, mode_t __mode);
136int fchmod(int __fd, mode_t __mode);
137int mkdir(const char* __path, mode_t __mode);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800138
Elliott Hughesff26a162017-08-17 22:34:21 +0000139int fstat(int __fd, struct stat* __buf);
Elliott Hughes25f17e42018-02-12 15:48:01 -0800140int fstat64(int __fd, struct stat64* __buf) __RENAME_STAT64(fstat, 3, 21);
Elliott Hughesff26a162017-08-17 22:34:21 +0000141int fstatat(int __dir_fd, const char* __path, struct stat* __buf, int __flags);
Elliott Hughes25f17e42018-02-12 15:48:01 -0800142int fstatat64(int __dir_fd, const char* __path, struct stat64* __buf, int __flags) __RENAME_STAT64(fstatat, 3, 21);
Elliott Hughesff26a162017-08-17 22:34:21 +0000143int lstat(const char* __path, struct stat* __buf);
Elliott Hughes25f17e42018-02-12 15:48:01 -0800144int lstat64(const char* __path, struct stat64* __buf) __RENAME_STAT64(lstat, 3, 21);
Elliott Hughesff26a162017-08-17 22:34:21 +0000145int stat(const char* __path, struct stat* __buf);
Elliott Hughes25f17e42018-02-12 15:48:01 -0800146int stat64(const char* __path, struct stat64* __buf) __RENAME_STAT64(stat, 3, 21);
Elliott Hughesdb1ea342014-01-17 18:42:49 -0800147
Elliott Hughesff26a162017-08-17 22:34:21 +0000148int mknod(const char* __path, mode_t __mode, dev_t __dev);
George Burgess IV90242352018-02-06 12:51:31 -0800149mode_t umask(mode_t __mask);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800150
George Burgess IVb97049c2017-07-24 15:05:05 -0700151#if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS)
152#include <bits/fortify/stat.h>
153#endif
Nick Kralevichcd587702012-09-26 10:02:30 -0700154
Elliott Hughes95c6cd72019-12-20 13:26:14 -0800155#if __ANDROID_API__ >= 21
Elliott Hughesff26a162017-08-17 22:34:21 +0000156int mkfifo(const char* __path, mode_t __mode) __INTRODUCED_IN(21);
Josh Gao8778d642016-07-22 15:26:36 -0700157#else
158// Implemented as a static inline before 21.
159#endif
160
Elliott Hughesff26a162017-08-17 22:34:21 +0000161int mkfifoat(int __dir_fd, const char* __path, mode_t __mode) __INTRODUCED_IN(23);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800162
Elliott Hughesff26a162017-08-17 22:34:21 +0000163int fchmodat(int __dir_fd, const char* __path, mode_t __mode, int __flags);
164int mkdirat(int __dir_fd, const char* __path, mode_t __mode);
165int mknodat(int __dir_fd, const char* __path, mode_t __mode, dev_t __dev) __INTRODUCED_IN(21);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800166
Elliott Hughesdb1ea342014-01-17 18:42:49 -0800167#define UTIME_NOW ((1L << 30) - 1L)
168#define UTIME_OMIT ((1L << 30) - 2L)
Elliott Hughesf106a392019-10-03 16:09:04 -0700169int utimensat(int __dir_fd, const char* __path, const struct timespec __times[2], int __flags);
Elliott Hughesff26a162017-08-17 22:34:21 +0000170int futimens(int __dir_fd, const struct timespec __times[2]) __INTRODUCED_IN(19);
Ken Sumrallae2d5ba2011-03-18 11:55:12 -0700171
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800172__END_DECLS
173
Josh Gaob8e1b7052016-04-13 17:18:20 -0700174#include <android/legacy_sys_stat_inlines.h>
175
Elliott Hughesff26a162017-08-17 22:34:21 +0000176#endif