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