]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/stat.h
kassert.h: update MPASS definition commentary
[FreeBSD/FreeBSD.git] / sys / sys / stat.h
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1982, 1986, 1989, 1993
5  *      The Regents of the University of California.  All rights reserved.
6  * (c) UNIX System Laboratories, Inc.
7  * All or some portions of this file are derived from material licensed
8  * to the University of California by American Telephone and Telegraph
9  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10  * the permission of UNIX System Laboratories, Inc.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  */
36
37 #ifndef _SYS_STAT_H_
38 #define _SYS_STAT_H_
39
40 #include <sys/cdefs.h>
41 #include <sys/_timespec.h>
42 #include <sys/_types.h>
43
44 #ifndef _BLKSIZE_T_DECLARED
45 typedef __blksize_t     blksize_t;
46 #define _BLKSIZE_T_DECLARED
47 #endif
48
49 #ifndef _BLKCNT_T_DECLARED
50 typedef __blkcnt_t      blkcnt_t;
51 #define _BLKCNT_T_DECLARED
52 #endif
53
54 #ifndef _DEV_T_DECLARED
55 typedef __dev_t         dev_t;
56 #define _DEV_T_DECLARED
57 #endif
58
59 #ifndef _FFLAGS_T_DECLARED
60 typedef __fflags_t      fflags_t;
61 #define _FFLAGS_T_DECLARED
62 #endif
63
64 #ifndef _GID_T_DECLARED
65 typedef __gid_t         gid_t;
66 #define _GID_T_DECLARED
67 #endif
68
69 #ifndef _INO_T_DECLARED
70 typedef __ino_t         ino_t;
71 #define _INO_T_DECLARED
72 #endif
73
74 #ifndef _MODE_T_DECLARED
75 typedef __mode_t        mode_t;
76 #define _MODE_T_DECLARED
77 #endif
78
79 #ifndef _NLINK_T_DECLARED
80 typedef __nlink_t       nlink_t;
81 #define _NLINK_T_DECLARED
82 #endif
83
84 #ifndef _OFF_T_DECLARED
85 typedef __off_t         off_t;
86 #define _OFF_T_DECLARED
87 #endif
88
89 #ifndef _UID_T_DECLARED
90 typedef __uid_t         uid_t;
91 #define _UID_T_DECLARED
92 #endif
93
94 #if !defined(_KERNEL) && __BSD_VISIBLE
95 /*
96  * XXX We get miscellaneous namespace pollution with this.
97  */
98 #include <sys/time.h>
99 #endif
100
101 #ifdef _KERNEL
102 struct ostat {
103         __uint16_t st_dev;              /* inode's device */
104         __uint32_t st_ino;              /* inode's number */
105         mode_t    st_mode;              /* inode protection mode */
106         __uint16_t st_nlink;            /* number of hard links */
107         __uint16_t st_uid;              /* user ID of the file's owner */
108         __uint16_t st_gid;              /* group ID of the file's group */
109         __uint16_t st_rdev;             /* device type */
110         __int32_t st_size;              /* file size, in bytes */
111         struct  timespec st_atim;       /* time of last access */
112         struct  timespec st_mtim;       /* time of last data modification */
113         struct  timespec st_ctim;       /* time of last file status change */
114         __int32_t st_blksize;           /* optimal blocksize for I/O */
115         __int32_t st_blocks;            /* blocks allocated for file */
116         fflags_t  st_flags;             /* user defined flags for file */
117         __uint32_t st_gen;              /* file generation number */
118 };
119 #endif
120
121 #if defined(_WANT_FREEBSD11_STAT) || defined(_KERNEL)
122 struct freebsd11_stat {
123         __uint32_t st_dev;              /* inode's device */
124         __uint32_t st_ino;              /* inode's number */
125         mode_t    st_mode;              /* inode protection mode */
126         __uint16_t st_nlink;            /* number of hard links */
127         uid_t     st_uid;               /* user ID of the file's owner */
128         gid_t     st_gid;               /* group ID of the file's group */
129         __uint32_t st_rdev;             /* device type */
130         struct  timespec st_atim;       /* time of last access */
131         struct  timespec st_mtim;       /* time of last data modification */
132         struct  timespec st_ctim;       /* time of last file status change */
133         off_t     st_size;              /* file size, in bytes */
134         blkcnt_t st_blocks;             /* blocks allocated for file */
135         blksize_t st_blksize;           /* optimal blocksize for I/O */
136         fflags_t  st_flags;             /* user defined flags for file */
137         __uint32_t st_gen;              /* file generation number */
138         __int32_t st_lspare;
139         struct timespec st_birthtim;    /* time of file creation */
140         /*
141          * Explicitly pad st_birthtim to 16 bytes so that the size of
142          * struct stat is backwards compatible.  We use bitfields instead
143          * of an array of chars so that this doesn't require a C99 compiler
144          * to compile if the size of the padding is 0.  We use 2 bitfields
145          * to cover up to 64 bits on 32-bit machines.  We assume that
146          * CHAR_BIT is 8...
147          */
148         unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
149         unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
150 };
151 #endif /* _WANT_FREEBSD11_STAT || _KERNEL */
152
153 #if defined(__i386__)
154 #define __STAT_TIME_T_EXT       1
155 #endif
156
157 struct stat {
158         dev_t     st_dev;               /* inode's device */
159         ino_t     st_ino;               /* inode's number */
160         nlink_t   st_nlink;             /* number of hard links */
161         mode_t    st_mode;              /* inode protection mode */
162         __int16_t st_padding0;
163         uid_t     st_uid;               /* user ID of the file's owner */
164         gid_t     st_gid;               /* group ID of the file's group */
165         __int32_t st_padding1;
166         dev_t     st_rdev;              /* device type */
167 #ifdef  __STAT_TIME_T_EXT
168         __int32_t st_atim_ext;
169 #endif
170         struct  timespec st_atim;       /* time of last access */
171 #ifdef  __STAT_TIME_T_EXT
172         __int32_t st_mtim_ext;
173 #endif
174         struct  timespec st_mtim;       /* time of last data modification */
175 #ifdef  __STAT_TIME_T_EXT
176         __int32_t st_ctim_ext;
177 #endif
178         struct  timespec st_ctim;       /* time of last file status change */
179 #ifdef  __STAT_TIME_T_EXT
180         __int32_t st_btim_ext;
181 #endif
182         struct  timespec st_birthtim;   /* time of file creation */
183         off_t     st_size;              /* file size, in bytes */
184         blkcnt_t st_blocks;             /* blocks allocated for file */
185         blksize_t st_blksize;           /* optimal blocksize for I/O */
186         fflags_t  st_flags;             /* user defined flags for file */
187         __uint64_t st_gen;              /* file generation number */
188         __uint64_t st_spare[10];
189 };
190
191 #ifdef _KERNEL
192 struct nstat {
193         __uint32_t st_dev;              /* inode's device */
194         __uint32_t st_ino;              /* inode's number */
195         __uint32_t st_mode;             /* inode protection mode */
196         __uint32_t st_nlink;            /* number of hard links */
197         uid_t     st_uid;               /* user ID of the file's owner */
198         gid_t     st_gid;               /* group ID of the file's group */
199         __uint32_t st_rdev;             /* device type */
200         struct  timespec st_atim;       /* time of last access */
201         struct  timespec st_mtim;       /* time of last data modification */
202         struct  timespec st_ctim;       /* time of last file status change */
203         off_t     st_size;              /* file size, in bytes */
204         blkcnt_t st_blocks;             /* blocks allocated for file */
205         blksize_t st_blksize;           /* optimal blocksize for I/O */
206         fflags_t  st_flags;             /* user defined flags for file */
207         __uint32_t st_gen;              /* file generation number */
208         struct timespec st_birthtim;    /* time of file creation */
209         /*
210          * See comment in the definition of struct freebsd11_stat
211          * above about the following padding.
212          */
213         unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
214         unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
215 };
216 #endif
217
218 #ifndef _KERNEL
219 #define st_atime                st_atim.tv_sec
220 #define st_mtime                st_mtim.tv_sec
221 #define st_ctime                st_ctim.tv_sec
222 #if __BSD_VISIBLE
223 #define st_birthtime            st_birthtim.tv_sec
224 #define st_atimensec            st_atim.tv_nsec
225 #define st_mtimensec            st_mtim.tv_nsec
226 #define st_ctimensec            st_ctim.tv_nsec
227 #define st_birthtimensec        st_birthtim.tv_nsec
228 #endif
229
230 /* For compatibility. */
231 #if __BSD_VISIBLE
232 #define st_atimespec            st_atim
233 #define st_mtimespec            st_mtim
234 #define st_ctimespec            st_ctim
235 #define st_birthtimespec        st_birthtim
236 #endif
237 #endif /* !_KERNEL */
238
239 #define S_ISUID 0004000                 /* set user id on execution */
240 #define S_ISGID 0002000                 /* set group id on execution */
241 #if __BSD_VISIBLE
242 #define S_ISTXT 0001000                 /* sticky bit */
243 #endif
244
245 #define S_IRWXU 0000700                 /* RWX mask for owner */
246 #define S_IRUSR 0000400                 /* R for owner */
247 #define S_IWUSR 0000200                 /* W for owner */
248 #define S_IXUSR 0000100                 /* X for owner */
249
250 #if __BSD_VISIBLE
251 #define S_IREAD         S_IRUSR
252 #define S_IWRITE        S_IWUSR
253 #define S_IEXEC         S_IXUSR
254 #endif
255
256 #define S_IRWXG 0000070                 /* RWX mask for group */
257 #define S_IRGRP 0000040                 /* R for group */
258 #define S_IWGRP 0000020                 /* W for group */
259 #define S_IXGRP 0000010                 /* X for group */
260
261 #define S_IRWXO 0000007                 /* RWX mask for other */
262 #define S_IROTH 0000004                 /* R for other */
263 #define S_IWOTH 0000002                 /* W for other */
264 #define S_IXOTH 0000001                 /* X for other */
265
266 #if __XSI_VISIBLE
267 #define S_IFMT   0170000                /* type of file mask */
268 #define S_IFIFO  0010000                /* named pipe (fifo) */
269 #define S_IFCHR  0020000                /* character special */
270 #define S_IFDIR  0040000                /* directory */
271 #define S_IFBLK  0060000                /* block special */
272 #define S_IFREG  0100000                /* regular */
273 #define S_IFLNK  0120000                /* symbolic link */
274 #define S_IFSOCK 0140000                /* socket */
275 #define S_ISVTX  0001000                /* save swapped text even after use */
276 #endif
277 #if __BSD_VISIBLE
278 #define S_IFWHT  0160000                /* whiteout */
279 #endif
280
281 #define S_ISDIR(m)      (((m) & 0170000) == 0040000)    /* directory */
282 #define S_ISCHR(m)      (((m) & 0170000) == 0020000)    /* char special */
283 #define S_ISBLK(m)      (((m) & 0170000) == 0060000)    /* block special */
284 #define S_ISREG(m)      (((m) & 0170000) == 0100000)    /* regular file */
285 #define S_ISFIFO(m)     (((m) & 0170000) == 0010000)    /* fifo or socket */
286 #if __POSIX_VISIBLE >= 200112
287 #define S_ISLNK(m)      (((m) & 0170000) == 0120000)    /* symbolic link */
288 #define S_ISSOCK(m)     (((m) & 0170000) == 0140000)    /* socket */
289 #endif
290 #if __BSD_VISIBLE
291 #define S_ISWHT(m)      (((m) & 0170000) == 0160000)    /* whiteout */
292 #endif
293
294 #if __BSD_VISIBLE
295 #define ACCESSPERMS     (S_IRWXU|S_IRWXG|S_IRWXO)       /* 0777 */
296                                                         /* 7777 */
297 #define ALLPERMS        (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
298                                                         /* 0666 */
299 #define DEFFILEMODE     (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
300
301 #define S_BLKSIZE       512             /* block size used in the stat struct */
302
303 /*
304  * Definitions of flags stored in file flags word.
305  *
306  * Super-user and owner changeable flags.
307  */
308 #define UF_SETTABLE     0x0000ffff      /* mask of owner changeable flags */
309 #define UF_NODUMP       0x00000001      /* do not dump file */
310 #define UF_IMMUTABLE    0x00000002      /* file may not be changed */
311 #define UF_APPEND       0x00000004      /* writes to file may only append */
312 #define UF_OPAQUE       0x00000008      /* directory is opaque wrt. union */
313 #define UF_NOUNLINK     0x00000010      /* file may not be removed or renamed */
314 /*
315  * These two bits are defined in MacOS X.  They are not currently used in
316  * FreeBSD.
317  */
318 #if 0
319 #define UF_COMPRESSED   0x00000020      /* file is compressed */
320 #define UF_TRACKED      0x00000040      /* renames and deletes are tracked */
321 #endif
322
323 #define UF_SYSTEM       0x00000080      /* Windows system file bit */
324 #define UF_SPARSE       0x00000100      /* sparse file */
325 #define UF_OFFLINE      0x00000200      /* file is offline */
326 #define UF_REPARSE      0x00000400      /* Windows reparse point file bit */
327 #define UF_ARCHIVE      0x00000800      /* file needs to be archived */
328 #define UF_READONLY     0x00001000      /* Windows readonly file bit */
329 /* This is the same as the MacOS X definition of UF_HIDDEN. */
330 #define UF_HIDDEN       0x00008000      /* file is hidden */
331
332 /*
333  * Super-user changeable flags.
334  */
335 #define SF_SETTABLE     0xffff0000      /* mask of superuser changeable flags */
336 #define SF_ARCHIVED     0x00010000      /* file is archived */
337 #define SF_IMMUTABLE    0x00020000      /* file may not be changed */
338 #define SF_APPEND       0x00040000      /* writes to file may only append */
339 #define SF_NOUNLINK     0x00100000      /* file may not be removed or renamed */
340 #define SF_SNAPSHOT     0x00200000      /* snapshot inode */
341
342 #ifdef _KERNEL
343 /*
344  * Shorthand abbreviations of above.
345  */
346 #define OPAQUE          (UF_OPAQUE)
347 #define APPEND          (UF_APPEND | SF_APPEND)
348 #define IMMUTABLE       (UF_IMMUTABLE | SF_IMMUTABLE)
349 #define NOUNLINK        (UF_NOUNLINK | SF_NOUNLINK)
350 #endif
351
352 #endif /* __BSD_VISIBLE */
353
354 #if __POSIX_VISIBLE >= 200809
355 #define UTIME_NOW       -1
356 #define UTIME_OMIT      -2
357 #endif
358
359 #ifndef _KERNEL
360 __BEGIN_DECLS
361 #if __BSD_VISIBLE
362 int     chflags(const char *, unsigned long);
363 int     chflagsat(int, const char *, unsigned long, int);
364 #endif
365 int     chmod(const char *, mode_t);
366 #if __BSD_VISIBLE
367 int     fchflags(int, unsigned long);
368 #endif
369 #if __POSIX_VISIBLE >= 200112
370 int     fchmod(int, mode_t);
371 #endif
372 #if __POSIX_VISIBLE >= 200809
373 int     fchmodat(int, const char *, mode_t, int);
374 int     futimens(int fd, const struct timespec times[2]);
375 int     utimensat(int fd, const char *path, const struct timespec times[2],
376                 int flag);
377 #endif
378 int     fstat(int, struct stat *);
379 #if __BSD_VISIBLE
380 int     lchflags(const char *, unsigned long);
381 int     lchmod(const char *, mode_t);
382 #endif
383 #if __POSIX_VISIBLE >= 200112
384 int     lstat(const char * __restrict, struct stat * __restrict);
385 #endif
386 int     mkdir(const char *, mode_t);
387 int     mkfifo(const char *, mode_t);
388 #if !defined(_MKNOD_DECLARED) && __XSI_VISIBLE
389 int     mknod(const char *, mode_t, dev_t);
390 #define _MKNOD_DECLARED
391 #endif
392 int     stat(const char * __restrict, struct stat * __restrict);
393 mode_t  umask(mode_t);
394 #if __POSIX_VISIBLE >= 200809
395 int     fstatat(int, const char *, struct stat *, int);
396 int     mkdirat(int, const char *, mode_t);
397 int     mkfifoat(int, const char *, mode_t);
398 #endif
399 #if __XSI_VISIBLE >= 700
400 int     mknodat(int, const char *, mode_t, dev_t);
401 #endif
402 __END_DECLS
403 #endif /* !_KERNEL */
404
405 #endif /* !_SYS_STAT_H_ */