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