The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /* |
| 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 Hughes | b810462 | 2014-08-19 09:18:03 -0700 | [diff] [blame] | 28 | |
Elliott Hughes | 733cedd | 2020-02-21 23:21:28 -0800 | [diff] [blame] | 29 | #pragma once |
| 30 | |
| 31 | /** |
| 32 | * @file sys/stat.h |
| 33 | * @brief File status. |
| 34 | */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 35 | |
Elliott Hughes | 5704c42 | 2016-01-25 18:06:24 -0800 | [diff] [blame] | 36 | #include <bits/timespec.h> |
Yabin Cui | db49903 | 2014-12-09 20:15:48 -0800 | [diff] [blame] | 37 | #include <linux/stat.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 38 | #include <sys/cdefs.h> |
| 39 | #include <sys/types.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 40 | |
| 41 | __BEGIN_DECLS |
| 42 | |
Elliott Hughes | 5cc8a46 | 2022-10-06 00:26:18 +0000 | [diff] [blame^] | 43 | #if defined(__aarch64__) || defined(__riscv) |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 44 | #define __STAT64_BODY \ |
Elliott Hughes | 9257c47 | 2014-12-18 15:17:42 -0800 | [diff] [blame] | 45 | dev_t st_dev; \ |
| 46 | ino_t st_ino; \ |
| 47 | mode_t st_mode; \ |
| 48 | nlink_t st_nlink; \ |
Elliott Hughes | 6b55593 | 2014-02-18 16:43:31 -0800 | [diff] [blame] | 49 | uid_t st_uid; \ |
| 50 | gid_t st_gid; \ |
Elliott Hughes | 9257c47 | 2014-12-18 15:17:42 -0800 | [diff] [blame] | 51 | dev_t st_rdev; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 52 | unsigned long __pad1; \ |
Elliott Hughes | 9257c47 | 2014-12-18 15:17:42 -0800 | [diff] [blame] | 53 | off_t st_size; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 54 | int st_blksize; \ |
| 55 | int __pad2; \ |
| 56 | long st_blocks; \ |
Elliott Hughes | 0ac0df8 | 2014-11-07 19:15:10 -0800 | [diff] [blame] | 57 | struct timespec st_atim; \ |
| 58 | struct timespec st_mtim; \ |
| 59 | struct timespec st_ctim; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 60 | unsigned int __unused4; \ |
| 61 | unsigned int __unused5; \ |
| 62 | |
Elliott Hughes | b8fa5b1 | 2013-12-19 16:50:22 -0800 | [diff] [blame] | 63 | #elif defined(__x86_64__) |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 64 | #define __STAT64_BODY \ |
Elliott Hughes | 1c52e6c | 2014-12-18 12:38:44 -0800 | [diff] [blame] | 65 | dev_t st_dev; \ |
| 66 | ino_t st_ino; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 67 | unsigned long st_nlink; \ |
Elliott Hughes | 1c52e6c | 2014-12-18 12:38:44 -0800 | [diff] [blame] | 68 | mode_t st_mode; \ |
Elliott Hughes | 6b55593 | 2014-02-18 16:43:31 -0800 | [diff] [blame] | 69 | uid_t st_uid; \ |
| 70 | gid_t st_gid; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 71 | unsigned int __pad0; \ |
Elliott Hughes | 1c52e6c | 2014-12-18 12:38:44 -0800 | [diff] [blame] | 72 | dev_t st_rdev; \ |
| 73 | off_t st_size; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 74 | long st_blksize; \ |
| 75 | long st_blocks; \ |
Elliott Hughes | 0ac0df8 | 2014-11-07 19:15:10 -0800 | [diff] [blame] | 76 | struct timespec st_atim; \ |
| 77 | struct timespec st_mtim; \ |
| 78 | struct timespec st_ctim; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 79 | long __pad3[3]; \ |
| 80 | |
Elliott Hughes | 9257c47 | 2014-12-18 15:17:42 -0800 | [diff] [blame] | 81 | #else /* __arm__ || __i386__ */ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 82 | #define __STAT64_BODY \ |
| 83 | unsigned long long st_dev; \ |
| 84 | unsigned char __pad0[4]; \ |
| 85 | unsigned long __st_ino; \ |
| 86 | unsigned int st_mode; \ |
Elliott Hughes | 9257c47 | 2014-12-18 15:17:42 -0800 | [diff] [blame] | 87 | nlink_t st_nlink; \ |
Elliott Hughes | 6b55593 | 2014-02-18 16:43:31 -0800 | [diff] [blame] | 88 | uid_t st_uid; \ |
| 89 | gid_t st_gid; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 90 | unsigned long long st_rdev; \ |
| 91 | unsigned char __pad3[4]; \ |
| 92 | long long st_size; \ |
| 93 | unsigned long st_blksize; \ |
| 94 | unsigned long long st_blocks; \ |
Elliott Hughes | 0ac0df8 | 2014-11-07 19:15:10 -0800 | [diff] [blame] | 95 | struct timespec st_atim; \ |
| 96 | struct timespec st_mtim; \ |
| 97 | struct timespec st_ctim; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 98 | unsigned long long st_ino; \ |
| 99 | |
Raghu Gandham | 6437eac | 2012-08-02 16:50:10 -0700 | [diff] [blame] | 100 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 101 | |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 102 | struct stat { __STAT64_BODY }; |
| 103 | struct stat64 { __STAT64_BODY }; |
| 104 | |
Calin Juravle | f963da2 | 2014-05-13 11:01:11 +0100 | [diff] [blame] | 105 | #undef __STAT64_BODY |
| 106 | |
Elliott Hughes | 0ac0df8 | 2014-11-07 19:15:10 -0800 | [diff] [blame] | 107 | /* Compatibility with older versions of POSIX. */ |
| 108 | #define st_atime st_atim.tv_sec |
| 109 | #define st_mtime st_mtim.tv_sec |
| 110 | #define st_ctime st_ctim.tv_sec |
| 111 | /* Compatibility with glibc. */ |
| 112 | #define st_atimensec st_atim.tv_nsec |
| 113 | #define st_mtimensec st_mtim.tv_nsec |
| 114 | #define st_ctimensec st_ctim.tv_nsec |
Dan Albert | a4e774c | 2017-06-12 14:59:38 -0700 | [diff] [blame] | 115 | /* Compatibility with Linux headers and old NDKs. */ |
| 116 | #define st_atime_nsec st_atim.tv_nsec |
| 117 | #define st_mtime_nsec st_mtim.tv_nsec |
| 118 | #define st_ctime_nsec st_ctim.tv_nsec |
David 'Digit' Turner | 09baf4e | 2009-06-22 12:16:06 +0200 | [diff] [blame] | 119 | |
Elliott Hughes | 3ba55f8 | 2016-06-08 18:11:23 -0700 | [diff] [blame] | 120 | #if defined(__USE_BSD) |
Hakan Kvist | f27b7fb | 2012-10-10 08:32:52 +0200 | [diff] [blame] | 121 | /* Permission macros provided by glibc for compatibility with BSDs. */ |
| 122 | #define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */ |
| 123 | #define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */ |
| 124 | #define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */ |
| 125 | #endif |
| 126 | |
Elliott Hughes | 1f1a51a | 2016-03-31 17:05:30 -0700 | [diff] [blame] | 127 | #if defined(__USE_BSD) || defined(__USE_GNU) |
| 128 | #define S_IREAD S_IRUSR |
| 129 | #define S_IWRITE S_IWUSR |
| 130 | #define S_IEXEC S_IXUSR |
| 131 | #endif |
| 132 | |
Elliott Hughes | 9288761 | 2016-08-16 13:26:35 -0700 | [diff] [blame] | 133 | /* POSIX mandates these, but Linux doesn't implement them as distinct file types. */ |
| 134 | #define S_TYPEISMQ(__sb) 0 |
| 135 | #define S_TYPEISSEM(__sb) 0 |
| 136 | #define S_TYPEISSHM(__sb) 0 |
| 137 | #define S_TYPEISTMO(__sb) 0 |
| 138 | |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 139 | int chmod(const char* __path, mode_t __mode); |
| 140 | int fchmod(int __fd, mode_t __mode); |
| 141 | int mkdir(const char* __path, mode_t __mode); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 142 | |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 143 | int fstat(int __fd, struct stat* __buf); |
Elliott Hughes | 25f17e4 | 2018-02-12 15:48:01 -0800 | [diff] [blame] | 144 | int fstat64(int __fd, struct stat64* __buf) __RENAME_STAT64(fstat, 3, 21); |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 145 | int fstatat(int __dir_fd, const char* __path, struct stat* __buf, int __flags); |
Elliott Hughes | 25f17e4 | 2018-02-12 15:48:01 -0800 | [diff] [blame] | 146 | int fstatat64(int __dir_fd, const char* __path, struct stat64* __buf, int __flags) __RENAME_STAT64(fstatat, 3, 21); |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 147 | int lstat(const char* __path, struct stat* __buf); |
Elliott Hughes | 25f17e4 | 2018-02-12 15:48:01 -0800 | [diff] [blame] | 148 | int lstat64(const char* __path, struct stat64* __buf) __RENAME_STAT64(lstat, 3, 21); |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 149 | int stat(const char* __path, struct stat* __buf); |
Elliott Hughes | 25f17e4 | 2018-02-12 15:48:01 -0800 | [diff] [blame] | 150 | int stat64(const char* __path, struct stat64* __buf) __RENAME_STAT64(stat, 3, 21); |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 151 | |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 152 | int mknod(const char* __path, mode_t __mode, dev_t __dev); |
George Burgess IV | 9024235 | 2018-02-06 12:51:31 -0800 | [diff] [blame] | 153 | mode_t umask(mode_t __mask); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 154 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 155 | #if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS) |
| 156 | #include <bits/fortify/stat.h> |
| 157 | #endif |
Nick Kralevich | cd58770 | 2012-09-26 10:02:30 -0700 | [diff] [blame] | 158 | |
Elliott Hughes | 95c6cd7 | 2019-12-20 13:26:14 -0800 | [diff] [blame] | 159 | #if __ANDROID_API__ >= 21 |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 160 | int mkfifo(const char* __path, mode_t __mode) __INTRODUCED_IN(21); |
Josh Gao | 8778d64 | 2016-07-22 15:26:36 -0700 | [diff] [blame] | 161 | #else |
| 162 | // Implemented as a static inline before 21. |
| 163 | #endif |
| 164 | |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 165 | int mkfifoat(int __dir_fd, const char* __path, mode_t __mode) __INTRODUCED_IN(23); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 166 | |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 167 | int fchmodat(int __dir_fd, const char* __path, mode_t __mode, int __flags); |
| 168 | int mkdirat(int __dir_fd, const char* __path, mode_t __mode); |
| 169 | int mknodat(int __dir_fd, const char* __path, mode_t __mode, dev_t __dev) __INTRODUCED_IN(21); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 170 | |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 171 | #define UTIME_NOW ((1L << 30) - 1L) |
| 172 | #define UTIME_OMIT ((1L << 30) - 2L) |
Elliott Hughes | f106a39 | 2019-10-03 16:09:04 -0700 | [diff] [blame] | 173 | int utimensat(int __dir_fd, const char* __path, const struct timespec __times[2], int __flags); |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 174 | int futimens(int __dir_fd, const struct timespec __times[2]) __INTRODUCED_IN(19); |
Ken Sumrall | ae2d5ba | 2011-03-18 11:55:12 -0700 | [diff] [blame] | 175 | |
Elliott Hughes | 733cedd | 2020-02-21 23:21:28 -0800 | [diff] [blame] | 176 | #if defined(__USE_GNU) |
| 177 | /** |
| 178 | * [statx(2)](http://man7.org/linux/man-pages/man2/statx.2.html) returns |
| 179 | * extended file status information. |
| 180 | * |
| 181 | * Returns 0 on success and returns -1 and sets `errno` on failure. |
| 182 | */ |
| 183 | int statx(int __dir_fd, const char* __path, int __flags, unsigned __mask, struct statx* __buf) __INTRODUCED_IN(30); |
| 184 | #endif |
| 185 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 186 | __END_DECLS |
| 187 | |
Josh Gao | b8e1b705 | 2016-04-13 17:18:20 -0700 | [diff] [blame] | 188 | #include <android/legacy_sys_stat_inlines.h> |