xref: /original-bsd/sys/sys/stat.h (revision 94a4c615)
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  * %sccs.include.redist.c%
11  *
12  *	@(#)stat.h	8.12 (Berkeley) 06/16/95
13  */
14 
15 #ifndef _SYS_STAT_H_
16 #define	_SYS_STAT_H_
17 
18 #include <sys/time.h>
19 
20 #ifndef _POSIX_SOURCE
21 struct ostat {
22 	u_int16_t st_dev;		/* inode's device */
23 	ino_t	  st_ino;		/* inode's number */
24 	mode_t	  st_mode;		/* inode protection mode */
25 	nlink_t	  st_nlink;		/* number of hard links */
26 	u_int16_t st_uid;		/* user ID of the file's owner */
27 	u_int16_t st_gid;		/* group ID of the file's group */
28 	u_int16_t st_rdev;		/* device type */
29 	int32_t	  st_size;		/* file size, in bytes */
30 	struct	timespec st_atimespec;	/* time of last access */
31 	struct	timespec st_mtimespec;	/* time of last data modification */
32 	struct	timespec st_ctimespec;	/* time of last file status change */
33 	int32_t	  st_blksize;		/* optimal blocksize for I/O */
34 	int32_t	  st_blocks;		/* blocks allocated for file */
35 	u_int32_t st_flags;		/* user defined flags for file */
36 	u_int32_t st_gen;		/* file generation number */
37 };
38 #endif /* !_POSIX_SOURCE */
39 
40 struct stat {
41 	dev_t	  st_dev;		/* inode's device */
42 	ino_t	  st_ino;		/* inode's number */
43 	mode_t	  st_mode;		/* inode protection mode */
44 	nlink_t	  st_nlink;		/* number of hard links */
45 	uid_t	  st_uid;		/* user ID of the file's owner */
46 	gid_t	  st_gid;		/* group ID of the file's group */
47 	dev_t	  st_rdev;		/* device type */
48 #ifndef _POSIX_SOURCE
49 	struct	timespec st_atimespec;	/* time of last access */
50 	struct	timespec st_mtimespec;	/* time of last data modification */
51 	struct	timespec st_ctimespec;	/* time of last file status change */
52 #else
53 	time_t	  st_atime;		/* time of last access */
54 	long	  st_atimensec;		/* nsec of last access */
55 	time_t	  st_mtime;		/* time of last data modification */
56 	long	  st_mtimensec;		/* nsec of last data modification */
57 	time_t	  st_ctime;		/* time of last file status change */
58 	long	  st_ctimensec;		/* nsec of last file status change */
59 #endif
60 	off_t	  st_size;		/* file size, in bytes */
61 	int64_t	  st_blocks;		/* blocks allocated for file */
62 	u_int32_t st_blksize;		/* optimal blocksize for I/O */
63 	u_int32_t st_flags;		/* user defined flags for file */
64 	u_int32_t st_gen;		/* file generation number */
65 	int32_t	  st_lspare;
66 	int64_t	  st_qspare[2];
67 };
68 #ifndef _POSIX_SOURCE
69 #define st_atime st_atimespec.ts_sec
70 #define st_mtime st_mtimespec.ts_sec
71 #define st_ctime st_ctimespec.ts_sec
72 #endif
73 
74 #define	S_ISUID	0004000			/* set user id on execution */
75 #define	S_ISGID	0002000			/* set group id on execution */
76 #ifndef _POSIX_SOURCE
77 #define	S_ISTXT	0001000			/* sticky bit */
78 #endif
79 
80 #define	S_IRWXU	0000700			/* RWX mask for owner */
81 #define	S_IRUSR	0000400			/* R for owner */
82 #define	S_IWUSR	0000200			/* W for owner */
83 #define	S_IXUSR	0000100			/* X for owner */
84 
85 #ifndef _POSIX_SOURCE
86 #define	S_IREAD		S_IRUSR
87 #define	S_IWRITE	S_IWUSR
88 #define	S_IEXEC		S_IXUSR
89 #endif
90 
91 #define	S_IRWXG	0000070			/* RWX mask for group */
92 #define	S_IRGRP	0000040			/* R for group */
93 #define	S_IWGRP	0000020			/* W for group */
94 #define	S_IXGRP	0000010			/* X for group */
95 
96 #define	S_IRWXO	0000007			/* RWX mask for other */
97 #define	S_IROTH	0000004			/* R for other */
98 #define	S_IWOTH	0000002			/* W for other */
99 #define	S_IXOTH	0000001			/* X for other */
100 
101 #ifndef _POSIX_SOURCE
102 #define	S_IFMT	 0170000		/* type of file mask */
103 #define	S_IFIFO	 0010000		/* named pipe (fifo) */
104 #define	S_IFCHR	 0020000		/* character special */
105 #define	S_IFDIR	 0040000		/* directory */
106 #define	S_IFBLK	 0060000		/* block special */
107 #define	S_IFREG	 0100000		/* regular */
108 #define	S_IFLNK	 0120000		/* symbolic link */
109 #define	S_IFSOCK 0140000		/* socket */
110 #define	S_IFWHT  0160000		/* whiteout */
111 #define	S_ISVTX	 0001000		/* save swapped text even after use */
112 #endif
113 
114 #define	S_ISDIR(m)	((m & 0170000) == 0040000)	/* directory */
115 #define	S_ISCHR(m)	((m & 0170000) == 0020000)	/* char special */
116 #define	S_ISBLK(m)	((m & 0170000) == 0060000)	/* block special */
117 #define	S_ISREG(m)	((m & 0170000) == 0100000)	/* regular file */
118 #define	S_ISFIFO(m)	((m & 0170000) == 0010000 || \
119 			 (m & 0170000) == 0140000)	/* fifo or socket */
120 #ifndef _POSIX_SOURCE
121 #define	S_ISLNK(m)	((m & 0170000) == 0120000)	/* symbolic link */
122 #define	S_ISSOCK(m)	((m & 0170000) == 0010000 || \
123 			 (m & 0170000) == 0140000)	/* fifo or socket */
124 #define	S_ISWHT(m)	((m & 0170000) == 0160000)	/* whiteout */
125 #endif
126 
127 #ifndef _POSIX_SOURCE
128 #define	ACCESSPERMS	(S_IRWXU|S_IRWXG|S_IRWXO)	/* 0777 */
129 							/* 7777 */
130 #define	ALLPERMS	(S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
131 							/* 0666 */
132 #define	DEFFILEMODE	(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
133 
134 #define S_BLKSIZE	512		/* block size used in the stat struct */
135 
136 /*
137  * Definitions of flags stored in file flags word.
138  *
139  * Super-user and owner changeable flags.
140  */
141 #define	UF_SETTABLE	0x0000ffff	/* mask of owner changeable flags */
142 #define	UF_NODUMP	0x00000001	/* do not dump file */
143 #define	UF_IMMUTABLE	0x00000002	/* file may not be changed */
144 #define	UF_APPEND	0x00000004	/* writes to file may only append */
145 #define UF_OPAQUE	0x00000008	/* directory is opaque wrt. union */
146 /*
147  * Super-user changeable flags.
148  */
149 #define	SF_SETTABLE	0xffff0000	/* mask of superuser changeable flags */
150 #define	SF_ARCHIVED	0x00010000	/* file is archived */
151 #define	SF_IMMUTABLE	0x00020000	/* file may not be changed */
152 #define	SF_APPEND	0x00040000	/* writes to file may only append */
153 
154 #ifdef KERNEL
155 /*
156  * Shorthand abbreviations of above.
157  */
158 #define	OPAQUE		(UF_OPAQUE)
159 #define	APPEND		(UF_APPEND | SF_APPEND)
160 #define	IMMUTABLE	(UF_IMMUTABLE | SF_IMMUTABLE)
161 #endif
162 #endif
163 
164 #ifndef KERNEL
165 #include <sys/cdefs.h>
166 
167 __BEGIN_DECLS
168 int	chmod __P((const char *, mode_t));
169 int	fstat __P((int, struct stat *));
170 int	mkdir __P((const char *, mode_t));
171 int	mkfifo __P((const char *, mode_t));
172 int	stat __P((const char *, struct stat *));
173 mode_t	umask __P((mode_t));
174 #ifndef _POSIX_SOURCE
175 int	chflags __P((const char *, u_long));
176 int	fchflags __P((int, u_long));
177 int	fchmod __P((int, mode_t));
178 int	lstat __P((const char *, struct stat *));
179 #endif
180 __END_DECLS
181 #endif
182 #endif /* !_SYS_STAT_H_ */
183