1 /** $MirOS: src/sys/sys/stat.h,v 1.4 2007/05/19 21:31:58 tg Exp $ */ 2 /* $OpenBSD: stat.h,v 1.15 2005/06/18 18:09:43 millert Exp $ */ 3 /* $NetBSD: stat.h,v 1.20 1996/05/16 22:17:49 cgd Exp $ */ 4 5 /*- 6 * Copyright (c) 1982, 1986, 1989, 1993 7 * The Regents of the University of California. All rights reserved. 8 * (c) UNIX System Laboratories, Inc. 9 * All or some portions of this file are derived from material licensed 10 * to the University of California by American Telephone and Telegraph 11 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 12 * the permission of UNIX System Laboratories, Inc. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions 16 * are met: 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in the 21 * documentation and/or other materials provided with the distribution. 22 * 3. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)stat.h 8.9 (Berkeley) 8/17/94 39 */ 40 41 #ifndef _SYS_STAT_H_ 42 #define _SYS_STAT_H_ 43 44 #include <sys/time.h> 45 46 struct stat { 47 dev_t st_dev; /* inode's device */ 48 ino_t st_ino; /* inode's number */ 49 mode_t st_mode; /* inode protection mode */ 50 nlink_t st_nlink; /* number of hard links */ 51 uid_t st_uid; /* user ID of the file's owner */ 52 gid_t st_gid; /* group ID of the file's group */ 53 dev_t st_rdev; /* device type */ 54 int32_t st_lspare0; 55 #ifndef _POSIX_SOURCE 56 struct timespec st_atimespec; /* time of last access */ 57 struct timespec st_mtimespec; /* time of last data modification */ 58 struct timespec st_ctimespec; /* time of last file status change */ 59 #else 60 time_t st_atime; /* time of last access */ 61 long st_atimensec; /* nsec of last access */ 62 time_t st_mtime; /* time of last data modification */ 63 long st_mtimensec; /* nsec of last data modification */ 64 time_t st_ctime; /* time of last file status change */ 65 long st_ctimensec; /* nsec of last file status change */ 66 #endif 67 off_t st_size; /* file size, in bytes */ 68 int64_t st_blocks; /* blocks allocated for file */ 69 u_int32_t st_blksize; /* optimal blocksize for I/O */ 70 u_int32_t st_flags; /* user defined flags for file */ 71 u_int32_t st_gen; /* file generation number */ 72 int32_t st_lspare1; 73 #ifndef _POSIX_SOURCE 74 struct timespec __st_birthtimespec; /* time of file creation */ 75 #else 76 time_t __st_birthtime; /* time of file creation */ 77 long __st_birthtimensec; /* nsec of file creation */ 78 #endif 79 int64_t st_qspare[2]; 80 }; 81 #ifndef _POSIX_SOURCE 82 #define st_atime st_atimespec.tv_sec 83 #define st_atimensec st_atimespec.tv_nsec 84 #define st_mtime st_mtimespec.tv_sec 85 #define st_mtimensec st_mtimespec.tv_nsec 86 #define st_ctime st_ctimespec.tv_sec 87 #define st_ctimensec st_ctimespec.tv_nsec 88 #endif 89 90 #define S_ISUID 0004000 /* set user id on execution */ 91 #define S_ISGID 0002000 /* set group id on execution */ 92 #ifndef _POSIX_SOURCE 93 #define S_ISTXT 0001000 /* sticky bit */ 94 #endif 95 96 #define S_IRWXU 0000700 /* RWX mask for owner */ 97 #define S_IRUSR 0000400 /* R for owner */ 98 #define S_IWUSR 0000200 /* W for owner */ 99 #define S_IXUSR 0000100 /* X for owner */ 100 101 #ifndef _POSIX_SOURCE 102 #define S_IREAD S_IRUSR 103 #define S_IWRITE S_IWUSR 104 #define S_IEXEC S_IXUSR 105 #endif 106 107 #define S_IRWXG 0000070 /* RWX mask for group */ 108 #define S_IRGRP 0000040 /* R for group */ 109 #define S_IWGRP 0000020 /* W for group */ 110 #define S_IXGRP 0000010 /* X for group */ 111 112 #define S_IRWXO 0000007 /* RWX mask for other */ 113 #define S_IROTH 0000004 /* R for other */ 114 #define S_IWOTH 0000002 /* W for other */ 115 #define S_IXOTH 0000001 /* X for other */ 116 117 #ifndef _POSIX_SOURCE 118 #define S_IFMT 0170000 /* type of file mask */ 119 #define S_IFIFO 0010000 /* named pipe (fifo) */ 120 #define S_IFCHR 0020000 /* character special */ 121 #define S_IFDIR 0040000 /* directory */ 122 #define S_IFBLK 0060000 /* block special */ 123 #define S_IFREG 0100000 /* regular */ 124 #define S_IFLNK 0120000 /* symbolic link */ 125 #define S_IFSOCK 0140000 /* socket */ 126 #define S_ISVTX 0001000 /* save swapped text even after use */ 127 #endif 128 129 #define S_ISDIR(m) ((m & 0170000) == 0040000) /* directory */ 130 #define S_ISCHR(m) ((m & 0170000) == 0020000) /* char special */ 131 #define S_ISBLK(m) ((m & 0170000) == 0060000) /* block special */ 132 #define S_ISREG(m) ((m & 0170000) == 0100000) /* regular file */ 133 #define S_ISFIFO(m) ((m & 0170000) == 0010000) /* fifo */ 134 #ifndef _POSIX_SOURCE 135 #define S_ISLNK(m) ((m & 0170000) == 0120000) /* symbolic link */ 136 #define S_ISSOCK(m) ((m & 0170000) == 0140000) /* socket */ 137 #endif 138 139 #ifndef _POSIX_SOURCE 140 #define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 00777 */ 141 /* 07777 */ 142 #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO) 143 /* 00666 */ 144 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) 145 146 #define S_BLKSIZE 512 /* block size used in the stat struct */ 147 148 /* 149 * Definitions of flags stored in file flags word. 150 * 151 * Super-user and owner changeable flags. 152 */ 153 #define UF_SETTABLE 0x0000ffff /* mask of owner changeable flags */ 154 #define UF_NODUMP 0x00000001 /* do not dump file */ 155 #define UF_IMMUTABLE 0x00000002 /* file may not be changed */ 156 #define UF_APPEND 0x00000004 /* writes to file may only append */ 157 #define UF_OPAQUE 0x00000008 /* directory is opaque wrt. union */ 158 /* 159 * Super-user changeable flags. 160 */ 161 #define SF_SETTABLE 0xffff0000 /* mask of superuser changeable flags */ 162 #define SF_ARCHIVED 0x00010000 /* file is archived */ 163 #define SF_IMMUTABLE 0x00020000 /* file may not be changed */ 164 #define SF_APPEND 0x00040000 /* writes to file may only append */ 165 166 #ifdef _KERNEL 167 /* 168 * Shorthand abbreviations of above. 169 */ 170 #define OPAQUE (UF_OPAQUE) 171 #define APPEND (UF_APPEND | SF_APPEND) 172 #define IMMUTABLE (UF_IMMUTABLE | SF_IMMUTABLE) 173 #endif 174 #endif 175 176 #ifndef _KERNEL 177 #include <sys/cdefs.h> 178 179 __BEGIN_DECLS 180 int chmod(const char *, mode_t); 181 int fstat(int, struct stat *); 182 int mknod(const char *, mode_t, dev_t); 183 int mkdir(const char *, mode_t); 184 int mkfifo(const char *, mode_t); 185 int stat(const char *, struct stat *); 186 mode_t umask(mode_t); 187 #ifndef _POSIX_SOURCE 188 int chflags(const char *, unsigned int); 189 int fchflags(int, unsigned int); 190 int lchflags(const char *, unsigned int); 191 int fchmod(int, mode_t); 192 int lchmod(const char *, mode_t); 193 int lstat(const char *, struct stat *); 194 int isfdtype(int, int); 195 #endif 196 __END_DECLS 197 #endif 198 #endif /* !_SYS_STAT_H_ */ 199