xref: /dragonfly/sys/sys/stat.h (revision 5ca0a96d)
1 /*-
2  * Copyright (c) 1982, 1986, 1989, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  * (c) UNIX System Laboratories, Inc.
5  * All or some portions of this file are derived from material licensed
6  * to the University of California by American Telephone and Telegraph
7  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8  * the permission of UNIX System Laboratories, Inc.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  *	@(#)stat.h	8.12 (Berkeley) 6/16/95
35  * $FreeBSD: src/sys/sys/stat.h,v 1.20 1999/12/29 04:24:47 peter Exp $
36  */
37 
38 #ifndef _SYS_STAT_H_
39 #define	_SYS_STAT_H_
40 
41 #include <sys/cdefs.h>
42 #include <sys/types.h>
43 
44 #if !defined(_KERNEL) && __BSD_VISIBLE
45 /*
46  * XXX We get miscellaneous namespace pollution with this.
47  */
48 #include <sys/time.h>
49 #else
50 #include <sys/_timespec.h>
51 #endif
52 
53 struct stat {
54 	ino_t		st_ino;		/* inode's number */
55 	nlink_t		st_nlink;	/* number of hard links */
56 	dev_t		st_dev;		/* inode's device */
57 	mode_t		st_mode;	/* inode protection mode */
58 	uint16_t	st_padding1;
59 	uid_t		st_uid;		/* user ID of the file's owner */
60 	gid_t		st_gid;		/* group ID of the file's group */
61 	dev_t		st_rdev;		/* device type */
62 	struct timespec	st_atim;	/* time of last access */
63 	struct timespec	st_mtim;	/* time of last data modification */
64 	struct timespec	st_ctim;	/* time of last file status change */
65 	off_t		st_size;	/* file size, in bytes */
66 	blkcnt_t	st_blocks;	/* blocks allocated for file */
67 	u_int32_t	__old_st_blksize; /* old ABI compatibility only */
68 	u_int32_t	st_flags;	/* user defined flags for file */
69 	u_int32_t	st_gen;		/* file generation number */
70 	int32_t		st_lspare;
71 	blksize_t	st_blksize;	/* optimal blocksize for I/O */
72 	int64_t		st_qspare2;
73 };
74 
75 #define	_ST_FLAGS_PRESENT_
76 
77 #define	st_atime st_atim.tv_sec
78 #define	st_mtime st_mtim.tv_sec
79 #define	st_ctime st_ctim.tv_sec
80 
81 /* BSD compatibility */
82 #if __BSD_VISIBLE
83 #define	st_atimespec st_atim
84 #define	st_mtimespec st_mtim
85 #define	st_ctimespec st_ctim
86 #endif
87 
88 /* Always ensure that these are consistent with <fcntl.h>! */
89 #ifndef S_ISUID
90 #define	S_ISUID	0004000			/* set user id on execution */
91 #endif
92 #ifndef S_ISGID
93 #define	S_ISGID	0002000			/* set group id on execution */
94 #endif
95 #if __BSD_VISIBLE
96 #define	S_ISTXT	0001000			/* sticky bit */
97 #endif
98 
99 #ifndef S_IRWXU
100 #define	S_IRWXU	0000700			/* RWX mask for owner */
101 #endif
102 #ifndef S_IRUSR
103 #define	S_IRUSR	0000400			/* R for owner */
104 #endif
105 #ifndef S_IWUSR
106 #define	S_IWUSR	0000200			/* W for owner */
107 #endif
108 #ifndef S_IXUSR
109 #define	S_IXUSR	0000100			/* X for owner */
110 #endif
111 
112 #if __BSD_VISIBLE
113 #define	S_IREAD		S_IRUSR
114 #define	S_IWRITE	S_IWUSR
115 #define	S_IEXEC		S_IXUSR
116 #endif
117 
118 #ifndef S_IRWXG
119 #define	S_IRWXG	0000070			/* RWX mask for group */
120 #endif
121 #ifndef S_IRGRP
122 #define	S_IRGRP	0000040			/* R for group */
123 #endif
124 #ifndef S_IWGRP
125 #define	S_IWGRP	0000020			/* W for group */
126 #endif
127 #ifndef S_IXGRP
128 #define	S_IXGRP	0000010			/* X for group */
129 #endif
130 
131 #ifndef S_IRWXO
132 #define	S_IRWXO	0000007			/* RWX mask for other */
133 #endif
134 #ifndef S_IROTH
135 #define	S_IROTH	0000004			/* R for other */
136 #endif
137 #ifndef S_IWOTH
138 #define	S_IWOTH	0000002			/* W for other */
139 #endif
140 #ifndef S_IXOTH
141 #define	S_IXOTH	0000001			/* X for other */
142 #endif
143 
144 #if __XSI_VISIBLE
145 #define	S_IFMT	 0170000		/* type of file mask */
146 #define	S_IFIFO	 0010000		/* named pipe (fifo) */
147 #define	S_IFCHR	 0020000		/* character special */
148 #define	S_IFDIR	 0040000		/* directory */
149 #define	S_IFBLK	 0060000		/* block special */
150 #define	S_IFREG	 0100000		/* regular */
151 #define	S_IFLNK	 0120000		/* symbolic link */
152 #define	S_IFSOCK 0140000		/* socket */
153 #define	S_ISVTX	 0001000		/* save swapped text even after use */
154 #endif
155 #if __BSD_VISIBLE
156 #define	S_IFDB	 0110000		/* record access file */
157 #define	S_IFWHT  0160000		/* whiteout */
158 #endif
159 
160 #define	S_ISDIR(m)	(((m) & 0170000) == 0040000)	/* directory */
161 #define	S_ISCHR(m)	(((m) & 0170000) == 0020000)	/* char special */
162 #define	S_ISBLK(m)	(((m) & 0170000) == 0060000)	/* block special */
163 #define	S_ISREG(m)	(((m) & 0170000) == 0100000)	/* regular file */
164 #define	S_ISDB(m)	(((m) & 0170000) == 0110000)	/* record access file */
165 #define	S_ISFIFO(m)	(((m) & 0170000) == 0010000)	/* fifo or socket */
166 #if __POSIX_VISIBLE
167 #define	S_ISLNK(m)	(((m) & 0170000) == 0120000)	/* symbolic link */
168 #define	S_ISSOCK(m)	(((m) & 0170000) == 0140000)	/* socket */
169 #endif
170 #if __BSD_VISIBLE
171 #define	S_ISWHT(m)	(((m) & 0170000) == 0160000)	/* whiteout */
172 #endif
173 
174 /*
175  * The value of `buf' is a pointer to a `stat' data structure. Since we don't
176  * implement message queues, semaphores, and shared memory objects as distinct
177  * file types, the following macros evaluate to zero.
178  *
179  * XXX: Add S_TYPEISTMO() once we grow support for POSIX typed memory objects.
180  */
181 #define	S_TYPEISMQ(buf)		(0)	/* message queue */
182 #define	S_TYPEISSEM(buf)	(0)	/* semaphore */
183 #define	S_TYPEISSHM(buf)	(0)	/* shared memory object */
184 
185 #if __BSD_VISIBLE
186 #define	ACCESSPERMS	(S_IRWXU|S_IRWXG|S_IRWXO)	/* 0777 */
187 							/* 7777 */
188 #define	ALLPERMS	(S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
189 							/* 0666 */
190 #define	DEFFILEMODE	(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
191 
192 #define	S_BLKSIZE	512		/* block size used in the stat struct */
193 
194 /*
195  * Definitions of flags stored in file flags word.
196  *
197  * Super-user and owner changeable flags.
198  */
199 #define	UF_SETTABLE	0x0000ffff	/* mask of owner changeable flags */
200 #define	UF_NODUMP	0x00000001	/* do not dump file */
201 #define	UF_IMMUTABLE	0x00000002	/* file may not be changed */
202 #define	UF_APPEND	0x00000004	/* writes to file may only append */
203 #define	UF_OPAQUE	0x00000008	/* directory is opaque wrt. union */
204 #define	UF_NOUNLINK	0x00000010	/* file may not be removed or renamed */
205 #define	UF_UNUSED5	0x00000020	/* (unused) */
206 #define	UF_NOHISTORY	0x00000040	/* do not retain history/snapshots */
207 #define	UF_CACHE	0x00000080	/* enable data swapcache */
208 #define	UF_XLINK	0x00000100	/* cross-link (hardlink) boundary */
209 
210 /*
211  * Super-user changeable flags.
212  */
213 #define	SF_SETTABLE	0xffff0000	/* mask of superuser changeable flags */
214 #define	SF_ARCHIVED	0x00010000	/* file is archived */
215 #define	SF_IMMUTABLE	0x00020000	/* file may not be changed */
216 #define	SF_APPEND	0x00040000	/* writes to file may only append */
217 #define	SF_NOUNLINK	0x00100000	/* file may not be removed or renamed */
218 #define	SF_UNUSED17	0x00200000	/* (used by FreeBSD for snapshots) */
219 #define	SF_NOHISTORY	0x00400000	/* do not retain history/snapshots */
220 #define	SF_NOCACHE	0x00800000	/* disable data swapcache */
221 #define	SF_XLINK	0x01000000	/* cross-link (hardlink) boundary */
222 
223 #ifdef _KERNEL
224 /*
225  * Shorthand abbreviations of above.
226  */
227 #define	OPAQUE		(UF_OPAQUE)
228 #define	APPEND		(UF_APPEND | SF_APPEND)
229 #define	IMMUTABLE	(UF_IMMUTABLE | SF_IMMUTABLE)
230 #define	NOUNLINK	(UF_NOUNLINK | SF_NOUNLINK)
231 #endif
232 
233 #endif /* __BSD_VISIBLE */
234 
235 #if __POSIX_VISIBLE >= 200809
236 #define	UTIME_NOW	-1
237 #define	UTIME_OMIT	-2
238 #endif
239 
240 #if !defined(_KERNEL) || defined(_KERNEL_VIRTUAL)
241 
242 __BEGIN_DECLS
243 int	chmod(const char *, mode_t);
244 int	fchmod(int, mode_t);
245 #if __POSIX_VISIBLE >= 200809
246 int	fchmodat(int, const char *, mode_t, int);
247 int	futimens(int, const struct timespec *);
248 int	utimensat(int, const char *, const struct timespec *, int);
249 #endif
250 int	fstat(int, struct stat *);
251 #if __POSIX_VISIBLE >= 199506
252 int	lstat(const char * __restrict, struct stat * __restrict);
253 #endif
254 int	mkdir(const char *, mode_t);
255 int	mkfifo(const char *, mode_t);
256 #if !defined(_MKNOD_DECLARED) && __XSI_VISIBLE
257 int	mknod(const char *, mode_t, dev_t);
258 #define	_MKNOD_DECLARED
259 #endif
260 int	stat(const char * __restrict, struct stat * __restrict);
261 mode_t	umask(mode_t);
262 #if __POSIX_VISIBLE >= 200809
263 int	fstatat(int, const char * __restrict, struct stat * __restrict, int);
264 int	mkdirat(int, const char *, mode_t);
265 int	mkfifoat(int, const char *, mode_t);
266 #endif
267 #if __XSI_VISIBLE >= 700
268 int	mknodat(int, const char *, mode_t, dev_t);
269 #endif
270 #if __BSD_VISIBLE
271 int	chflags(const char *, unsigned long);
272 int	fchflags(int, unsigned long);
273 int	lchflags(const char *, unsigned long);
274 int	chflagsat(int, const char *, unsigned long, int);
275 int	lchmod(const char *, mode_t);
276 #endif
277 __END_DECLS
278 
279 #endif
280 
281 #endif /* !_SYS_STAT_H_ */
282