| 1 | /* $NetBSD: stat.h,v 1.68 2013/10/17 18:01:11 njoly 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. 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) 8/17/94 |
| 37 | */ |
| 38 | |
| 39 | #ifndef _SYS_STAT_H_ |
| 40 | #define _SYS_STAT_H_ |
| 41 | |
| 42 | #include <sys/featuretest.h> |
| 43 | #include <sys/types.h> /* XXX */ |
| 44 | |
| 45 | #if (_POSIX_C_SOURCE - 0) >= 200809L || (_XOPEN_SOURCE - 0) >= 700 || \ |
| 46 | defined(_NETBSD_SOURCE) |
| 47 | /* |
| 48 | * POSIX:2008 / XPG7 requires struct timespec to be declared in |
| 49 | * this header, but does not provide the usual exemption |
| 50 | * "inclusion of this header may make visible symbols defined in <time.h>". |
| 51 | * |
| 52 | * This is a Standard omission, acknowledged by the committee and |
| 53 | * scheduled to be corrected in Technical Corrigendum 2, according to |
| 54 | * http://austingroupbugs.net/view.php?id=531 |
| 55 | */ |
| 56 | #include <sys/time.h> |
| 57 | #endif |
| 58 | |
| 59 | struct stat { |
| 60 | dev_t st_dev; /* inode's device */ |
| 61 | mode_t st_mode; /* inode protection mode */ |
| 62 | ino_t st_ino; /* inode's number */ |
| 63 | nlink_t st_nlink; /* number of hard links */ |
| 64 | uid_t st_uid; /* user ID of the file's owner */ |
| 65 | gid_t st_gid; /* group ID of the file's group */ |
| 66 | dev_t st_rdev; /* device type */ |
| 67 | #if (_POSIX_C_SOURCE - 0) >= 200809L || (_XOPEN_SOURCE - 0) >= 700 || \ |
| 68 | defined(_NETBSD_SOURCE) |
| 69 | struct timespec st_atim; /* time of last access */ |
| 70 | struct timespec st_mtim; /* time of last data modification */ |
| 71 | struct timespec st_ctim; /* time of last file status change */ |
| 72 | struct timespec st_birthtim; /* time of creation */ |
| 73 | #else |
| 74 | time_t st_atime; /* time of last access */ |
| 75 | long st_atimensec; /* nsec of last access */ |
| 76 | time_t st_mtime; /* time of last data modification */ |
| 77 | long st_mtimensec; /* nsec of last data modification */ |
| 78 | time_t st_ctime; /* time of last file status change */ |
| 79 | long st_ctimensec; /* nsec of last file status change */ |
| 80 | time_t st_birthtime; /* time of creation */ |
| 81 | long st_birthtimensec; /* nsec of time of creation */ |
| 82 | #endif |
| 83 | off_t st_size; /* file size, in bytes */ |
| 84 | blkcnt_t st_blocks; /* blocks allocated for file */ |
| 85 | blksize_t st_blksize; /* optimal blocksize for I/O */ |
| 86 | uint32_t st_flags; /* user defined flags for file */ |
| 87 | uint32_t st_gen; /* file generation number */ |
| 88 | uint32_t st_spare[2]; |
| 89 | }; |
| 90 | |
| 91 | #if (_POSIX_C_SOURCE - 0) >= 200809L || (_XOPEN_SOURCE - 0) >= 700 || \ |
| 92 | defined(_NETBSD_SOURCE) |
| 93 | /* Standard-mandated compatibility */ |
| 94 | #define st_atime st_atim.tv_sec |
| 95 | #define st_mtime st_mtim.tv_sec |
| 96 | #define st_ctime st_ctim.tv_sec |
| 97 | #define st_birthtime st_birthtim.tv_sec |
| 98 | #endif |
| 99 | |
| 100 | #if defined(_NETBSD_SOURCE) |
| 101 | #define st_atimespec st_atim |
| 102 | #define st_atimensec st_atim.tv_nsec |
| 103 | #define st_mtimespec st_mtim |
| 104 | #define st_mtimensec st_mtim.tv_nsec |
| 105 | #define st_ctimespec st_ctim |
| 106 | #define st_ctimensec st_ctim.tv_nsec |
| 107 | #define st_birthtimespec st_birthtim |
| 108 | #define st_birthtimensec st_birthtimespec.tv_nsec |
| 109 | #endif |
| 110 | |
| 111 | #define S_ISUID 0004000 /* set user id on execution */ |
| 112 | #define S_ISGID 0002000 /* set group id on execution */ |
| 113 | #if defined(_NETBSD_SOURCE) |
| 114 | #define S_ISTXT 0001000 /* sticky bit */ |
| 115 | #endif |
| 116 | |
| 117 | #define S_IRWXU 0000700 /* RWX mask for owner */ |
| 118 | #define S_IRUSR 0000400 /* R for owner */ |
| 119 | #define S_IWUSR 0000200 /* W for owner */ |
| 120 | #define S_IXUSR 0000100 /* X for owner */ |
| 121 | |
| 122 | #if defined(_NETBSD_SOURCE) |
| 123 | #define S_IREAD S_IRUSR |
| 124 | #define S_IWRITE S_IWUSR |
| 125 | #define S_IEXEC S_IXUSR |
| 126 | #endif |
| 127 | |
| 128 | #define S_IRWXG 0000070 /* RWX mask for group */ |
| 129 | #define S_IRGRP 0000040 /* R for group */ |
| 130 | #define S_IWGRP 0000020 /* W for group */ |
| 131 | #define S_IXGRP 0000010 /* X for group */ |
| 132 | |
| 133 | #define S_IRWXO 0000007 /* RWX mask for other */ |
| 134 | #define S_IROTH 0000004 /* R for other */ |
| 135 | #define S_IWOTH 0000002 /* W for other */ |
| 136 | #define S_IXOTH 0000001 /* X for other */ |
| 137 | |
| 138 | #define _S_IFMT 0170000 /* type of file mask */ |
| 139 | #define _S_IFIFO 0010000 /* named pipe (fifo) */ |
| 140 | #define _S_IFCHR 0020000 /* character special */ |
| 141 | #define _S_IFDIR 0040000 /* directory */ |
| 142 | #define _S_IFBLK 0060000 /* block special */ |
| 143 | #define _S_IFREG 0100000 /* regular */ |
| 144 | #define _S_IFLNK 0120000 /* symbolic link */ |
| 145 | #define _S_ISVTX 0001000 /* save swapped text even after use */ |
| 146 | #define _S_IFSOCK 0140000 /* socket */ |
| 147 | #define _S_IFWHT 0160000 /* whiteout */ |
| 148 | #define _S_ARCH1 0200000 /* Archive state 1, ls -l shows 'a' */ |
| 149 | #define _S_ARCH2 0400000 /* Archive state 2, ls -l shows 'A' */ |
| 150 | |
| 151 | #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) |
| 152 | #define S_IFMT _S_IFMT |
| 153 | #define S_IFIFO _S_IFIFO |
| 154 | #define S_IFCHR _S_IFCHR |
| 155 | #define S_IFDIR _S_IFDIR |
| 156 | #define S_IFBLK _S_IFBLK |
| 157 | #define S_IFREG _S_IFREG |
| 158 | #define S_IFLNK _S_IFLNK |
| 159 | #define S_ISVTX _S_ISVTX |
| 160 | #endif |
| 161 | #if ((_XOPEN_SOURCE - 0) >= 600) || defined(_NETBSD_SOURCE) |
| 162 | #define S_IFSOCK _S_IFSOCK |
| 163 | #endif |
| 164 | #if defined(_NETBSD_SOURCE) |
| 165 | #define S_IFWHT _S_IFWHT |
| 166 | |
| 167 | #define S_ARCH1 _S_ARCH1 |
| 168 | #define S_ARCH2 _S_ARCH2 |
| 169 | #endif |
| 170 | |
| 171 | #define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) /* directory */ |
| 172 | #define S_ISCHR(m) (((m) & _S_IFMT) == _S_IFCHR) /* char special */ |
| 173 | #define S_ISBLK(m) (((m) & _S_IFMT) == _S_IFBLK) /* block special */ |
| 174 | #define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) /* regular file */ |
| 175 | #define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO) /* fifo */ |
| 176 | #if ((_POSIX_C_SOURCE - 0) >= 200112L) || defined(_XOPEN_SOURCE) || \ |
| 177 | defined(_NETBSD_SOURCE) |
| 178 | #define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK) /* symbolic link */ |
| 179 | #endif |
| 180 | #if ((_POSIX_C_SOURCE - 0) >= 200112L) || ((_XOPEN_SOURCE - 0) >= 600) || \ |
| 181 | defined(_NETBSD_SOURCE) |
| 182 | #define S_ISSOCK(m) (((m) & _S_IFMT) == _S_IFSOCK) /* socket */ |
| 183 | #endif |
| 184 | #if defined(_NETBSD_SOURCE) |
| 185 | #define S_ISWHT(m) (((m) & _S_IFMT) == _S_IFWHT) /* whiteout */ |
| 186 | #endif |
| 187 | |
| 188 | #if defined(_NETBSD_SOURCE) |
| 189 | #define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */ |
| 190 | /* 7777 */ |
| 191 | #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO) |
| 192 | /* 0666 */ |
| 193 | #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) |
| 194 | |
| 195 | #define S_BLKSIZE 512 /* block size used in the stat struct */ |
| 196 | |
| 197 | /* |
| 198 | * Definitions of flags stored in file flags word. |
| 199 | * |
| 200 | * Super-user and owner changeable flags. |
| 201 | */ |
| 202 | #define UF_SETTABLE 0x0000ffff /* mask of owner changeable flags */ |
| 203 | #define UF_NODUMP 0x00000001 /* do not dump file */ |
| 204 | #define UF_IMMUTABLE 0x00000002 /* file may not be changed */ |
| 205 | #define UF_APPEND 0x00000004 /* writes to file may only append */ |
| 206 | #define UF_OPAQUE 0x00000008 /* directory is opaque wrt. union */ |
| 207 | /* UF_NOUNLINK 0x00000010 [NOT IMPLEMENTED] */ |
| 208 | /* |
| 209 | * Super-user changeable flags. |
| 210 | */ |
| 211 | #define SF_SETTABLE 0xffff0000 /* mask of superuser changeable flags */ |
| 212 | #define SF_ARCHIVED 0x00010000 /* file is archived */ |
| 213 | #define SF_IMMUTABLE 0x00020000 /* file may not be changed */ |
| 214 | #define SF_APPEND 0x00040000 /* writes to file may only append */ |
| 215 | /* SF_NOUNLINK 0x00100000 [NOT IMPLEMENTED] */ |
| 216 | #define SF_SNAPSHOT 0x00200000 /* snapshot inode */ |
| 217 | #define SF_LOG 0x00400000 /* WAPBL log file inode */ |
| 218 | #define SF_SNAPINVAL 0x00800000 /* snapshot is invalid */ |
| 219 | |
| 220 | #ifdef _KERNEL |
| 221 | /* |
| 222 | * Shorthand abbreviations of above. |
| 223 | */ |
| 224 | #define OPAQUE (UF_OPAQUE) |
| 225 | #define APPEND (UF_APPEND | SF_APPEND) |
| 226 | #define IMMUTABLE (UF_IMMUTABLE | SF_IMMUTABLE) |
| 227 | #endif /* _KERNEL */ |
| 228 | #endif /* _NETBSD_SOURCE */ |
| 229 | |
| 230 | #if (_POSIX_C_SOURCE - 0) >= 200809L || (_XOPEN_SOURCE - 0) >= 700 || \ |
| 231 | defined(_NETBSD_SOURCE) |
| 232 | /* |
| 233 | * Special values for utimensat and futimens |
| 234 | */ |
| 235 | #define UTIME_NOW ((1 << 30) - 1) |
| 236 | #define UTIME_OMIT ((1 << 30) - 2) |
| 237 | #endif |
| 238 | |
| 239 | #if !defined(_KERNEL) && !defined(_STANDALONE) |
| 240 | #include <sys/cdefs.h> |
| 241 | |
| 242 | __BEGIN_DECLS |
| 243 | int chmod(const char *, mode_t); |
| 244 | int mkdir(const char *, mode_t); |
| 245 | int mkfifo(const char *, mode_t); |
| 246 | #ifndef __LIBC12_SOURCE__ |
| 247 | int stat(const char *, struct stat *) __RENAME(__stat50); |
| 248 | int fstat(int, struct stat *) __RENAME(__fstat50); |
| 249 | #endif |
| 250 | mode_t umask(mode_t); |
| 251 | #if (_POSIX_C_SOURCE - 0) >= 200112L || defined(_XOPEN_SOURCE) || \ |
| 252 | defined(_NETBSD_SOURCE) |
| 253 | #ifndef __LIBC12_SOURCE__ |
| 254 | int lstat(const char *, struct stat *) __RENAME(__lstat50); |
| 255 | #endif |
| 256 | #endif /* _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE || _NETBSD_SOURCE */ |
| 257 | #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) |
| 258 | int fchmod(int, mode_t); |
| 259 | #ifndef __LIBC12_SOURCE__ |
| 260 | int mknod(const char *, mode_t, dev_t) __RENAME(__mknod50); |
| 261 | #endif |
| 262 | #endif /* defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) */ |
| 263 | |
| 264 | #if defined(_NETBSD_SOURCE) |
| 265 | int chflags(const char *, unsigned long); |
| 266 | int fchflags(int, unsigned long); |
| 267 | int lchflags(const char *, unsigned long); |
| 268 | int lchmod(const char *, mode_t); |
| 269 | #endif /* defined(_NETBSD_SOURCE) */ |
| 270 | |
| 271 | #ifndef __LIBC12_SOURCE__ |
| 272 | /* |
| 273 | * X/Open Extended API set 2 (a.k.a. C063) |
| 274 | */ |
| 275 | #if (_POSIX_C_SOURCE - 0) >= 200809L || (_XOPEN_SOURCE - 0) >= 700 || \ |
| 276 | defined(_NETBSD_SOURCE) || defined(_INCOMPLETE_XOPEN_C063) |
| 277 | int fchmodat(int, const char *, mode_t, int); |
| 278 | int fstatat(int, const char *, struct stat *, int); |
| 279 | int mkdirat(int, const char *, mode_t); |
| 280 | int mkfifoat(int, const char *, mode_t); |
| 281 | int mknodat(int, const char *, mode_t, dev_t); |
| 282 | int utimensat(int, const char *, const struct timespec *, int); |
| 283 | #endif |
| 284 | |
| 285 | #ifdef _NETBSD_SOURCE |
| 286 | int utimens(const char *, const struct timespec *); |
| 287 | int lutimens(const char *, const struct timespec *); |
| 288 | #endif |
| 289 | |
| 290 | #if (_POSIX_C_SOURCE - 0) >= 200809L || (_XOPEN_SOURCE - 0) >= 700 || \ |
| 291 | defined(_NETBSD_SOURCE) |
| 292 | int futimens(int, const struct timespec *); |
| 293 | #endif |
| 294 | #endif |
| 295 | |
| 296 | __END_DECLS |
| 297 | |
| 298 | #endif /* !_KERNEL && !_STANDALONE */ |
| 299 | #endif /* !_SYS_STAT_H_ */ |
| 300 | |