1 /* $NetBSD: stat.h,v 1.41 2002/05/03 00:27:45 eeh Exp $ */ 2 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. All advertising materials mentioning features or use of this software 21 * must display the following acknowledgement: 22 * This product includes software developed by the University of 23 * California, Berkeley and its contributors. 24 * 4. Neither the name of the University nor the names of its contributors 25 * may be used to endorse or promote products derived from this software 26 * without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38 * SUCH DAMAGE. 39 * 40 * @(#)stat.h 8.12 (Berkeley) 8/17/94 41 */ 42 43 #ifndef _SYS_STAT_H_ 44 #define _SYS_STAT_H_ 45 46 #include <sys/featuretest.h> 47 #include <sys/types.h> /* XXX */ 48 49 #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) 50 #include <sys/time.h> 51 #endif 52 53 #ifdef _KERNEL 54 struct stat43 { /* BSD-4.3 stat struct */ 55 u_int16_t st_dev; /* inode's device */ 56 ino_t st_ino; /* inode's number */ 57 u_int16_t st_mode; /* inode protection mode */ 58 u_int16_t st_nlink; /* number of hard links */ 59 u_int16_t st_uid; /* user ID of the file's owner */ 60 u_int16_t st_gid; /* group ID of the file's group */ 61 u_int16_t st_rdev; /* device type */ 62 int32_t st_size; /* file size, in bytes */ 63 struct timespec st_atimespec;/* time of last access */ 64 struct timespec st_mtimespec;/* time of last data modification */ 65 struct timespec st_ctimespec;/* time of last file status change */ 66 int32_t st_blksize; /* optimal blocksize for I/O */ 67 int32_t st_blocks; /* blocks allocated for file */ 68 u_int32_t st_flags; /* user defined flags for file */ 69 u_int32_t st_gen; /* file generation number */ 70 }; 71 #endif /* defined(_KERNEL) */ 72 73 #if defined(__LIBC12_SOURCE__) || defined(_KERNEL) 74 struct stat12 { /* NetBSD-1.2 stat struct */ 75 dev_t st_dev; /* inode's device */ 76 ino_t st_ino; /* inode's number */ 77 u_int16_t st_mode; /* inode protection mode */ 78 u_int16_t st_nlink; /* number of hard links */ 79 uid_t st_uid; /* user ID of the file's owner */ 80 gid_t st_gid; /* group ID of the file's group */ 81 dev_t st_rdev; /* device type */ 82 struct timespec st_atimespec;/* time of last access */ 83 struct timespec st_mtimespec;/* time of last data modification */ 84 struct timespec st_ctimespec;/* time of last file status change */ 85 off_t st_size; /* file size, in bytes */ 86 int64_t st_blocks; /* blocks allocated for file */ 87 u_int32_t st_blksize; /* optimal blocksize for I/O */ 88 u_int32_t st_flags; /* user defined flags for file */ 89 u_int32_t st_gen; /* file generation number */ 90 int32_t st_lspare; 91 int64_t st_qspare[2]; 92 }; 93 #endif /* defined(__LIBC12_SOURCE__) || defined(_KERNEL) */ 94 95 /* 96 * On systems with 8 byte longs and 4 byte time_ts, padding the time_ts 97 * is required in order to have a consistent ABI. This is because the 98 * stat structure used to contain timespecs, which had different 99 * alignment constraints than a time_t and a long alone. The padding 100 * should be removed the next time the stat structure ABI is changed. 101 * (This will happen whever we change to 8 byte time_t.) 102 */ 103 #if defined(_LP64) /* XXXX && _BSD_TIME_T_ == int */ 104 #define __STATPAD(x) int x; 105 #else 106 #define __STATPAD(x) /* nothing */ 107 #endif 108 109 struct stat { 110 dev_t st_dev; /* inode's device */ 111 ino_t st_ino; /* inode's number */ 112 mode_t st_mode; /* inode protection mode */ 113 nlink_t st_nlink; /* number of hard links */ 114 uid_t st_uid; /* user ID of the file's owner */ 115 gid_t st_gid; /* group ID of the file's group */ 116 dev_t st_rdev; /* device type */ 117 #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) 118 struct timespec st_atimespec;/* time of last access */ 119 struct timespec st_mtimespec;/* time of last data modification */ 120 struct timespec st_ctimespec;/* time of last file status change */ 121 #else 122 __STATPAD(__pad0) 123 time_t st_atime; /* time of last access */ 124 __STATPAD(__pad1) 125 long st_atimensec; /* nsec of last access */ 126 time_t st_mtime; /* time of last data modification */ 127 __STATPAD(__pad2) 128 long st_mtimensec; /* nsec of last data modification */ 129 time_t st_ctime; /* time of last file status change */ 130 __STATPAD(__pad3) 131 long st_ctimensec; /* nsec of last file status change */ 132 #endif 133 off_t st_size; /* file size, in bytes */ 134 blkcnt_t st_blocks; /* blocks allocated for file */ 135 blksize_t st_blksize; /* optimal blocksize for I/O */ 136 u_int32_t st_flags; /* user defined flags for file */ 137 u_int32_t st_gen; /* file generation number */ 138 int64_t st_qspare[2]; 139 }; 140 141 #undef __STATPAD 142 143 #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) 144 #define st_atime st_atimespec.tv_sec 145 #define st_atimensec st_atimespec.tv_nsec 146 #define st_mtime st_mtimespec.tv_sec 147 #define st_mtimensec st_mtimespec.tv_nsec 148 #define st_ctime st_ctimespec.tv_sec 149 #define st_ctimensec st_ctimespec.tv_nsec 150 #endif 151 152 #define S_ISUID 0004000 /* set user id on execution */ 153 #define S_ISGID 0002000 /* set group id on execution */ 154 #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) 155 #define S_ISTXT 0001000 /* sticky bit */ 156 #endif 157 158 #define S_IRWXU 0000700 /* RWX mask for owner */ 159 #define S_IRUSR 0000400 /* R for owner */ 160 #define S_IWUSR 0000200 /* W for owner */ 161 #define S_IXUSR 0000100 /* X for owner */ 162 163 #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) 164 #define S_IREAD S_IRUSR 165 #define S_IWRITE S_IWUSR 166 #define S_IEXEC S_IXUSR 167 #endif 168 169 #define S_IRWXG 0000070 /* RWX mask for group */ 170 #define S_IRGRP 0000040 /* R for group */ 171 #define S_IWGRP 0000020 /* W for group */ 172 #define S_IXGRP 0000010 /* X for group */ 173 174 #define S_IRWXO 0000007 /* RWX mask for other */ 175 #define S_IROTH 0000004 /* R for other */ 176 #define S_IWOTH 0000002 /* W for other */ 177 #define S_IXOTH 0000001 /* X for other */ 178 179 #define _S_IFMT 0170000 /* type of file mask */ 180 #define _S_IFIFO 0010000 /* named pipe (fifo) */ 181 #define _S_IFCHR 0020000 /* character special */ 182 #define _S_IFDIR 0040000 /* directory */ 183 #define _S_IFBLK 0060000 /* block special */ 184 #define _S_IFREG 0100000 /* regular */ 185 #define _S_IFLNK 0120000 /* symbolic link */ 186 #define _S_ISVTX 0001000 /* save swapped text even after use */ 187 #define _S_IFSOCK 0140000 /* socket */ 188 #define _S_IFWHT 0160000 /* whiteout */ 189 #define _S_ARCH1 0200000 /* Archive state 1, ls -l shows 'a' */ 190 #define _S_ARCH2 0400000 /* Archive state 2, ls -l shows 'A' */ 191 192 #if !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) 193 #define S_IFMT _S_IFMT 194 #define S_IFIFO _S_IFIFO 195 #define S_IFCHR _S_IFCHR 196 #define S_IFDIR _S_IFDIR 197 #define S_IFBLK _S_IFBLK 198 #define S_IFREG _S_IFREG 199 #define S_IFLNK _S_IFLNK 200 #define S_ISVTX _S_ISVTX 201 #endif 202 #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) 203 #define S_IFSOCK _S_IFSOCK 204 #define S_IFWHT _S_IFWHT 205 206 #define S_ARCH1 _S_ARCH1 207 #define S_ARCH2 _S_ARCH2 208 #endif 209 210 #define S_ISDIR(m) ((m & _S_IFMT) == _S_IFDIR) /* directory */ 211 #define S_ISCHR(m) ((m & _S_IFMT) == _S_IFCHR) /* char special */ 212 #define S_ISBLK(m) ((m & _S_IFMT) == _S_IFBLK) /* block special */ 213 #define S_ISREG(m) ((m & _S_IFMT) == _S_IFREG) /* regular file */ 214 #define S_ISFIFO(m) ((m & _S_IFMT) == _S_IFIFO) /* fifo */ 215 #if !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) 216 #define S_ISLNK(m) ((m & _S_IFMT) == _S_IFLNK) /* symbolic link */ 217 #endif 218 #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) 219 #define S_ISSOCK(m) ((m & _S_IFMT) == _S_IFSOCK) /* socket */ 220 #define S_ISWHT(m) ((m & _S_IFMT) == _S_IFWHT) /* whiteout */ 221 #endif 222 223 #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) 224 #define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */ 225 /* 7777 */ 226 #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO) 227 /* 0666 */ 228 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) 229 230 #define S_BLKSIZE 512 /* block size used in the stat struct */ 231 232 /* 233 * Definitions of flags stored in file flags word. 234 * 235 * Super-user and owner changeable flags. 236 */ 237 #define UF_SETTABLE 0x0000ffff /* mask of owner changeable flags */ 238 #define UF_NODUMP 0x00000001 /* do not dump file */ 239 #define UF_IMMUTABLE 0x00000002 /* file may not be changed */ 240 #define UF_APPEND 0x00000004 /* writes to file may only append */ 241 #define UF_OPAQUE 0x00000008 /* directory is opaque wrt. union */ 242 /* 243 * Super-user changeable flags. 244 */ 245 #define SF_SETTABLE 0xffff0000 /* mask of superuser changeable flags */ 246 #define SF_ARCHIVED 0x00010000 /* file is archived */ 247 #define SF_IMMUTABLE 0x00020000 /* file may not be changed */ 248 #define SF_APPEND 0x00040000 /* writes to file may only append */ 249 250 #ifdef _KERNEL 251 /* 252 * Shorthand abbreviations of above. 253 */ 254 #define OPAQUE (UF_OPAQUE) 255 #define APPEND (UF_APPEND | SF_APPEND) 256 #define IMMUTABLE (UF_IMMUTABLE | SF_IMMUTABLE) 257 #endif /* _KERNEL */ 258 #endif /* !_POSIX_C_SOURCE && !_XOPEN_SOURCE */ 259 260 #if !defined(_KERNEL) && !defined(_STANDALONE) 261 #include <sys/cdefs.h> 262 263 __BEGIN_DECLS 264 int chmod __P((const char *, mode_t)); 265 int mkdir __P((const char *, mode_t)); 266 int mkfifo __P((const char *, mode_t)); 267 #ifdef __LIBC12_SOURCE__ 268 int stat __P((const char *, struct stat12 *)); 269 int fstat __P((int, struct stat12 *)); 270 int __stat13 __P((const char *, struct stat *)); 271 int __fstat13 __P((int, struct stat *)); 272 #else 273 int stat __P((const char *, struct stat *)) __RENAME(__stat13); 274 int fstat __P((int, struct stat *)) __RENAME(__fstat13); 275 #endif 276 mode_t umask __P((mode_t)); 277 #if !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) 278 int fchmod __P((int, mode_t)); 279 #ifdef __LIBC12_SOURCE__ 280 int lstat __P((const char *, struct stat12 *)); 281 int __lstat13 __P((const char *, struct stat *)); 282 #else 283 int lstat __P((const char *, struct stat *)) __RENAME(__lstat13); 284 #endif 285 int mknod __P((const char *, mode_t, dev_t)); 286 #endif /* !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) */ 287 288 #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) 289 int chflags __P((const char *, unsigned long)); 290 int fchflags __P((int, unsigned long)); 291 int lchflags __P((const char *, unsigned long)); 292 int lchmod __P((const char *, mode_t)); 293 #endif /* !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) */ 294 __END_DECLS 295 296 #endif /* !_KERNEL && !_STANDALONE */ 297 #endif /* !_SYS_STAT_H_ */ 298