Merge from vendor branch GDB:
[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  * $DragonFly: src/sys/sys/stat.h,v 1.12 2007/11/02 19:52:24 dillon Exp $
37  */
38
39 #ifndef _SYS_STAT_H_
40 #define _SYS_STAT_H_
41
42 #if !defined(_POSIX_SOURCE)
43 /*
44  * XXX we need this for struct timespec.  We get miscellaneous namespace
45  * pollution with it.
46  */
47 #ifndef _SYS_TIME_H_
48 #include <sys/time.h>
49 #endif
50 #endif  /* _POSIX_SOURCE */
51
52 #ifdef _KERNEL
53 #define __dev_t udev_t
54 #else
55 #define __dev_t dev_t
56 #endif
57
58 /*
59  * stat structure notes:
60  *
61  * (1) st_fsmid (DragonFly only).  This is a DragonFly supported field that
62  *     is incremented if the represented file or directory changes or, for
63  *     directories, if any change is made within the directory or any sub-
64  *     directory, recursively.
65  */
66 struct stat {
67         ino_t     st_ino;               /* inode's number */
68         nlink_t   st_nlink;             /* number of hard links */
69         __dev_t   st_dev;               /* inode's device */
70         mode_t    st_mode;              /* inode protection mode */
71         uint16_t  st_padding1;
72         uid_t     st_uid;               /* user ID of the file's owner */
73         gid_t     st_gid;               /* group ID of the file's group */
74         __dev_t   st_rdev;              /* device type */
75 #ifndef _POSIX_SOURCE
76         struct  timespec st_atimespec;  /* time of last access */
77         struct  timespec st_mtimespec;  /* time of last data modification */
78         struct  timespec st_ctimespec;  /* time of last file status change */
79 #else
80         time_t    st_atime;             /* time of last access */
81         long      st_atimensec;         /* nsec of last access */
82         time_t    st_mtime;             /* time of last data modification */
83         long      st_mtimensec;         /* nsec of last data modification */
84         time_t    st_ctime;             /* time of last file status change */
85         long      st_ctimensec;         /* nsec of last file status change */
86 #endif
87         off_t     st_size;              /* file size, in bytes */
88         int64_t   st_blocks;            /* blocks allocated for file */
89         u_int32_t st_blksize;           /* optimal blocksize for I/O */
90         u_int32_t st_flags;             /* user defined flags for file */
91         u_int32_t st_gen;               /* file generation number */
92         int32_t   st_lspare;
93         int64_t   st_fsmid;             /* recursive change detect */
94         int64_t   st_qspare;
95 };
96
97 #define _ST_FSMID_PRESENT_
98 #define _ST_FLAGS_PRESENT_
99
100 #undef __dev_t
101
102 #ifndef _POSIX_SOURCE
103 #define st_atime st_atimespec.tv_sec
104 #define st_mtime st_mtimespec.tv_sec
105 #define st_ctime st_ctimespec.tv_sec
106 #endif
107
108 #define S_ISUID 0004000                 /* set user id on execution */
109 #define S_ISGID 0002000                 /* set group id on execution */
110 #ifndef _POSIX_SOURCE
111 #define S_ISTXT 0001000                 /* sticky bit */
112 #endif
113
114 #define S_IRWXU 0000700                 /* RWX mask for owner */
115 #define S_IRUSR 0000400                 /* R for owner */
116 #define S_IWUSR 0000200                 /* W for owner */
117 #define S_IXUSR 0000100                 /* X for owner */
118
119 #ifndef _POSIX_SOURCE
120 #define S_IREAD         S_IRUSR
121 #define S_IWRITE        S_IWUSR
122 #define S_IEXEC         S_IXUSR
123 #endif
124
125 #define S_IRWXG 0000070                 /* RWX mask for group */
126 #define S_IRGRP 0000040                 /* R for group */
127 #define S_IWGRP 0000020                 /* W for group */
128 #define S_IXGRP 0000010                 /* X for group */
129
130 #define S_IRWXO 0000007                 /* RWX mask for other */
131 #define S_IROTH 0000004                 /* R for other */
132 #define S_IWOTH 0000002                 /* W for other */
133 #define S_IXOTH 0000001                 /* X for other */
134
135 #ifndef _POSIX_SOURCE
136 #define S_IFMT   0170000                /* type of file mask */
137 #define S_IFIFO  0010000                /* named pipe (fifo) */
138 #define S_IFCHR  0020000                /* character special */
139 #define S_IFDIR  0040000                /* directory */
140 #define S_IFBLK  0060000                /* block special */
141 #define S_IFREG  0100000                /* regular */
142 #define S_IFDB   0110000                /* record access file */
143 #define S_IFLNK  0120000                /* symbolic link */
144 #define S_IFSOCK 0140000                /* socket */
145 #define S_IFWHT  0160000                /* whiteout */
146 #define S_ISVTX  0001000                /* save swapped text even after use */
147 #endif
148
149 #define S_ISDIR(m)      (((m) & 0170000) == 0040000)    /* directory */
150 #define S_ISCHR(m)      (((m) & 0170000) == 0020000)    /* char special */
151 #define S_ISBLK(m)      (((m) & 0170000) == 0060000)    /* block special */
152 #define S_ISREG(m)      (((m) & 0170000) == 0100000)    /* regular file */
153 #define S_ISDB(m)       (((m) & 0170000) == 0110000)    /* record access file */
154 #define S_ISFIFO(m)     (((m) & 0170000) == 0010000)    /* fifo or socket */
155 #ifndef _POSIX_SOURCE
156 #define S_ISLNK(m)      (((m) & 0170000) == 0120000)    /* symbolic link */
157 #define S_ISSOCK(m)     (((m) & 0170000) == 0140000)    /* socket */
158 #define S_ISWHT(m)      (((m) & 0170000) == 0160000)    /* whiteout */
159 #endif
160
161 #ifndef _POSIX_SOURCE
162 #define ACCESSPERMS     (S_IRWXU|S_IRWXG|S_IRWXO)       /* 0777 */
163                                                         /* 7777 */
164 #define ALLPERMS        (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
165                                                         /* 0666 */
166 #define DEFFILEMODE     (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
167
168 #define S_BLKSIZE       512             /* block size used in the stat struct */
169
170 /*
171  * Definitions of flags stored in file flags word.
172  *
173  * Super-user and owner changeable flags.
174  */
175 #define UF_SETTABLE     0x0000ffff      /* mask of owner changeable flags */
176 #define UF_NODUMP       0x00000001      /* do not dump file */
177 #define UF_IMMUTABLE    0x00000002      /* file may not be changed */
178 #define UF_APPEND       0x00000004      /* writes to file may only append */
179 #define UF_OPAQUE       0x00000008      /* directory is opaque wrt. union */
180 #define UF_NOUNLINK     0x00000010      /* file may not be removed or renamed */
181 /*
182  * Super-user changeable flags.
183  */
184 #define SF_SETTABLE     0xffff0000      /* mask of superuser changeable flags */
185 #define SF_ARCHIVED     0x00010000      /* file is archived */
186 #define SF_IMMUTABLE    0x00020000      /* file may not be changed */
187 #define SF_APPEND       0x00040000      /* writes to file may only append */
188 #define SF_NOUNLINK     0x00100000      /* file may not be removed or renamed */
189
190 #ifdef _KERNEL
191 /*
192  * Shorthand abbreviations of above.
193  */
194 #define OPAQUE          (UF_OPAQUE)
195 #define APPEND          (UF_APPEND | SF_APPEND)
196 #define IMMUTABLE       (UF_IMMUTABLE | SF_IMMUTABLE)
197 #define NOUNLINK        (UF_NOUNLINK | SF_NOUNLINK)
198 #endif
199
200 #endif /* !_POSIX_SOURCE */
201
202 #if !defined(_KERNEL) || defined(_KERNEL_VIRTUAL)
203 #include <sys/cdefs.h>
204
205 __BEGIN_DECLS
206 int     chmod (const char *, mode_t);
207 int     fstat (int, struct stat *);
208 int     mkdir (const char *, mode_t);
209 int     mkfifo (const char *, mode_t);
210 int     stat (const char *, struct stat *);
211 mode_t  umask (mode_t);
212
213 #ifndef _POSIX_SOURCE
214 int     chflags (const char *, u_long);
215 int     fchflags (int, u_long);
216 int     fchmod (int, mode_t);
217 int     lchmod (const char *, mode_t);
218 int     lstat (const char *, struct stat *);
219 #endif
220 __END_DECLS
221
222 #endif
223
224 #endif /* !_SYS_STAT_H_ */