* Add __unused where necessary.
[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. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *      This product includes software developed by the University of
21  *      California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *      @(#)stat.h      8.12 (Berkeley) 6/16/95
39  * $FreeBSD: src/sys/sys/stat.h,v 1.20 1999/12/29 04:24:47 peter Exp $
40  * $DragonFly: src/sys/sys/stat.h,v 1.3 2003/08/20 07:31:21 rob Exp $
41  */
42
43 #ifndef _SYS_STAT_H_
44 #define _SYS_STAT_H_
45
46 #if !defined(_KERNEL) && !defined(_POSIX_SOURCE)
47 /*
48  * XXX we need this for struct timespec.  We get miscellaneous namespace
49  * pollution with it.
50  */
51 #include <sys/time.h>
52 #endif
53
54 #ifdef _KERNEL
55 #define __dev_t udev_t
56 #else
57 #define __dev_t dev_t
58 #endif
59
60 #ifndef _POSIX_SOURCE
61 struct ostat {
62         u_int16_t st_dev;               /* inode's device */
63         ino_t     st_ino;               /* inode's number */
64         mode_t    st_mode;              /* inode protection mode */
65         nlink_t   st_nlink;             /* number of hard links */
66         u_int16_t st_uid;               /* user ID of the file's owner */
67         u_int16_t st_gid;               /* group ID of the file's group */
68         u_int16_t st_rdev;              /* device type */
69         int32_t   st_size;              /* file size, in bytes */
70         struct  timespec st_atimespec;  /* time of last access */
71         struct  timespec st_mtimespec;  /* time of last data modification */
72         struct  timespec st_ctimespec;  /* time of last file status change */
73         int32_t   st_blksize;           /* optimal blocksize for I/O */
74         int32_t   st_blocks;            /* blocks allocated for file */
75         u_int32_t st_flags;             /* user defined flags for file */
76         u_int32_t st_gen;               /* file generation number */
77 };
78 #endif /* !_POSIX_SOURCE */
79
80 struct stat {
81         __dev_t   st_dev;               /* inode's device */
82         ino_t     st_ino;               /* inode's number */
83         mode_t    st_mode;              /* inode protection mode */
84         nlink_t   st_nlink;             /* number of hard links */
85         uid_t     st_uid;               /* user ID of the file's owner */
86         gid_t     st_gid;               /* group ID of the file's group */
87         __dev_t   st_rdev;              /* device type */
88 #ifndef _POSIX_SOURCE
89         struct  timespec st_atimespec;  /* time of last access */
90         struct  timespec st_mtimespec;  /* time of last data modification */
91         struct  timespec st_ctimespec;  /* time of last file status change */
92 #else
93         time_t    st_atime;             /* time of last access */
94         long      st_atimensec;         /* nsec of last access */
95         time_t    st_mtime;             /* time of last data modification */
96         long      st_mtimensec;         /* nsec of last data modification */
97         time_t    st_ctime;             /* time of last file status change */
98         long      st_ctimensec;         /* nsec of last file status change */
99 #endif
100         off_t     st_size;              /* file size, in bytes */
101         int64_t   st_blocks;            /* blocks allocated for file */
102         u_int32_t st_blksize;           /* optimal blocksize for I/O */
103         u_int32_t st_flags;             /* user defined flags for file */
104         u_int32_t st_gen;               /* file generation number */
105         int32_t   st_lspare;
106         int64_t   st_qspare[2];
107 };
108
109 #ifndef _POSIX_SOURCE
110 struct nstat {
111         __dev_t   st_dev;               /* inode's device */
112         ino_t     st_ino;               /* inode's number */
113         u_int32_t st_mode;              /* inode protection mode */
114         u_int32_t st_nlink;             /* number of hard links */
115         uid_t     st_uid;               /* user ID of the file's owner */
116         gid_t     st_gid;               /* group ID of the file's group */
117         __dev_t   st_rdev;              /* device type */
118 #ifndef _POSIX_SOURCE
119         struct  timespec st_atimespec;  /* time of last access */
120         struct  timespec st_mtimespec;  /* time of last data modification */
121         struct  timespec st_ctimespec;  /* time of last file status change */
122 #else
123         time_t    st_atime;             /* time of last access */
124         long      st_atimensec;         /* nsec of last access */
125         time_t    st_mtime;             /* time of last data modification */
126         long      st_mtimensec;         /* nsec of last data modification */
127         time_t    st_ctime;             /* time of last file status change */
128         long      st_ctimensec;         /* nsec of last file status change */
129 #endif
130         off_t     st_size;              /* file size, in bytes */
131         int64_t   st_blocks;            /* blocks allocated for file */
132         u_int32_t st_blksize;           /* optimal blocksize for I/O */
133         u_int32_t st_flags;             /* user defined flags for file */
134         u_int32_t st_gen;               /* file generation number */
135         int64_t   st_qspare[2];
136 };
137 #endif
138
139 #undef __dev_t
140
141 #ifndef _POSIX_SOURCE
142 #define st_atime st_atimespec.tv_sec
143 #define st_mtime st_mtimespec.tv_sec
144 #define st_ctime st_ctimespec.tv_sec
145 #endif
146
147 #define S_ISUID 0004000                 /* set user id on execution */
148 #define S_ISGID 0002000                 /* set group id on execution */
149 #ifndef _POSIX_SOURCE
150 #define S_ISTXT 0001000                 /* sticky bit */
151 #endif
152
153 #define S_IRWXU 0000700                 /* RWX mask for owner */
154 #define S_IRUSR 0000400                 /* R for owner */
155 #define S_IWUSR 0000200                 /* W for owner */
156 #define S_IXUSR 0000100                 /* X for owner */
157
158 #ifndef _POSIX_SOURCE
159 #define S_IREAD         S_IRUSR
160 #define S_IWRITE        S_IWUSR
161 #define S_IEXEC         S_IXUSR
162 #endif
163
164 #define S_IRWXG 0000070                 /* RWX mask for group */
165 #define S_IRGRP 0000040                 /* R for group */
166 #define S_IWGRP 0000020                 /* W for group */
167 #define S_IXGRP 0000010                 /* X for group */
168
169 #define S_IRWXO 0000007                 /* RWX mask for other */
170 #define S_IROTH 0000004                 /* R for other */
171 #define S_IWOTH 0000002                 /* W for other */
172 #define S_IXOTH 0000001                 /* X for other */
173
174 #ifndef _POSIX_SOURCE
175 #define S_IFMT   0170000                /* type of file mask */
176 #define S_IFIFO  0010000                /* named pipe (fifo) */
177 #define S_IFCHR  0020000                /* character special */
178 #define S_IFDIR  0040000                /* directory */
179 #define S_IFBLK  0060000                /* block special */
180 #define S_IFREG  0100000                /* regular */
181 #define S_IFLNK  0120000                /* symbolic link */
182 #define S_IFSOCK 0140000                /* socket */
183 #define S_IFWHT  0160000                /* whiteout */
184 #define S_ISVTX  0001000                /* save swapped text even after use */
185 #endif
186
187 #define S_ISDIR(m)      (((m) & 0170000) == 0040000)    /* directory */
188 #define S_ISCHR(m)      (((m) & 0170000) == 0020000)    /* char special */
189 #define S_ISBLK(m)      (((m) & 0170000) == 0060000)    /* block special */
190 #define S_ISREG(m)      (((m) & 0170000) == 0100000)    /* regular file */
191 #define S_ISFIFO(m)     (((m) & 0170000) == 0010000)    /* fifo or socket */
192 #ifndef _POSIX_SOURCE
193 #define S_ISLNK(m)      (((m) & 0170000) == 0120000)    /* symbolic link */
194 #define S_ISSOCK(m)     (((m) & 0170000) == 0140000)    /* socket */
195 #define S_ISWHT(m)      (((m) & 0170000) == 0160000)    /* whiteout */
196 #endif
197
198 #ifndef _POSIX_SOURCE
199 #define ACCESSPERMS     (S_IRWXU|S_IRWXG|S_IRWXO)       /* 0777 */
200                                                         /* 7777 */
201 #define ALLPERMS        (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
202                                                         /* 0666 */
203 #define DEFFILEMODE     (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
204
205 #define S_BLKSIZE       512             /* block size used in the stat struct */
206
207 /*
208  * Definitions of flags stored in file flags word.
209  *
210  * Super-user and owner changeable flags.
211  */
212 #define UF_SETTABLE     0x0000ffff      /* mask of owner changeable flags */
213 #define UF_NODUMP       0x00000001      /* do not dump file */
214 #define UF_IMMUTABLE    0x00000002      /* file may not be changed */
215 #define UF_APPEND       0x00000004      /* writes to file may only append */
216 #define UF_OPAQUE       0x00000008      /* directory is opaque wrt. union */
217 #define UF_NOUNLINK     0x00000010      /* file may not be removed or renamed */
218 /*
219  * Super-user changeable flags.
220  */
221 #define SF_SETTABLE     0xffff0000      /* mask of superuser changeable flags */
222 #define SF_ARCHIVED     0x00010000      /* file is archived */
223 #define SF_IMMUTABLE    0x00020000      /* file may not be changed */
224 #define SF_APPEND       0x00040000      /* writes to file may only append */
225 #define SF_NOUNLINK     0x00100000      /* file may not be removed or renamed */
226
227 #ifdef _KERNEL
228 /*
229  * Shorthand abbreviations of above.
230  */
231 #define OPAQUE          (UF_OPAQUE)
232 #define APPEND          (UF_APPEND | SF_APPEND)
233 #define IMMUTABLE       (UF_IMMUTABLE | SF_IMMUTABLE)
234 #define NOUNLINK        (UF_NOUNLINK | SF_NOUNLINK)
235 #endif
236
237 #endif /* !_POSIX_SOURCE */
238
239 #ifndef _KERNEL
240 #include <sys/cdefs.h>
241
242 __BEGIN_DECLS
243 int     chmod (const char *, mode_t);
244 int     fstat (int, struct stat *);
245 int     mkdir (const char *, mode_t);
246 int     mkfifo (const char *, mode_t);
247 int     stat (const char *, struct stat *);
248 mode_t  umask (mode_t);
249
250 #ifndef _POSIX_SOURCE
251 int     chflags (const char *, u_long);
252 int     fchflags (int, u_long);
253 int     fchmod (int, mode_t);
254 int     lchmod (const char *, mode_t);
255 int     lstat (const char *, struct stat *);
256 #endif
257 __END_DECLS
258
259 #endif /* !_KERNEL */
260
261 #endif /* !_SYS_STAT_H_ */