xref: /dragonfly/sys/sys/stat.h (revision d960c16f)
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 <machine/stdint.h>
43 
44 #if !defined(_KERNEL) && __BSD_VISIBLE
45 #include <sys/time.h>
46 #else
47 #include <sys/_timespec.h>
48 #endif
49 
50 #ifndef _BLKCNT_T_DECLARED
51 typedef	__int64_t	blkcnt_t;	/* file block count */
52 #define	_BLKCNT_T_DECLARED
53 #endif
54 
55 #ifndef _BLKSIZE_T_DECLARED
56 typedef	__int64_t	blksize_t;	/* block size */
57 #define	_BLKSIZE_T_DECLARED
58 #endif
59 
60 #ifndef _DEV_T_DECLARED
61 typedef	__uint32_t	dev_t;		/* device number */
62 #define	_DEV_T_DECLARED
63 #endif
64 
65 #ifndef _GID_T_DECLARED
66 typedef	__uint32_t	gid_t;		/* group id */
67 #define	_GID_T_DECLARED
68 #endif
69 
70 #ifndef _INO_T_DECLARED
71 typedef	__uint64_t	ino_t;		/* inode number */
72 #define	_INO_T_DECLARED
73 #endif
74 
75 #ifndef _MODE_T_DECLARED
76 typedef	__uint16_t	mode_t;		/* permissions */
77 #define	_MODE_T_DECLARED
78 #endif
79 
80 #ifndef _NLINK_T_DECLARED
81 typedef	__uint32_t	nlink_t;	/* link count */
82 #define	_NLINK_T_DECLARED
83 #endif
84 
85 #ifndef _OFF_T_DECLARED
86 typedef	__off_t		off_t;		/* file offset */
87 #define	_OFF_T_DECLARED
88 #endif
89 
90 #ifndef _TIME_T_DECLARED
91 typedef	__time_t	time_t;
92 #define	_TIME_T_DECLARED
93 #endif
94 
95 #ifndef _UID_T_DECLARED
96 typedef	__uint32_t	uid_t;		/* user id */
97 #define	_UID_T_DECLARED
98 #endif
99 
100 struct stat {
101 	ino_t		st_ino;		/* inode's number */
102 	nlink_t		st_nlink;	/* number of hard links */
103 	dev_t		st_dev;		/* inode's device */
104 	mode_t		st_mode;	/* inode protection mode */
105 	__uint16_t	st_padding1;
106 	uid_t		st_uid;		/* user ID of the file's owner */
107 	gid_t		st_gid;		/* group ID of the file's group */
108 	dev_t		st_rdev;	/* device type */
109 	struct timespec	st_atim;	/* time of last access */
110 	struct timespec	st_mtim;	/* time of last data modification */
111 	struct timespec	st_ctim;	/* time of last file status change */
112 	off_t		st_size;	/* file size, in bytes */
113 	blkcnt_t	st_blocks;	/* blocks allocated for file */
114 	__uint32_t	__old_st_blksize; /* old ABI compatibility only */
115 	__uint32_t	st_flags;	/* user defined flags for file */
116 	__uint32_t	st_gen;		/* file generation number */
117 	__int32_t	st_lspare;
118 	blksize_t	st_blksize;	/* optimal blocksize for I/O */
119 	__int64_t	st_qspare2;
120 };
121 
122 #define	_ST_FLAGS_PRESENT_
123 
124 #define	st_atime st_atim.tv_sec
125 #define	st_mtime st_mtim.tv_sec
126 #define	st_ctime st_ctim.tv_sec
127 
128 /* BSD compatibility */
129 #if __BSD_VISIBLE
130 #define	st_atimespec st_atim
131 #define	st_mtimespec st_mtim
132 #define	st_ctimespec st_ctim
133 #endif
134 
135 /* Always ensure that these are consistent with <fcntl.h>! */
136 #ifndef S_ISUID
137 #define	S_ISUID	0004000			/* set user id on execution */
138 #endif
139 #ifndef S_ISGID
140 #define	S_ISGID	0002000			/* set group id on execution */
141 #endif
142 #if __BSD_VISIBLE
143 #define	S_ISTXT	0001000			/* sticky bit */
144 #endif
145 
146 #ifndef S_IRWXU
147 #define	S_IRWXU	0000700			/* RWX mask for owner */
148 #endif
149 #ifndef S_IRUSR
150 #define	S_IRUSR	0000400			/* R for owner */
151 #endif
152 #ifndef S_IWUSR
153 #define	S_IWUSR	0000200			/* W for owner */
154 #endif
155 #ifndef S_IXUSR
156 #define	S_IXUSR	0000100			/* X for owner */
157 #endif
158 
159 #if __BSD_VISIBLE
160 #define	S_IREAD		S_IRUSR
161 #define	S_IWRITE	S_IWUSR
162 #define	S_IEXEC		S_IXUSR
163 #endif
164 
165 #ifndef S_IRWXG
166 #define	S_IRWXG	0000070			/* RWX mask for group */
167 #endif
168 #ifndef S_IRGRP
169 #define	S_IRGRP	0000040			/* R for group */
170 #endif
171 #ifndef S_IWGRP
172 #define	S_IWGRP	0000020			/* W for group */
173 #endif
174 #ifndef S_IXGRP
175 #define	S_IXGRP	0000010			/* X for group */
176 #endif
177 
178 #ifndef S_IRWXO
179 #define	S_IRWXO	0000007			/* RWX mask for other */
180 #endif
181 #ifndef S_IROTH
182 #define	S_IROTH	0000004			/* R for other */
183 #endif
184 #ifndef S_IWOTH
185 #define	S_IWOTH	0000002			/* W for other */
186 #endif
187 #ifndef S_IXOTH
188 #define	S_IXOTH	0000001			/* X for other */
189 #endif
190 
191 #if __XSI_VISIBLE
192 #define	S_IFMT	 0170000		/* type of file mask */
193 #define	S_IFIFO	 0010000		/* named pipe (fifo) */
194 #define	S_IFCHR	 0020000		/* character special */
195 #define	S_IFDIR	 0040000		/* directory */
196 #define	S_IFBLK	 0060000		/* block special */
197 #define	S_IFREG	 0100000		/* regular */
198 #define	S_IFLNK	 0120000		/* symbolic link */
199 #define	S_IFSOCK 0140000		/* socket */
200 #define	S_ISVTX	 0001000		/* save swapped text even after use */
201 #endif
202 #if __BSD_VISIBLE
203 #define	S_IFDB	 0110000		/* record access file */
204 #define	S_IFWHT  0160000		/* whiteout */
205 #endif
206 
207 #define	S_ISDIR(m)	(((m) & 0170000) == 0040000)	/* directory */
208 #define	S_ISCHR(m)	(((m) & 0170000) == 0020000)	/* char special */
209 #define	S_ISBLK(m)	(((m) & 0170000) == 0060000)	/* block special */
210 #define	S_ISREG(m)	(((m) & 0170000) == 0100000)	/* regular file */
211 #define	S_ISDB(m)	(((m) & 0170000) == 0110000)	/* record access file */
212 #define	S_ISFIFO(m)	(((m) & 0170000) == 0010000)	/* fifo or socket */
213 #if __POSIX_VISIBLE
214 #define	S_ISLNK(m)	(((m) & 0170000) == 0120000)	/* symbolic link */
215 #define	S_ISSOCK(m)	(((m) & 0170000) == 0140000)	/* socket */
216 #endif
217 #if __BSD_VISIBLE
218 #define	S_ISWHT(m)	(((m) & 0170000) == 0160000)	/* whiteout */
219 #endif
220 
221 /*
222  * The value of `buf' is a pointer to a `stat' data structure. Since we don't
223  * implement message queues, semaphores, and shared memory objects as distinct
224  * file types, the following macros evaluate to zero.
225  *
226  * XXX: Add S_TYPEISTMO() once we grow support for POSIX typed memory objects.
227  */
228 #define	S_TYPEISMQ(buf)		(0)	/* message queue */
229 #define	S_TYPEISSEM(buf)	(0)	/* semaphore */
230 #define	S_TYPEISSHM(buf)	(0)	/* shared memory object */
231 
232 #if __BSD_VISIBLE
233 #define	ACCESSPERMS	(S_IRWXU|S_IRWXG|S_IRWXO)	/* 0777 */
234 							/* 7777 */
235 #define	ALLPERMS	(S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
236 							/* 0666 */
237 #define	DEFFILEMODE	(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
238 
239 #define	S_BLKSIZE	512		/* block size used in the stat struct */
240 
241 /*
242  * Definitions of flags stored in file flags word.
243  *
244  * Super-user and owner changeable flags.
245  */
246 #define	UF_SETTABLE	0x0000ffff	/* mask of owner changeable flags */
247 #define	UF_NODUMP	0x00000001	/* do not dump file */
248 #define	UF_IMMUTABLE	0x00000002	/* file may not be changed */
249 #define	UF_APPEND	0x00000004	/* writes to file may only append */
250 #define	UF_OPAQUE	0x00000008	/* directory is opaque wrt. union */
251 #define	UF_NOUNLINK	0x00000010	/* file may not be removed or renamed */
252 #define	UF_UNUSED5	0x00000020	/* (unused) */
253 #define	UF_NOHISTORY	0x00000040	/* do not retain history/snapshots */
254 #define	UF_CACHE	0x00000080	/* enable data swapcache */
255 #define	UF_XLINK	0x00000100	/* cross-link (hardlink) boundary */
256 
257 /*
258  * Super-user changeable flags.
259  */
260 #define	SF_SETTABLE	0xffff0000	/* mask of superuser changeable flags */
261 #define	SF_ARCHIVED	0x00010000	/* file is archived */
262 #define	SF_IMMUTABLE	0x00020000	/* file may not be changed */
263 #define	SF_APPEND	0x00040000	/* writes to file may only append */
264 #define	SF_NOUNLINK	0x00100000	/* file may not be removed or renamed */
265 #define	SF_UNUSED17	0x00200000	/* (used by FreeBSD for snapshots) */
266 #define	SF_NOHISTORY	0x00400000	/* do not retain history/snapshots */
267 #define	SF_NOCACHE	0x00800000	/* disable data swapcache */
268 #define	SF_XLINK	0x01000000	/* cross-link (hardlink) boundary */
269 
270 #ifdef _KERNEL
271 /*
272  * Shorthand abbreviations of above.
273  */
274 #define	OPAQUE		(UF_OPAQUE)
275 #define	APPEND		(UF_APPEND | SF_APPEND)
276 #define	IMMUTABLE	(UF_IMMUTABLE | SF_IMMUTABLE)
277 #define	NOUNLINK	(UF_NOUNLINK | SF_NOUNLINK)
278 #endif
279 
280 #endif /* __BSD_VISIBLE */
281 
282 #if __POSIX_VISIBLE >= 200809
283 #define	UTIME_NOW	-1
284 #define	UTIME_OMIT	-2
285 #endif
286 
287 #if !defined(_KERNEL) || defined(_KERNEL_VIRTUAL)
288 
289 __BEGIN_DECLS
290 int	chmod(const char *, mode_t);
291 int	fchmod(int, mode_t);
292 #if __POSIX_VISIBLE >= 200809
293 int	fchmodat(int, const char *, mode_t, int);
294 int	futimens(int, const struct timespec *);
295 int	utimensat(int, const char *, const struct timespec *, int);
296 #endif
297 int	fstat(int, struct stat *);
298 #if __POSIX_VISIBLE >= 199506
299 int	lstat(const char * __restrict, struct stat * __restrict);
300 #endif
301 int	mkdir(const char *, mode_t);
302 int	mkfifo(const char *, mode_t);
303 #if !defined(_MKNOD_DECLARED) && __XSI_VISIBLE
304 int	mknod(const char *, mode_t, dev_t);
305 #define	_MKNOD_DECLARED
306 #endif
307 int	stat(const char * __restrict, struct stat * __restrict);
308 mode_t	umask(mode_t);
309 #if __POSIX_VISIBLE >= 200809
310 int	fstatat(int, const char * __restrict, struct stat * __restrict, int);
311 int	mkdirat(int, const char *, mode_t);
312 int	mkfifoat(int, const char *, mode_t);
313 #endif
314 #if __XSI_VISIBLE >= 700
315 int	mknodat(int, const char *, mode_t, dev_t);
316 #endif
317 #if __BSD_VISIBLE
318 int	chflags(const char *, unsigned long);
319 int	fchflags(int, unsigned long);
320 int	lchflags(const char *, unsigned long);
321 int	chflagsat(int, const char *, unsigned long, int);
322 int	lchmod(const char *, mode_t);
323 #endif
324 __END_DECLS
325 
326 #endif
327 
328 #endif /* !_SYS_STAT_H_ */
329