1199767fToomas Soome/*-
2199767fToomas Soome * Copyright (c) 1982, 1986, 1989, 1993
3199767fToomas Soome *	The Regents of the University of California.  All rights reserved.
4199767fToomas Soome * (c) UNIX System Laboratories, Inc.
5199767fToomas Soome * All or some portions of this file are derived from material licensed
6199767fToomas Soome * to the University of California by American Telephone and Telegraph
7199767fToomas Soome * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8199767fToomas Soome * the permission of UNIX System Laboratories, Inc.
9199767fToomas Soome *
10199767fToomas Soome * Redistribution and use in source and binary forms, with or without
11199767fToomas Soome * modification, are permitted provided that the following conditions
12199767fToomas Soome * are met:
13199767fToomas Soome * 1. Redistributions of source code must retain the above copyright
14199767fToomas Soome *    notice, this list of conditions and the following disclaimer.
15199767fToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
16199767fToomas Soome *    notice, this list of conditions and the following disclaimer in the
17199767fToomas Soome *    documentation and/or other materials provided with the distribution.
18199767fToomas Soome * 4. Neither the name of the University nor the names of its contributors
19199767fToomas Soome *    may be used to endorse or promote products derived from this software
20199767fToomas Soome *    without specific prior written permission.
21199767fToomas Soome *
22199767fToomas Soome * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23199767fToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24199767fToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25199767fToomas Soome * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26199767fToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27199767fToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28199767fToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29199767fToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30199767fToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31199767fToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32199767fToomas Soome * SUCH DAMAGE.
33199767fToomas Soome *
34199767fToomas Soome *	@(#)stat.h	8.12 (Berkeley) 6/16/95
35199767fToomas Soome * $FreeBSD$
36199767fToomas Soome */
37199767fToomas Soome
38199767fToomas Soome#ifndef _SYS_STAT_H_
39199767fToomas Soome#define	_SYS_STAT_H_
40199767fToomas Soome
41199767fToomas Soome#include <sys/cdefs.h>
42199767fToomas Soome#include <sys/_timespec.h>
43199767fToomas Soome#include <sys/_types.h>
44199767fToomas Soome
45199767fToomas Soome#ifndef _BLKSIZE_T_DECLARED
46199767fToomas Soometypedef	__blksize_t	blksize_t;
47199767fToomas Soome#define	_BLKSIZE_T_DECLARED
48199767fToomas Soome#endif
49199767fToomas Soome
50199767fToomas Soome#ifndef _BLKCNT_T_DECLARED
51199767fToomas Soometypedef	__blkcnt_t	blkcnt_t;
52199767fToomas Soome#define	_BLKCNT_T_DECLARED
53199767fToomas Soome#endif
54199767fToomas Soome
55199767fToomas Soome#ifndef _DEV_T_DECLARED
56199767fToomas Soometypedef	__dev_t		dev_t;
57199767fToomas Soome#define	_DEV_T_DECLARED
58199767fToomas Soome#endif
59199767fToomas Soome
60199767fToomas Soome#ifndef _FFLAGS_T_DECLARED
61199767fToomas Soometypedef	__fflags_t	fflags_t;
62199767fToomas Soome#define	_FFLAGS_T_DECLARED
63199767fToomas Soome#endif
64199767fToomas Soome
65199767fToomas Soome#ifndef _GID_T_DECLARED
66199767fToomas Soometypedef	__gid_t		gid_t;
67199767fToomas Soome#define	_GID_T_DECLARED
68199767fToomas Soome#endif
69199767fToomas Soome
70199767fToomas Soome#ifndef _INO_T_DECLARED
71199767fToomas Soometypedef	__ino_t		ino_t;
72199767fToomas Soome#define	_INO_T_DECLARED
73199767fToomas Soome#endif
74199767fToomas Soome
75199767fToomas Soome#ifndef _MODE_T_DECLARED
76199767fToomas Soometypedef	__mode_t	mode_t;
77199767fToomas Soome#define	_MODE_T_DECLARED
78199767fToomas Soome#endif
79199767fToomas Soome
80199767fToomas Soome#ifndef _NLINK_T_DECLARED
81199767fToomas Soometypedef	__nlink_t	nlink_t;
82199767fToomas Soome#define	_NLINK_T_DECLARED
83199767fToomas Soome#endif
84199767fToomas Soome
85199767fToomas Soome#ifndef _OFF_T_DECLARED
86199767fToomas Soometypedef	__off_t		off_t;
87199767fToomas Soome#define	_OFF_T_DECLARED
88199767fToomas Soome#endif
89199767fToomas Soome
90199767fToomas Soome#ifndef _UID_T_DECLARED
91199767fToomas Soometypedef	__uid_t		uid_t;
92199767fToomas Soome#define	_UID_T_DECLARED
93199767fToomas Soome#endif
94199767fToomas Soome
95199767fToomas Soome#if !defined(_KERNEL) && __BSD_VISIBLE
96199767fToomas Soome/*
97199767fToomas Soome * XXX We get miscellaneous namespace pollution with this.
98199767fToomas Soome */
99199767fToomas Soome#include <sys/time.h>
100199767fToomas Soome#endif
101199767fToomas Soome
102199767fToomas Soome#ifdef _KERNEL
103199767fToomas Soomestruct ostat {
104199767fToomas Soome	__uint16_t st_dev;		/* inode's device */
105199767fToomas Soome	ino_t	  st_ino;		/* inode's number */
106199767fToomas Soome	mode_t	  st_mode;		/* inode protection mode */
107199767fToomas Soome	nlink_t	  st_nlink;		/* number of hard links */
108199767fToomas Soome	__uint16_t st_uid;		/* user ID of the file's owner */
109199767fToomas Soome	__uint16_t st_gid;		/* group ID of the file's group */
110199767fToomas Soome	__uint16_t st_rdev;		/* device type */
111199767fToomas Soome	__int32_t st_size;		/* file size, in bytes */
112199767fToomas Soome	struct	timespec st_atim;	/* time of last access */
113199767fToomas Soome	struct	timespec st_mtim;	/* time of last data modification */
114199767fToomas Soome	struct	timespec st_ctim;	/* time of last file status change */
115199767fToomas Soome	__int32_t st_blksize;		/* optimal blocksize for I/O */
116199767fToomas Soome	__int32_t st_blocks;		/* blocks allocated for file */
117199767fToomas Soome	fflags_t  st_flags;		/* user defined flags for file */
118199767fToomas Soome	__uint32_t st_gen;		/* file generation number */
119199767fToomas Soome};
120199767fToomas Soome#endif
121199767fToomas Soome
122199767fToomas Soomestruct stat {
123199767fToomas Soome	__dev_t   st_dev;		/* inode's device */
124199767fToomas Soome	ino_t	  st_ino;		/* inode's number */
125199767fToomas Soome	mode_t	  st_mode;		/* inode protection mode */
126199767fToomas Soome	nlink_t	  st_nlink;		/* number of hard links */
127199767fToomas Soome	uid_t	  st_uid;		/* user ID of the file's owner */
128199767fToomas Soome	gid_t	  st_gid;		/* group ID of the file's group */
129199767fToomas Soome	__dev_t   st_rdev;		/* device type */
130199767fToomas Soome	struct	timespec st_atim;	/* time of last access */
131199767fToomas Soome	struct	timespec st_mtim;	/* time of last data modification */
132199767fToomas Soome	struct	timespec st_ctim;	/* time of last file status change */
133199767fToomas Soome	off_t	  st_size;		/* file size, in bytes */
134199767fToomas Soome	blkcnt_t st_blocks;		/* blocks allocated for file */
135199767fToomas Soome	blksize_t st_blksize;		/* optimal blocksize for I/O */
136199767fToomas Soome	fflags_t  st_flags;		/* user defined flags for file */
137199767fToomas Soome	__uint32_t st_gen;		/* file generation number */
138199767fToomas Soome	__int32_t st_lspare;
139199767fToomas Soome	struct timespec st_birthtim;	/* time of file creation */
140199767fToomas Soome	/*
141199767fToomas Soome	 * Explicitly pad st_birthtim to 16 bytes so that the size of
142199767fToomas Soome	 * struct stat is backwards compatible.  We use bitfields instead
143199767fToomas Soome	 * of an array of chars so that this doesn't require a C99 compiler
144199767fToomas Soome	 * to compile if the size of the padding is 0.  We use 2 bitfields
145199767fToomas Soome	 * to cover up to 64 bits on 32-bit machines.  We assume that
146199767fToomas Soome	 * CHAR_BIT is 8...
147199767fToomas Soome	 */
148199767fToomas Soome	unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
149199767fToomas Soome	unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
150199767fToomas Soome};
151199767fToomas Soome
152199767fToomas Soome#ifdef _KERNEL
153199767fToomas Soomestruct nstat {
154199767fToomas Soome	__dev_t   st_dev;		/* inode's device */
155199767fToomas Soome	ino_t	  st_ino;		/* inode's number */
156199767fToomas Soome	__uint32_t st_mode;		/* inode protection mode */
157199767fToomas Soome	__uint32_t st_nlink;		/* number of hard links */
158199767fToomas Soome	uid_t	  st_uid;		/* user ID of the file's owner */
159199767fToomas Soome	gid_t	  st_gid;		/* group ID of the file's group */
160199767fToomas Soome	__dev_t   st_rdev;		/* device type */
161199767fToomas Soome	struct	timespec st_atim;	/* time of last access */
162199767fToomas Soome	struct	timespec st_mtim;	/* time of last data modification */
163199767fToomas Soome	struct	timespec st_ctim;	/* time of last file status change */
164199767fToomas Soome	off_t	  st_size;		/* file size, in bytes */
165199767fToomas Soome	blkcnt_t st_blocks;		/* blocks allocated for file */
166199767fToomas Soome	blksize_t st_blksize;		/* optimal blocksize for I/O */
167199767fToomas Soome	fflags_t  st_flags;		/* user defined flags for file */
168199767fToomas Soome	__uint32_t st_gen;		/* file generation number */
169199767fToomas Soome	struct timespec st_birthtim;	/* time of file creation */
170199767fToomas Soome	/*
171199767fToomas Soome	 * See above about the following padding.
172199767fToomas Soome	 */
173199767fToomas Soome	unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
174199767fToomas Soome	unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
175199767fToomas Soome};
176199767fToomas Soome#endif
177199767fToomas Soome
178199767fToomas Soome#ifndef _KERNEL
179199767fToomas Soome#define	st_atime		st_atim.tv_sec
180199767fToomas Soome#define	st_mtime		st_mtim.tv_sec
181199767fToomas Soome#define	st_ctime		st_ctim.tv_sec
182199767fToomas Soome#if __BSD_VISIBLE
183199767fToomas Soome#define	st_birthtime		st_birthtim.tv_sec
184199767fToomas Soome#endif
185199767fToomas Soome
186199767fToomas Soome/* For compatibility. */
187199767fToomas Soome#if __BSD_VISIBLE
188199767fToomas Soome#define	st_atimespec		st_atim
189199767fToomas Soome#define	st_mtimespec		st_mtim
190199767fToomas Soome#define	st_ctimespec		st_ctim
191199767fToomas Soome#define	st_birthtimespec	st_birthtim
192199767fToomas Soome#endif
193199767fToomas Soome#endif /* !_KERNEL */
194199767fToomas Soome
195199767fToomas Soome#define	S_ISUID	0004000			/* set user id on execution */
196199767fToomas Soome#define	S_ISGID	0002000			/* set group id on execution */
197199767fToomas Soome#if __BSD_VISIBLE
198199767fToomas Soome#define	S_ISTXT	0001000			/* sticky bit */
199199767fToomas Soome#endif
200199767fToomas Soome
201199767fToomas Soome#define	S_IRWXU	0000700			/* RWX mask for owner */
202199767fToomas Soome#define	S_IRUSR	0000400			/* R for owner */
203199767fToomas Soome#define	S_IWUSR	0000200			/* W for owner */
204199767fToomas Soome#define	S_IXUSR	0000100			/* X for owner */
205199767fToomas Soome
206199767fToomas Soome#if __BSD_VISIBLE
207199767fToomas Soome#define	S_IREAD		S_IRUSR
208199767fToomas Soome#define	S_IWRITE	S_IWUSR
209199767fToomas Soome#define	S_IEXEC		S_IXUSR
210199767fToomas Soome#endif
211199767fToomas Soome
212199767fToomas Soome#define	S_IRWXG	0000070			/* RWX mask for group */
213199767fToomas Soome#define	S_IRGRP	0000040			/* R for group */
214199767fToomas Soome#define	S_IWGRP	0000020			/* W for group */
215199767fToomas Soome#define	S_IXGRP	0000010			/* X for group */
216199767fToomas Soome
217199767fToomas Soome#define	S_IRWXO	0000007			/* RWX mask for other */
218199767fToomas Soome#define	S_IROTH	0000004			/* R for other */
219199767fToomas Soome#define	S_IWOTH	0000002			/* W for other */
220199767fToomas Soome#define	S_IXOTH	0000001			/* X for other */
221199767fToomas Soome
222199767fToomas Soome#if __XSI_VISIBLE
223199767fToomas Soome#define	S_IFMT	 0170000		/* type of file mask */
224199767fToomas Soome#define	S_IFIFO	 0010000		/* named pipe (fifo) */
225199767fToomas Soome#define	S_IFCHR	 0020000		/* character special */
226199767fToomas Soome#define	S_IFDIR	 0040000		/* directory */
227199767fToomas Soome#define	S_IFBLK	 0060000		/* block special */
228199767fToomas Soome#define	S_IFREG	 0100000		/* regular */
229199767fToomas Soome#define	S_IFLNK	 0120000		/* symbolic link */
230199767fToomas Soome#define	S_IFSOCK 0140000		/* socket */
231199767fToomas Soome#define	S_ISVTX	 0001000		/* save swapped text even after use */
232199767fToomas Soome#endif
233199767fToomas Soome#if __BSD_VISIBLE
234199767fToomas Soome#define	S_IFWHT  0160000		/* whiteout */
235199767fToomas Soome#endif
236199767fToomas Soome
237199767fToomas Soome#define	S_ISDIR(m)	(((m) & 0170000) == 0040000)	/* directory */
238199767fToomas Soome#define	S_ISCHR(m)	(((m) & 0170000) == 0020000)	/* char special */
239199767fToomas Soome#define	S_ISBLK(m)	(((m) & 0170000) == 0060000)	/* block special */
240199767fToomas Soome#define	S_ISREG(m)	(((m) & 0170000) == 0100000)	/* regular file */
241199767fToomas Soome#define	S_ISFIFO(m)	(((m) & 0170000) == 0010000)	/* fifo or socket */
242199767fToomas Soome#if __POSIX_VISIBLE >= 200112
243199767fToomas Soome#define	S_ISLNK(m)	(((m) & 0170000) == 0120000)	/* symbolic link */
244199767fToomas Soome#define	S_ISSOCK(m)	(((m) & 0170000) == 0140000)	/* socket */
245199767fToomas Soome#endif
246199767fToomas Soome#if __BSD_VISIBLE
247199767fToomas Soome#define	S_ISWHT(m)	(((m) & 0170000) == 0160000)	/* whiteout */
248199767fToomas Soome#endif
249199767fToomas Soome
250199767fToomas Soome#if __BSD_VISIBLE
251199767fToomas Soome#define	ACCESSPERMS	(S_IRWXU|S_IRWXG|S_IRWXO)	/* 0777 */
252199767fToomas Soome							/* 7777 */
253199767fToomas Soome#define	ALLPERMS	(S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
254199767fToomas Soome							/* 0666 */
255199767fToomas Soome#define	DEFFILEMODE	(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
256199767fToomas Soome
257199767fToomas Soome#define S_BLKSIZE	512		/* block size used in the stat struct */
258199767fToomas Soome
259199767fToomas Soome/*
260199767fToomas Soome * Definitions of flags stored in file flags word.
261199767fToomas Soome *
262199767fToomas Soome * Super-user and owner changeable flags.
263199767fToomas Soome */
264199767fToomas Soome#define	UF_SETTABLE	0x0000ffff	/* mask of owner changeable flags */
265199767fToomas Soome#define	UF_NODUMP	0x00000001	/* do not dump file */
266199767fToomas Soome#define	UF_IMMUTABLE	0x00000002	/* file may not be changed */
267199767fToomas Soome#define	UF_APPEND	0x00000004	/* writes to file may only append */
268199767fToomas Soome#define	UF_OPAQUE	0x00000008	/* directory is opaque wrt. union */
269199767fToomas Soome#define	UF_NOUNLINK	0x00000010	/* file may not be removed or renamed */
270199767fToomas Soome/*
271199767fToomas Soome * These two bits are defined in MacOS X.  They are not currently used in
272199767fToomas Soome * FreeBSD.
273199767fToomas Soome */
274199767fToomas Soome#if 0
275199767fToomas Soome#define	UF_COMPRESSED	0x00000020	/* file is compressed */
276199767fToomas Soome#define	UF_TRACKED	0x00000040	/* renames and deletes are tracked */
277199767fToomas Soome#endif
278199767fToomas Soome
279199767fToomas Soome#define	UF_SYSTEM	0x00000080	/* Windows system file bit */
280199767fToomas Soome#define	UF_SPARSE	0x00000100	/* sparse file */
281199767fToomas Soome#define	UF_OFFLINE	0x00000200	/* file is offline */
282199767fToomas Soome#define	UF_REPARSE	0x00000400	/* Windows reparse point file bit */
283199767fToomas Soome#define	UF_ARCHIVE	0x00000800	/* file needs to be archived */
284199767fToomas Soome#define	UF_READONLY	0x00001000	/* Windows readonly file bit */
285199767fToomas Soome/* This is the same as the MacOS X definition of UF_HIDDEN. */
286199767fToomas Soome#define	UF_HIDDEN	0x00008000	/* file is hidden */
287199767fToomas Soome
288199767fToomas Soome/*
289199767fToomas Soome * Super-user changeable flags.
290199767fToomas Soome */
291199767fToomas Soome#define	SF_SETTABLE	0xffff0000	/* mask of superuser changeable flags */
292199767fToomas Soome#define	SF_ARCHIVED	0x00010000	/* file is archived */
293199767fToomas Soome#define	SF_IMMUTABLE	0x00020000	/* file may not be changed */
294199767fToomas Soome#define	SF_APPEND	0x00040000	/* writes to file may only append */
295199767fToomas Soome#define	SF_NOUNLINK	0x00100000	/* file may not be removed or renamed */
296199767fToomas Soome#define	SF_SNAPSHOT	0x00200000	/* snapshot inode */
297199767fToomas Soome
298199767fToomas Soome#ifdef _KERNEL
299199767fToomas Soome/*
300199767fToomas Soome * Shorthand abbreviations of above.
301199767fToomas Soome */
302199767fToomas Soome#define	OPAQUE		(UF_OPAQUE)
303199767fToomas Soome#define	APPEND		(UF_APPEND | SF_APPEND)
304199767fToomas Soome#define	IMMUTABLE	(UF_IMMUTABLE | SF_IMMUTABLE)
305199767fToomas Soome#define	NOUNLINK	(UF_NOUNLINK | SF_NOUNLINK)
306199767fToomas Soome#endif
307199767fToomas Soome
308199767fToomas Soome#endif /* __BSD_VISIBLE */
309199767fToomas Soome
310199767fToomas Soome#if __POSIX_VISIBLE >= 200809
311199767fToomas Soome#define	UTIME_NOW	-1
312199767fToomas Soome#define	UTIME_OMIT	-2
313199767fToomas Soome#endif
314199767fToomas Soome
315199767fToomas Soome#ifndef _KERNEL
316199767fToomas Soome__BEGIN_DECLS
317199767fToomas Soome#if __BSD_VISIBLE
318199767fToomas Soomeint	chflags(const char *, unsigned long);
319199767fToomas Soomeint	chflagsat(int, const char *, unsigned long, int);
320199767fToomas Soome#endif
321199767fToomas Soomeint	chmod(const char *, mode_t);
322199767fToomas Soome#if __BSD_VISIBLE
323199767fToomas Soomeint	fchflags(int, unsigned long);
324199767fToomas Soome#endif
325199767fToomas Soome#if __POSIX_VISIBLE >= 200112
326199767fToomas Soomeint	fchmod(int, mode_t);
327199767fToomas Soome#endif
328199767fToomas Soome#if __POSIX_VISIBLE >= 200809
329199767fToomas Soomeint	fchmodat(int, const char *, mode_t, int);
330199767fToomas Soomeint	futimens(int fd, const struct timespec times[2]);
331199767fToomas Soomeint	utimensat(int fd, const char *path, const struct timespec times[2],
332199767fToomas Soome		int flag);
333199767fToomas Soome#endif
334199767fToomas Soomeint	fstat(int, struct stat *);
335199767fToomas Soome#if __BSD_VISIBLE
336199767fToomas Soomeint	lchflags(const char *, unsigned long);
337199767fToomas Soomeint	lchmod(const char *, mode_t);
338199767fToomas Soome#endif
339199767fToomas Soome#if __POSIX_VISIBLE >= 200112
340199767fToomas Soomeint	lstat(const char * __restrict, struct stat * __restrict);
341199767fToomas Soome#endif
342199767fToomas Soomeint	mkdir(const char *, mode_t);
343199767fToomas Soomeint	mkfifo(const char *, mode_t);
344199767fToomas Soome#if !defined(_MKNOD_DECLARED) && __XSI_VISIBLE
345199767fToomas Soomeint	mknod(const char *, mode_t, dev_t);
346199767fToomas Soome#define	_MKNOD_DECLARED
347199767fToomas Soome#endif
348199767fToomas Soomeint	stat(const char * __restrict, struct stat * __restrict);
349199767fToomas Soomemode_t	umask(mode_t);
350199767fToomas Soome#if __POSIX_VISIBLE >= 200809
351199767fToomas Soomeint	fstatat(int, const char *, struct stat *, int);
352199767fToomas Soomeint	mkdirat(int, const char *, mode_t);
353199767fToomas Soomeint	mkfifoat(int, const char *, mode_t);
354199767fToomas Soome#endif
355199767fToomas Soome#if __XSI_VISIBLE >= 700
356199767fToomas Soomeint	mknodat(int, const char *, mode_t, dev_t);
357199767fToomas Soome#endif
358199767fToomas Soome__END_DECLS
359199767fToomas Soome#endif /* !_KERNEL */
360199767fToomas Soome
361199767fToomas Soome#endif /* !_SYS_STAT_H_ */
362