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 */ 28 29 #pragma once 30 31 /** 32 * @file sys/stat.h 33 * @brief File status. 34 */ 35 36 #include <bits/timespec.h> 37 #include <linux/stat.h> 38 #include <sys/cdefs.h> 39 #include <sys/types.h> 40 41 __BEGIN_DECLS 42 43 #if defined(__aarch64__) || defined(__riscv) 44 #define __STAT64_BODY \ 45 dev_t st_dev; \ 46 ino_t st_ino; \ 47 mode_t st_mode; \ 48 nlink_t st_nlink; \ 49 uid_t st_uid; \ 50 gid_t st_gid; \ 51 dev_t st_rdev; \ 52 unsigned long __pad1; \ 53 off_t st_size; \ 54 int st_blksize; \ 55 int __pad2; \ 56 long st_blocks; \ 57 struct timespec st_atim; \ 58 struct timespec st_mtim; \ 59 struct timespec st_ctim; \ 60 unsigned int __unused4; \ 61 unsigned int __unused5; \ 62 63 #elif defined(__x86_64__) 64 #define __STAT64_BODY \ 65 dev_t st_dev; \ 66 ino_t st_ino; \ 67 unsigned long st_nlink; \ 68 mode_t st_mode; \ 69 uid_t st_uid; \ 70 gid_t st_gid; \ 71 unsigned int __pad0; \ 72 dev_t st_rdev; \ 73 off_t st_size; \ 74 long st_blksize; \ 75 long st_blocks; \ 76 struct timespec st_atim; \ 77 struct timespec st_mtim; \ 78 struct timespec st_ctim; \ 79 long __pad3[3]; \ 80 81 #else /* __arm__ || __i386__ */ 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; \ 87 nlink_t st_nlink; \ 88 uid_t st_uid; \ 89 gid_t st_gid; \ 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; \ 95 struct timespec st_atim; \ 96 struct timespec st_mtim; \ 97 struct timespec st_ctim; \ 98 unsigned long long st_ino; \ 99 100 #endif 101 102 struct stat { __STAT64_BODY }; 103 struct stat64 { __STAT64_BODY }; 104 105 #undef __STAT64_BODY 106 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 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 119 120 #if defined(__USE_BSD) 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 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 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 139 int chmod(const char* _Nonnull __path, mode_t __mode); 140 int fchmod(int __fd, mode_t __mode); 141 int mkdir(const char* _Nonnull __path, mode_t __mode); 142 143 int fstat(int __fd, struct stat* _Nonnull __buf); 144 int fstat64(int __fd, struct stat64* _Nonnull __buf); 145 int fstatat(int __dir_fd, const char* _Nonnull __path, struct stat* _Nonnull __buf, int __flags); 146 int fstatat64(int __dir_fd, const char* _Nonnull __path, struct stat64* _Nonnull __buf, int __flags); 147 int lstat(const char* _Nonnull __path, struct stat* _Nonnull __buf); 148 int lstat64(const char* _Nonnull __path, struct stat64* _Nonnull __buf); 149 int stat(const char* _Nonnull __path, struct stat* _Nonnull __buf); 150 int stat64(const char* _Nonnull __path, struct stat64* _Nonnull __buf); 151 152 int mknod(const char* _Nonnull __path, mode_t __mode, dev_t __dev); 153 mode_t umask(mode_t __mask); 154 155 #if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS) 156 #include <bits/fortify/stat.h> 157 #endif 158 159 int mkfifo(const char* _Nonnull __path, mode_t __mode); 160 int mkfifoat(int __dir_fd, const char* _Nonnull __path, mode_t __mode) __INTRODUCED_IN(23); 161 162 int fchmodat(int __dir_fd, const char* _Nonnull __path, mode_t __mode, int __flags); 163 int mkdirat(int __dir_fd, const char* _Nonnull __path, mode_t __mode); 164 int mknodat(int __dir_fd, const char* _Nonnull __path, mode_t __mode, dev_t __dev); 165 166 /** 167 * Used in the tv_nsec field of an argument to utimensat()/futimens() 168 * to set that time to the current time. 169 */ 170 #define UTIME_NOW ((1L << 30) - 1L) 171 172 /** 173 * Used in the tv_nsec field of an argument to utimensat()/futimens() 174 * to _not_ set that time. 175 */ 176 #define UTIME_OMIT ((1L << 30) - 2L) 177 178 /** 179 * [utimensat(2)](https://man7.org/linux/man-pages/man2/utimensat.2.html) sets 180 * file timestamps. 181 * 182 * Note: Linux supports `__path` being NULL (in which case `__dir_fd` need not 183 * be a directory), allowing futimens() to be implemented with utimensat(). 184 * For normal use of utimensat(), though, `__path` should be non-null. 185 * 186 * `__times[0]` is the access time (atime), and `__times[1]` the last modification time (mtime). 187 * If `__times` is NULL, both times are set to the current time. 188 * See also UTIME_NOW and UTIME_OMIT. 189 * 190 * Returns 0 on success and returns -1 and sets `errno` on failure. 191 */ 192 int utimensat(int __dir_fd, const char* __BIONIC_COMPLICATED_NULLNESS __path, const struct timespec __times[_Nullable 2], int __flags); 193 194 /** 195 * [futimens(2)](https://man7.org/linux/man-pages/man2/utimensat.2.html) sets 196 * the given file descriptor's timestamp. 197 * 198 * `__times[0]` is the access time (atime), and `__times[1]` the last modification time (mtime). 199 * If `__times` is NULL, both times are set to the current time. 200 * See also UTIME_NOW and UTIME_OMIT. 201 * 202 * Returns 0 on success and returns -1 and sets `errno` on failure. 203 */ 204 int futimens(int __fd, const struct timespec __times[_Nullable 2]); 205 206 #if defined(__USE_GNU) 207 /** 208 * [statx(2)](http://man7.org/linux/man-pages/man2/statx.2.html) returns 209 * extended file status information. 210 * 211 * Returns 0 on success and returns -1 and sets `errno` on failure. 212 * 213 * Available since API level 30. 214 */ 215 int statx(int __dir_fd, const char* _Nonnull __path, int __flags, unsigned __mask, struct statx* _Nonnull __buf) __INTRODUCED_IN(30); 216 #endif 217 218 __END_DECLS 219