11541Srgrimes/*- 21541Srgrimes * Copyright (c) 1982, 1986, 1989, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * (c) UNIX System Laboratories, Inc. 51541Srgrimes * All or some portions of this file are derived from material licensed 61541Srgrimes * to the University of California by American Telephone and Telegraph 71541Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with 81541Srgrimes * the permission of UNIX System Laboratories, Inc. 91541Srgrimes * 101541Srgrimes * Redistribution and use in source and binary forms, with or without 111541Srgrimes * modification, are permitted provided that the following conditions 121541Srgrimes * are met: 131541Srgrimes * 1. Redistributions of source code must retain the above copyright 141541Srgrimes * notice, this list of conditions and the following disclaimer. 151541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 161541Srgrimes * notice, this list of conditions and the following disclaimer in the 171541Srgrimes * documentation and/or other materials provided with the distribution. 181541Srgrimes * 4. Neither the name of the University nor the names of its contributors 191541Srgrimes * may be used to endorse or promote products derived from this software 201541Srgrimes * without specific prior written permission. 211541Srgrimes * 221541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 231541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 261541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321541Srgrimes * SUCH DAMAGE. 331541Srgrimes * 3414493Shsu * @(#)stat.h 8.12 (Berkeley) 6/16/95 3550477Speter * $FreeBSD$ 361541Srgrimes */ 371541Srgrimes 381541Srgrimes#ifndef _SYS_STAT_H_ 391541Srgrimes#define _SYS_STAT_H_ 401541Srgrimes 4190711Swollman#include <sys/cdefs.h> 42205792Sed#include <sys/_timespec.h> 43102227Smike#include <sys/_types.h> 4490711Swollman 45143952Sdas#ifndef _BLKSIZE_T_DECLARED 46143952Sdastypedef __blksize_t blksize_t; 47143952Sdas#define _BLKSIZE_T_DECLARED 48143952Sdas#endif 49112237Smike 50143952Sdas#ifndef _BLKCNT_T_DECLARED 51143952Sdastypedef __blkcnt_t blkcnt_t; 52143952Sdas#define _BLKCNT_T_DECLARED 53143952Sdas#endif 54143952Sdas 55112745Smike#ifndef _DEV_T_DECLARED 56112745Smiketypedef __dev_t dev_t; 57112745Smike#define _DEV_T_DECLARED 58112745Smike#endif 59112745Smike 60102227Smike#ifndef _FFLAGS_T_DECLARED 61112237Smiketypedef __fflags_t fflags_t; 62102227Smike#define _FFLAGS_T_DECLARED 6390711Swollman#endif 6490711Swollman 65112237Smike#ifndef _GID_T_DECLARED 66112237Smiketypedef __gid_t gid_t; 67112237Smike#define _GID_T_DECLARED 68112237Smike#endif 69112237Smike 70112237Smike#ifndef _INO_T_DECLARED 71112237Smiketypedef __ino_t ino_t; 72112237Smike#define _INO_T_DECLARED 73112237Smike#endif 74112237Smike 75112237Smike#ifndef _MODE_T_DECLARED 76112237Smiketypedef __mode_t mode_t; 77112237Smike#define _MODE_T_DECLARED 78112237Smike#endif 79112237Smike 80112237Smike#ifndef _NLINK_T_DECLARED 81112237Smiketypedef __nlink_t nlink_t; 82112237Smike#define _NLINK_T_DECLARED 83112237Smike#endif 84112237Smike 85112237Smike#ifndef _OFF_T_DECLARED 86112237Smiketypedef __off_t off_t; 87112237Smike#define _OFF_T_DECLARED 88112237Smike#endif 89112237Smike 90112237Smike#ifndef _UID_T_DECLARED 91112237Smiketypedef __uid_t uid_t; 92112237Smike#define _UID_T_DECLARED 93112237Smike#endif 94112237Smike 95112408Smike#if !defined(_KERNEL) && __BSD_VISIBLE 962939Sbde/* 97205792Sed * XXX We get miscellaneous namespace pollution with this. 982939Sbde */ 991541Srgrimes#include <sys/time.h> 10024751Sbde#endif 1011541Srgrimes 102238703Skib#ifdef _KERNEL 1031541Srgrimesstruct ostat { 104112237Smike __uint16_t st_dev; /* inode's device */ 10514493Shsu ino_t st_ino; /* inode's number */ 10614493Shsu mode_t st_mode; /* inode protection mode */ 10714493Shsu nlink_t st_nlink; /* number of hard links */ 108112237Smike __uint16_t st_uid; /* user ID of the file's owner */ 109112237Smike __uint16_t st_gid; /* group ID of the file's group */ 110112237Smike __uint16_t st_rdev; /* device type */ 111112237Smike __int32_t st_size; /* file size, in bytes */ 112205792Sed struct timespec st_atim; /* time of last access */ 113205792Sed struct timespec st_mtim; /* time of last data modification */ 114205792Sed struct timespec st_ctim; /* time of last file status change */ 115112237Smike __int32_t st_blksize; /* optimal blocksize for I/O */ 116112237Smike __int32_t st_blocks; /* blocks allocated for file */ 11790711Swollman fflags_t st_flags; /* user defined flags for file */ 118112237Smike __uint32_t st_gen; /* file generation number */ 1191541Srgrimes}; 120238703Skib#endif 1211541Srgrimes 1221541Srgrimesstruct stat { 123130640Sphk __dev_t st_dev; /* inode's device */ 12414493Shsu ino_t st_ino; /* inode's number */ 12514493Shsu mode_t st_mode; /* inode protection mode */ 12614493Shsu nlink_t st_nlink; /* number of hard links */ 12714493Shsu uid_t st_uid; /* user ID of the file's owner */ 12814493Shsu gid_t st_gid; /* group ID of the file's group */ 129130640Sphk __dev_t st_rdev; /* device type */ 130205792Sed struct timespec st_atim; /* time of last access */ 131205792Sed struct timespec st_mtim; /* time of last data modification */ 132205792Sed struct timespec st_ctim; /* time of last file status change */ 13314493Shsu off_t st_size; /* file size, in bytes */ 134143952Sdas blkcnt_t st_blocks; /* blocks allocated for file */ 135143952Sdas blksize_t st_blksize; /* optimal blocksize for I/O */ 13690711Swollman fflags_t st_flags; /* user defined flags for file */ 137112237Smike __uint32_t st_gen; /* file generation number */ 138112237Smike __int32_t st_lspare; 139205792Sed struct timespec st_birthtim; /* time of file creation */ 14098644Smckusick /* 141205792Sed * Explicitly pad st_birthtim to 16 bytes so that the size of 14298644Smckusick * struct stat is backwards compatible. We use bitfields instead 14398644Smckusick * of an array of chars so that this doesn't require a C99 compiler 14498644Smckusick * to compile if the size of the padding is 0. We use 2 bitfields 14598644Smckusick * to cover up to 64 bits on 32-bit machines. We assume that 14698644Smckusick * CHAR_BIT is 8... 14798644Smckusick */ 148112237Smike unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec)); 149112237Smike unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec)); 1501541Srgrimes}; 15135938Sdyson 152238703Skib#ifdef _KERNEL 15335938Sdysonstruct nstat { 154130640Sphk __dev_t st_dev; /* inode's device */ 15535938Sdyson ino_t st_ino; /* inode's number */ 156112237Smike __uint32_t st_mode; /* inode protection mode */ 157112237Smike __uint32_t st_nlink; /* number of hard links */ 15835938Sdyson uid_t st_uid; /* user ID of the file's owner */ 15935938Sdyson gid_t st_gid; /* group ID of the file's group */ 160130640Sphk __dev_t st_rdev; /* device type */ 161205792Sed struct timespec st_atim; /* time of last access */ 162205792Sed struct timespec st_mtim; /* time of last data modification */ 163205792Sed struct timespec st_ctim; /* time of last file status change */ 16435938Sdyson off_t st_size; /* file size, in bytes */ 165143952Sdas blkcnt_t st_blocks; /* blocks allocated for file */ 166143952Sdas blksize_t st_blksize; /* optimal blocksize for I/O */ 16790711Swollman fflags_t st_flags; /* user defined flags for file */ 168112237Smike __uint32_t st_gen; /* file generation number */ 169205792Sed struct timespec st_birthtim; /* time of file creation */ 17098644Smckusick /* 17198644Smckusick * See above about the following padding. 17298644Smckusick */ 173112237Smike unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec)); 174112237Smike unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec)); 17535938Sdyson}; 17635938Sdyson#endif 17735938Sdyson 178205792Sed#ifndef _KERNEL 179205792Sed#define st_atime st_atim.tv_sec 180205792Sed#define st_mtime st_mtim.tv_sec 181205792Sed#define st_ctime st_ctim.tv_sec 182112237Smike#if __BSD_VISIBLE 183205792Sed#define st_birthtime st_birthtim.tv_sec 18414493Shsu#endif 1851541Srgrimes 186205792Sed/* For compatibility. */ 187205792Sed#if __BSD_VISIBLE 188205792Sed#define st_atimespec st_atim 189205792Sed#define st_mtimespec st_mtim 190205792Sed#define st_ctimespec st_ctim 191205792Sed#define st_birthtimespec st_birthtim 192205792Sed#endif 193205792Sed#endif /* !_KERNEL */ 194205792Sed 1951541Srgrimes#define S_ISUID 0004000 /* set user id on execution */ 1961541Srgrimes#define S_ISGID 0002000 /* set group id on execution */ 197112237Smike#if __BSD_VISIBLE 1981541Srgrimes#define S_ISTXT 0001000 /* sticky bit */ 1991541Srgrimes#endif 2001541Srgrimes 2011541Srgrimes#define S_IRWXU 0000700 /* RWX mask for owner */ 2021541Srgrimes#define S_IRUSR 0000400 /* R for owner */ 2031541Srgrimes#define S_IWUSR 0000200 /* W for owner */ 2041541Srgrimes#define S_IXUSR 0000100 /* X for owner */ 2051541Srgrimes 206112237Smike#if __BSD_VISIBLE 2071541Srgrimes#define S_IREAD S_IRUSR 2081541Srgrimes#define S_IWRITE S_IWUSR 2091541Srgrimes#define S_IEXEC S_IXUSR 2101541Srgrimes#endif 2111541Srgrimes 2121541Srgrimes#define S_IRWXG 0000070 /* RWX mask for group */ 2131541Srgrimes#define S_IRGRP 0000040 /* R for group */ 2141541Srgrimes#define S_IWGRP 0000020 /* W for group */ 2151541Srgrimes#define S_IXGRP 0000010 /* X for group */ 2161541Srgrimes 2171541Srgrimes#define S_IRWXO 0000007 /* RWX mask for other */ 2181541Srgrimes#define S_IROTH 0000004 /* R for other */ 2191541Srgrimes#define S_IWOTH 0000002 /* W for other */ 2201541Srgrimes#define S_IXOTH 0000001 /* X for other */ 2211541Srgrimes 222112237Smike#if __XSI_VISIBLE 2231541Srgrimes#define S_IFMT 0170000 /* type of file mask */ 2241541Srgrimes#define S_IFIFO 0010000 /* named pipe (fifo) */ 2251541Srgrimes#define S_IFCHR 0020000 /* character special */ 2261541Srgrimes#define S_IFDIR 0040000 /* directory */ 2271541Srgrimes#define S_IFBLK 0060000 /* block special */ 2281541Srgrimes#define S_IFREG 0100000 /* regular */ 2291541Srgrimes#define S_IFLNK 0120000 /* symbolic link */ 2301541Srgrimes#define S_IFSOCK 0140000 /* socket */ 2311541Srgrimes#define S_ISVTX 0001000 /* save swapped text even after use */ 2321541Srgrimes#endif 233112237Smike#if __BSD_VISIBLE 234112237Smike#define S_IFWHT 0160000 /* whiteout */ 235112237Smike#endif 2361541Srgrimes 2372939Sbde#define S_ISDIR(m) (((m) & 0170000) == 0040000) /* directory */ 2382939Sbde#define S_ISCHR(m) (((m) & 0170000) == 0020000) /* char special */ 2392939Sbde#define S_ISBLK(m) (((m) & 0170000) == 0060000) /* block special */ 2402939Sbde#define S_ISREG(m) (((m) & 0170000) == 0100000) /* regular file */ 24124751Sbde#define S_ISFIFO(m) (((m) & 0170000) == 0010000) /* fifo or socket */ 242112237Smike#if __POSIX_VISIBLE >= 200112 2432939Sbde#define S_ISLNK(m) (((m) & 0170000) == 0120000) /* symbolic link */ 24424751Sbde#define S_ISSOCK(m) (((m) & 0170000) == 0140000) /* socket */ 245112237Smike#endif 246143952Sdas#if __BSD_VISIBLE 24714493Shsu#define S_ISWHT(m) (((m) & 0170000) == 0160000) /* whiteout */ 2481541Srgrimes#endif 2491541Srgrimes 250112237Smike#if __BSD_VISIBLE 2511541Srgrimes#define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */ 2521541Srgrimes /* 7777 */ 2531541Srgrimes#define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO) 2541541Srgrimes /* 0666 */ 2551541Srgrimes#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) 2561541Srgrimes 2571541Srgrimes#define S_BLKSIZE 512 /* block size used in the stat struct */ 2581541Srgrimes 2591541Srgrimes/* 2601541Srgrimes * Definitions of flags stored in file flags word. 2611541Srgrimes * 2621541Srgrimes * Super-user and owner changeable flags. 2631541Srgrimes */ 2641541Srgrimes#define UF_SETTABLE 0x0000ffff /* mask of owner changeable flags */ 2651541Srgrimes#define UF_NODUMP 0x00000001 /* do not dump file */ 2661541Srgrimes#define UF_IMMUTABLE 0x00000002 /* file may not be changed */ 2671541Srgrimes#define UF_APPEND 0x00000004 /* writes to file may only append */ 268254627Sken#define UF_OPAQUE 0x00000008 /* directory is opaque wrt. union */ 269254627Sken#define UF_NOUNLINK 0x00000010 /* file may not be removed or renamed */ 2701541Srgrimes/* 271254627Sken * These two bits are defined in MacOS X. They are not currently used in 272254627Sken * FreeBSD. 273254627Sken */ 274254627Sken#if 0 275254627Sken#define UF_COMPRESSED 0x00000020 /* file is compressed */ 276254627Sken#define UF_TRACKED 0x00000040 /* renames and deletes are tracked */ 277254627Sken#endif 278254627Sken 279254627Sken#define UF_SYSTEM 0x00000080 /* Windows system file bit */ 280254627Sken#define UF_SPARSE 0x00000100 /* sparse file */ 281254627Sken#define UF_OFFLINE 0x00000200 /* file is offline */ 282254627Sken#define UF_REPARSE 0x00000400 /* Windows reparse point file bit */ 283254627Sken#define UF_ARCHIVE 0x00000800 /* file needs to be archived */ 284254627Sken#define UF_READONLY 0x00001000 /* Windows readonly file bit */ 285254627Sken/* This is the same as the MacOS X definition of UF_HIDDEN. */ 286254627Sken#define UF_HIDDEN 0x00008000 /* file is hidden */ 287254627Sken 288254627Sken/* 2891541Srgrimes * Super-user changeable flags. 2901541Srgrimes */ 2911541Srgrimes#define SF_SETTABLE 0xffff0000 /* mask of superuser changeable flags */ 2921541Srgrimes#define SF_ARCHIVED 0x00010000 /* file is archived */ 2931541Srgrimes#define SF_IMMUTABLE 0x00020000 /* file may not be changed */ 2941541Srgrimes#define SF_APPEND 0x00040000 /* writes to file may only append */ 29526360Sjulian#define SF_NOUNLINK 0x00100000 /* file may not be removed or renamed */ 29662553Smckusick#define SF_SNAPSHOT 0x00200000 /* snapshot inode */ 2971541Srgrimes 29855205Speter#ifdef _KERNEL 2991541Srgrimes/* 3001541Srgrimes * Shorthand abbreviations of above. 3011541Srgrimes */ 30214493Shsu#define OPAQUE (UF_OPAQUE) 3031541Srgrimes#define APPEND (UF_APPEND | SF_APPEND) 3041541Srgrimes#define IMMUTABLE (UF_IMMUTABLE | SF_IMMUTABLE) 30526360Sjulian#define NOUNLINK (UF_NOUNLINK | SF_NOUNLINK) 3061541Srgrimes#endif 3071541Srgrimes 308112237Smike#endif /* __BSD_VISIBLE */ 3092939Sbde 310293474Sdchagin#if __POSIX_VISIBLE >= 200809 311293474Sdchagin#define UTIME_NOW -1 312293474Sdchagin#define UTIME_OMIT -2 313293474Sdchagin#endif 314293474Sdchagin 31555205Speter#ifndef _KERNEL 3161541Srgrimes__BEGIN_DECLS 317112237Smike#if __BSD_VISIBLE 318112237Smikeint chflags(const char *, unsigned long); 319248599Spjdint chflagsat(int, const char *, unsigned long, int); 320112237Smike#endif 32192719Salfredint chmod(const char *, mode_t); 322112237Smike#if __BSD_VISIBLE 323112237Smikeint fchflags(int, unsigned long); 324189817Sdas#endif 325189817Sdas#if __POSIX_VISIBLE >= 200112 326112237Smikeint fchmod(int, mode_t); 327112237Smike#endif 328189817Sdas#if __POSIX_VISIBLE >= 200809 329189817Sdasint fchmodat(int, const char *, mode_t, int); 330293474Sdchaginint futimens(int fd, const struct timespec times[2]); 331293474Sdchaginint utimensat(int fd, const char *path, const struct timespec times[2], 332293474Sdchagin int flag); 333189817Sdas#endif 33492719Salfredint fstat(int, struct stat *); 335112237Smike#if __BSD_VISIBLE 336248597Spjdint lchflags(const char *, unsigned long); 337112237Smikeint lchmod(const char *, mode_t); 338112237Smike#endif 339112237Smike#if __POSIX_VISIBLE >= 200112 340143952Sdasint lstat(const char * __restrict, struct stat * __restrict); 341112237Smike#endif 34292719Salfredint mkdir(const char *, mode_t); 34392719Salfredint mkfifo(const char *, mode_t); 344143952Sdas#if !defined(_MKNOD_DECLARED) && __XSI_VISIBLE 345143952Sdasint mknod(const char *, mode_t, dev_t); 346143952Sdas#define _MKNOD_DECLARED 347143952Sdas#endif 348143952Sdasint stat(const char * __restrict, struct stat * __restrict); 34992719Salfredmode_t umask(mode_t); 350189354Sdas#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 351177791Skibint fstatat(int, const char *, struct stat *, int); 352177791Skibint mkdirat(int, const char *, mode_t); 353177791Skibint mkfifoat(int, const char *, mode_t); 354189817Sdas#endif 355189817Sdas#if __BSD_VISIBLE || __XSI_VISIBLE >= 700 356177791Skibint mknodat(int, const char *, mode_t, dev_t); 357177791Skib#endif 3581541Srgrimes__END_DECLS 35955205Speter#endif /* !_KERNEL */ 3602939Sbde 3611541Srgrimes#endif /* !_SYS_STAT_H_ */ 362