1 /*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 1982, 1986, 1989, 1993 5 * The Regents of the University of California. All rights reserved. 6 * (c) UNIX System Laboratories, Inc. 7 * All or some portions of this file are derived from material licensed 8 * to the University of California by American Telephone and Telegraph 9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 10 * the permission of UNIX System Laboratories, Inc. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * @(#)stat.h 8.12 (Berkeley) 6/16/95 37 */ 38 39 #ifndef _SYS_STAT_H_ 40 #define _SYS_STAT_H_ 41 42 #include <sys/cdefs.h> 43 #include <sys/_timespec.h> 44 #include <sys/_types.h> 45 46 #ifndef _BLKSIZE_T_DECLARED 47 typedef __blksize_t blksize_t; 48 #define _BLKSIZE_T_DECLARED 49 #endif 50 51 #ifndef _BLKCNT_T_DECLARED 52 typedef __blkcnt_t blkcnt_t; 53 #define _BLKCNT_T_DECLARED 54 #endif 55 56 #ifndef _DEV_T_DECLARED 57 typedef __dev_t dev_t; 58 #define _DEV_T_DECLARED 59 #endif 60 61 #ifndef _FFLAGS_T_DECLARED 62 typedef __fflags_t fflags_t; 63 #define _FFLAGS_T_DECLARED 64 #endif 65 66 #ifndef _GID_T_DECLARED 67 typedef __gid_t gid_t; 68 #define _GID_T_DECLARED 69 #endif 70 71 #ifndef _INO_T_DECLARED 72 typedef __ino_t ino_t; 73 #define _INO_T_DECLARED 74 #endif 75 76 #ifndef _MODE_T_DECLARED 77 typedef __mode_t mode_t; 78 #define _MODE_T_DECLARED 79 #endif 80 81 #ifndef _NLINK_T_DECLARED 82 typedef __nlink_t nlink_t; 83 #define _NLINK_T_DECLARED 84 #endif 85 86 #ifndef _OFF_T_DECLARED 87 typedef __off_t off_t; 88 #define _OFF_T_DECLARED 89 #endif 90 91 #ifndef _UID_T_DECLARED 92 typedef __uid_t uid_t; 93 #define _UID_T_DECLARED 94 #endif 95 96 #if !defined(_KERNEL) && __BSD_VISIBLE 97 /* 98 * XXX We get miscellaneous namespace pollution with this. 99 */ 100 #include <sys/time.h> 101 #endif 102 103 #ifdef _KERNEL 104 struct ostat { 105 __uint16_t st_dev; /* inode's device */ 106 __uint32_t st_ino; /* inode's number */ 107 mode_t st_mode; /* inode protection mode */ 108 __uint16_t st_nlink; /* number of hard links */ 109 __uint16_t st_uid; /* user ID of the file's owner */ 110 __uint16_t st_gid; /* group ID of the file's group */ 111 __uint16_t st_rdev; /* device type */ 112 __int32_t st_size; /* file size, in bytes */ 113 struct timespec st_atim; /* time of last access */ 114 struct timespec st_mtim; /* time of last data modification */ 115 struct timespec st_ctim; /* time of last file status change */ 116 __int32_t st_blksize; /* optimal blocksize for I/O */ 117 __int32_t st_blocks; /* blocks allocated for file */ 118 fflags_t st_flags; /* user defined flags for file */ 119 __uint32_t st_gen; /* file generation number */ 120 }; 121 #endif 122 123 #if defined(_WANT_FREEBSD11_STAT) || defined(_KERNEL) 124 struct freebsd11_stat { 125 __uint32_t st_dev; /* inode's device */ 126 __uint32_t st_ino; /* inode's number */ 127 mode_t st_mode; /* inode protection mode */ 128 __uint16_t st_nlink; /* number of hard links */ 129 uid_t st_uid; /* user ID of the file's owner */ 130 gid_t st_gid; /* group ID of the file's group */ 131 __uint32_t st_rdev; /* device type */ 132 struct timespec st_atim; /* time of last access */ 133 struct timespec st_mtim; /* time of last data modification */ 134 struct timespec st_ctim; /* time of last file status change */ 135 off_t st_size; /* file size, in bytes */ 136 blkcnt_t st_blocks; /* blocks allocated for file */ 137 blksize_t st_blksize; /* optimal blocksize for I/O */ 138 fflags_t st_flags; /* user defined flags for file */ 139 __uint32_t st_gen; /* file generation number */ 140 __int32_t st_lspare; 141 struct timespec st_birthtim; /* time of file creation */ 142 /* 143 * Explicitly pad st_birthtim to 16 bytes so that the size of 144 * struct stat is backwards compatible. We use bitfields instead 145 * of an array of chars so that this doesn't require a C99 compiler 146 * to compile if the size of the padding is 0. We use 2 bitfields 147 * to cover up to 64 bits on 32-bit machines. We assume that 148 * CHAR_BIT is 8... 149 */ 150 unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec)); 151 unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec)); 152 }; 153 #endif /* _WANT_FREEBSD11_STAT || _KERNEL */ 154 155 #if defined(__i386__) 156 #define __STAT_TIME_T_EXT 1 157 #endif 158 159 struct stat { 160 dev_t st_dev; /* inode's device */ 161 ino_t st_ino; /* inode's number */ 162 nlink_t st_nlink; /* number of hard links */ 163 mode_t st_mode; /* inode protection mode */ 164 __int16_t st_bsdflags; /* misc system flags */ 165 uid_t st_uid; /* user ID of the file's owner */ 166 gid_t st_gid; /* group ID of the file's group */ 167 __int32_t st_padding1; 168 dev_t st_rdev; /* device type */ 169 #ifdef __STAT_TIME_T_EXT 170 __int32_t st_atim_ext; 171 #endif 172 struct timespec st_atim; /* time of last access */ 173 #ifdef __STAT_TIME_T_EXT 174 __int32_t st_mtim_ext; 175 #endif 176 struct timespec st_mtim; /* time of last data modification */ 177 #ifdef __STAT_TIME_T_EXT 178 __int32_t st_ctim_ext; 179 #endif 180 struct timespec st_ctim; /* time of last file status change */ 181 #ifdef __STAT_TIME_T_EXT 182 __int32_t st_btim_ext; 183 #endif 184 struct timespec st_birthtim; /* time of file creation */ 185 off_t st_size; /* file size, in bytes */ 186 blkcnt_t st_blocks; /* blocks allocated for file */ 187 blksize_t st_blksize; /* optimal blocksize for I/O */ 188 fflags_t st_flags; /* user defined flags for file */ 189 __uint64_t st_gen; /* file generation number */ 190 __uint64_t st_filerev; /* file revision, incr on changes */ 191 __uint64_t st_spare[9]; 192 }; 193 194 #ifdef _KERNEL 195 struct nstat { 196 __uint32_t st_dev; /* inode's device */ 197 __uint32_t st_ino; /* inode's number */ 198 __uint32_t st_mode; /* inode protection mode */ 199 __uint32_t st_nlink; /* number of hard links */ 200 uid_t st_uid; /* user ID of the file's owner */ 201 gid_t st_gid; /* group ID of the file's group */ 202 __uint32_t st_rdev; /* device type */ 203 struct timespec st_atim; /* time of last access */ 204 struct timespec st_mtim; /* time of last data modification */ 205 struct timespec st_ctim; /* time of last file status change */ 206 off_t st_size; /* file size, in bytes */ 207 blkcnt_t st_blocks; /* blocks allocated for file */ 208 blksize_t st_blksize; /* optimal blocksize for I/O */ 209 fflags_t st_flags; /* user defined flags for file */ 210 __uint32_t st_gen; /* file generation number */ 211 struct timespec st_birthtim; /* time of file creation */ 212 /* 213 * See comment in the definition of struct freebsd11_stat 214 * above about the following padding. 215 */ 216 unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec)); 217 unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec)); 218 }; 219 #endif 220 221 #ifndef _KERNEL 222 #define st_atime st_atim.tv_sec 223 #define st_mtime st_mtim.tv_sec 224 #define st_ctime st_ctim.tv_sec 225 #if __BSD_VISIBLE 226 #define st_birthtime st_birthtim.tv_sec 227 #define st_atimensec st_atim.tv_nsec 228 #define st_mtimensec st_mtim.tv_nsec 229 #define st_ctimensec st_ctim.tv_nsec 230 #define st_birthtimensec st_birthtim.tv_nsec 231 #endif 232 233 /* For compatibility. */ 234 #if __BSD_VISIBLE 235 #define st_atimespec st_atim 236 #define st_mtimespec st_mtim 237 #define st_ctimespec st_ctim 238 #define st_birthtimespec st_birthtim 239 #endif 240 #endif /* !_KERNEL */ 241 242 #define S_ISUID 0004000 /* set user id on execution */ 243 #define S_ISGID 0002000 /* set group id on execution */ 244 #if __BSD_VISIBLE 245 #define S_ISTXT 0001000 /* sticky bit */ 246 #endif 247 248 #define S_IRWXU 0000700 /* RWX mask for owner */ 249 #define S_IRUSR 0000400 /* R for owner */ 250 #define S_IWUSR 0000200 /* W for owner */ 251 #define S_IXUSR 0000100 /* X for owner */ 252 253 #if __BSD_VISIBLE 254 #define S_IREAD S_IRUSR 255 #define S_IWRITE S_IWUSR 256 #define S_IEXEC S_IXUSR 257 #endif 258 259 #define S_IRWXG 0000070 /* RWX mask for group */ 260 #define S_IRGRP 0000040 /* R for group */ 261 #define S_IWGRP 0000020 /* W for group */ 262 #define S_IXGRP 0000010 /* X for group */ 263 264 #define S_IRWXO 0000007 /* RWX mask for other */ 265 #define S_IROTH 0000004 /* R for other */ 266 #define S_IWOTH 0000002 /* W for other */ 267 #define S_IXOTH 0000001 /* X for other */ 268 269 #if __XSI_VISIBLE 270 #define S_IFMT 0170000 /* type of file mask */ 271 #define S_IFIFO 0010000 /* named pipe (fifo) */ 272 #define S_IFCHR 0020000 /* character special */ 273 #define S_IFDIR 0040000 /* directory */ 274 #define S_IFBLK 0060000 /* block special */ 275 #define S_IFREG 0100000 /* regular */ 276 #define S_IFLNK 0120000 /* symbolic link */ 277 #define S_IFSOCK 0140000 /* socket */ 278 #define S_ISVTX 0001000 /* save swapped text even after use */ 279 #endif 280 #if __BSD_VISIBLE 281 #define S_IFWHT 0160000 /* whiteout */ 282 #endif 283 284 #define S_ISDIR(m) (((m) & 0170000) == 0040000) /* directory */ 285 #define S_ISCHR(m) (((m) & 0170000) == 0020000) /* char special */ 286 #define S_ISBLK(m) (((m) & 0170000) == 0060000) /* block special */ 287 #define S_ISREG(m) (((m) & 0170000) == 0100000) /* regular file */ 288 #define S_ISFIFO(m) (((m) & 0170000) == 0010000) /* fifo or socket */ 289 #if __POSIX_VISIBLE >= 200112 290 #define S_ISLNK(m) (((m) & 0170000) == 0120000) /* symbolic link */ 291 #define S_ISSOCK(m) (((m) & 0170000) == 0140000) /* socket */ 292 #endif 293 #if __BSD_VISIBLE 294 #define S_ISWHT(m) (((m) & 0170000) == 0160000) /* whiteout */ 295 #endif 296 297 #if __BSD_VISIBLE 298 #define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */ 299 /* 7777 */ 300 #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO) 301 /* 0666 */ 302 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) 303 304 #define S_BLKSIZE 512 /* block size used in the stat struct */ 305 306 /* 307 * Definitions of flags stored in file flags word. 308 * 309 * Super-user and owner changeable flags. 310 */ 311 #define UF_SETTABLE 0x0000ffff /* mask of owner changeable flags */ 312 #define UF_NODUMP 0x00000001 /* do not dump file */ 313 #define UF_IMMUTABLE 0x00000002 /* file may not be changed */ 314 #define UF_APPEND 0x00000004 /* writes to file may only append */ 315 #define UF_OPAQUE 0x00000008 /* directory is opaque wrt. union */ 316 #define UF_NOUNLINK 0x00000010 /* file may not be removed or renamed */ 317 /* 318 * These two bits are defined in MacOS X. They are not currently used in 319 * FreeBSD. 320 */ 321 #if 0 322 #define UF_COMPRESSED 0x00000020 /* file is compressed */ 323 #define UF_TRACKED 0x00000040 /* renames and deletes are tracked */ 324 #endif 325 326 #define UF_SYSTEM 0x00000080 /* Windows system file bit */ 327 #define UF_SPARSE 0x00000100 /* sparse file */ 328 #define UF_OFFLINE 0x00000200 /* file is offline */ 329 #define UF_REPARSE 0x00000400 /* Windows reparse point file bit */ 330 #define UF_ARCHIVE 0x00000800 /* file needs to be archived */ 331 #define UF_READONLY 0x00001000 /* Windows readonly file bit */ 332 /* This is the same as the MacOS X definition of UF_HIDDEN. */ 333 #define UF_HIDDEN 0x00008000 /* file is hidden */ 334 335 /* 336 * Super-user changeable flags. 337 */ 338 #define SF_SETTABLE 0xffff0000 /* mask of superuser changeable flags */ 339 #define SF_ARCHIVED 0x00010000 /* file is archived */ 340 #define SF_IMMUTABLE 0x00020000 /* file may not be changed */ 341 #define SF_APPEND 0x00040000 /* writes to file may only append */ 342 #define SF_NOUNLINK 0x00100000 /* file may not be removed or renamed */ 343 #define SF_SNAPSHOT 0x00200000 /* snapshot inode */ 344 345 /* st_bsdflags */ 346 #define SFBSD_NAMEDATTR 0x0001 /* file is named attribute or dir */ 347 348 #ifdef _KERNEL 349 /* 350 * Shorthand abbreviations of above. 351 */ 352 #define OPAQUE (UF_OPAQUE) 353 #define APPEND (UF_APPEND | SF_APPEND) 354 #define IMMUTABLE (UF_IMMUTABLE | SF_IMMUTABLE) 355 #define NOUNLINK (UF_NOUNLINK | SF_NOUNLINK) 356 #endif 357 358 #endif /* __BSD_VISIBLE */ 359 360 #if __POSIX_VISIBLE >= 200809 361 #define UTIME_NOW -1 362 #define UTIME_OMIT -2 363 #endif 364 365 #ifndef _KERNEL 366 __BEGIN_DECLS 367 #if __BSD_VISIBLE 368 int chflags(const char *, unsigned long); 369 int chflagsat(int, const char *, unsigned long, int); 370 #endif 371 int chmod(const char *, mode_t); 372 #if __BSD_VISIBLE 373 int fchflags(int, unsigned long); 374 #endif 375 #if __POSIX_VISIBLE >= 200112 376 int fchmod(int, mode_t); 377 #endif 378 #if __POSIX_VISIBLE >= 200809 379 int fchmodat(int, const char *, mode_t, int); 380 int futimens(int fd, const struct timespec times[2]); 381 int utimensat(int fd, const char *path, const struct timespec times[2], 382 int flag); 383 #endif 384 int fstat(int, struct stat *); 385 #if __BSD_VISIBLE 386 int lchflags(const char *, unsigned long); 387 int lchmod(const char *, mode_t); 388 #endif 389 #if __POSIX_VISIBLE >= 200112 390 int lstat(const char * __restrict, struct stat * __restrict); 391 #endif 392 int mkdir(const char *, mode_t); 393 int mkfifo(const char *, mode_t); 394 #if !defined(_MKNOD_DECLARED) && __XSI_VISIBLE 395 int mknod(const char *, mode_t, dev_t); 396 #define _MKNOD_DECLARED 397 #endif 398 int stat(const char * __restrict, struct stat * __restrict); 399 mode_t umask(mode_t); 400 #if __POSIX_VISIBLE >= 200809 401 int fstatat(int, const char *, struct stat *, int); 402 int mkdirat(int, const char *, mode_t); 403 int mkfifoat(int, const char *, mode_t); 404 #endif 405 #if __XSI_VISIBLE >= 700 406 int mknodat(int, const char *, mode_t, dev_t); 407 #endif 408 __END_DECLS 409 #endif /* !_KERNEL */ 410 411 #endif /* !_SYS_STAT_H_ */ 412