FreeBSD/Linux Kernel Cross Reference
sys/sys/stat.h
1 /* $NetBSD: stat.h,v 1.48 2005/02/03 19:20:02 perry Exp $ */
2
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 * @(#)stat.h 8.12 (Berkeley) 8/17/94
37 */
38
39 #ifndef _SYS_STAT_H_
40 #define _SYS_STAT_H_
41
42 #include <sys/featuretest.h>
43 #include <sys/types.h> /* XXX */
44
45 #if defined(_NETBSD_SOURCE)
46 #include <sys/time.h>
47 #endif
48
49 #ifdef _KERNEL
50 struct stat43 { /* BSD-4.3 stat struct */
51 u_int16_t st_dev; /* inode's device */
52 ino_t st_ino; /* inode's number */
53 u_int16_t st_mode; /* inode protection mode */
54 u_int16_t st_nlink; /* number of hard links */
55 u_int16_t st_uid; /* user ID of the file's owner */
56 u_int16_t st_gid; /* group ID of the file's group */
57 u_int16_t st_rdev; /* device type */
58 int32_t st_size; /* file size, in bytes */
59 struct timespec st_atimespec;/* time of last access */
60 struct timespec st_mtimespec;/* time of last data modification */
61 struct timespec st_ctimespec;/* time of last file status change */
62 int32_t st_blksize; /* optimal blocksize for I/O */
63 int32_t st_blocks; /* blocks allocated for file */
64 u_int32_t st_flags; /* user defined flags for file */
65 u_int32_t st_gen; /* file generation number */
66 };
67 #endif /* defined(_KERNEL) */
68
69 #if defined(__LIBC12_SOURCE__) || defined(_KERNEL)
70 struct stat12 { /* NetBSD-1.2 stat struct */
71 dev_t st_dev; /* inode's device */
72 ino_t st_ino; /* inode's number */
73 u_int16_t st_mode; /* inode protection mode */
74 u_int16_t st_nlink; /* number of hard links */
75 uid_t st_uid; /* user ID of the file's owner */
76 gid_t st_gid; /* group ID of the file's group */
77 dev_t st_rdev; /* device type */
78 struct timespec st_atimespec;/* time of last access */
79 struct timespec st_mtimespec;/* time of last data modification */
80 struct timespec st_ctimespec;/* time of last file status change */
81 off_t st_size; /* file size, in bytes */
82 int64_t st_blocks; /* blocks allocated for file */
83 u_int32_t st_blksize; /* optimal blocksize for I/O */
84 u_int32_t st_flags; /* user defined flags for file */
85 u_int32_t st_gen; /* file generation number */
86 int32_t st_lspare;
87 int64_t st_qspare[2];
88 };
89 #endif /* defined(__LIBC12_SOURCE__) || defined(_KERNEL) */
90
91 /*
92 * On systems with 8 byte longs and 4 byte time_ts, padding the time_ts
93 * is required in order to have a consistent ABI. This is because the
94 * stat structure used to contain timespecs, which had different
95 * alignment constraints than a time_t and a long alone. The padding
96 * should be removed the next time the stat structure ABI is changed.
97 * (This will happen whever we change to 8 byte time_t.)
98 */
99 #if defined(_LP64) /* XXXX && _BSD_TIME_T_ == int */
100 #define __STATPAD(x) int x;
101 #else
102 #define __STATPAD(x) /* nothing */
103 #endif
104
105 struct stat {
106 dev_t st_dev; /* inode's device */
107 ino_t st_ino; /* inode's number */
108 mode_t st_mode; /* inode protection mode */
109 nlink_t st_nlink; /* number of hard links */
110 uid_t st_uid; /* user ID of the file's owner */
111 gid_t st_gid; /* group ID of the file's group */
112 dev_t st_rdev; /* device type */
113 #if defined(_NETBSD_SOURCE)
114 struct timespec st_atimespec;/* time of last access */
115 struct timespec st_mtimespec;/* time of last data modification */
116 struct timespec st_ctimespec;/* time of last file status change */
117 #else
118 __STATPAD(__pad0)
119 time_t st_atime; /* time of last access */
120 __STATPAD(__pad1)
121 long st_atimensec; /* nsec of last access */
122 time_t st_mtime; /* time of last data modification */
123 __STATPAD(__pad2)
124 long st_mtimensec; /* nsec of last data modification */
125 time_t st_ctime; /* time of last file status change */
126 __STATPAD(__pad3)
127 long st_ctimensec; /* nsec of last file status change */
128 #endif
129 off_t st_size; /* file size, in bytes */
130 blkcnt_t st_blocks; /* blocks allocated for file */
131 blksize_t st_blksize; /* optimal blocksize for I/O */
132 u_int32_t st_flags; /* user defined flags for file */
133 u_int32_t st_gen; /* file generation number */
134 u_int32_t st_spare0;
135 #if defined(_NETBSD_SOURCE)
136 struct timespec st_birthtimespec;
137 #else
138 time_t st_birthtime;
139 __STATPAD(__pad4)
140 long st_birthtimensec;
141 #endif
142 #if !defined(_LP64)
143 int __pad5;
144 #endif
145 };
146
147 #undef __STATPAD
148
149 #if defined(_NETBSD_SOURCE)
150 #define st_atime st_atimespec.tv_sec
151 #define st_atimensec st_atimespec.tv_nsec
152 #define st_mtime st_mtimespec.tv_sec
153 #define st_mtimensec st_mtimespec.tv_nsec
154 #define st_ctime st_ctimespec.tv_sec
155 #define st_ctimensec st_ctimespec.tv_nsec
156 #define st_birthtime st_birthtimespec.tv_sec
157 #define st_birthtimensec st_birthtimespec.tv_nsec
158 #endif
159
160 #define S_ISUID 0004000 /* set user id on execution */
161 #define S_ISGID 0002000 /* set group id on execution */
162 #if defined(_NETBSD_SOURCE)
163 #define S_ISTXT 0001000 /* sticky bit */
164 #endif
165
166 #define S_IRWXU 0000700 /* RWX mask for owner */
167 #define S_IRUSR 0000400 /* R for owner */
168 #define S_IWUSR 0000200 /* W for owner */
169 #define S_IXUSR 0000100 /* X for owner */
170
171 #if defined(_NETBSD_SOURCE)
172 #define S_IREAD S_IRUSR
173 #define S_IWRITE S_IWUSR
174 #define S_IEXEC S_IXUSR
175 #endif
176
177 #define S_IRWXG 0000070 /* RWX mask for group */
178 #define S_IRGRP 0000040 /* R for group */
179 #define S_IWGRP 0000020 /* W for group */
180 #define S_IXGRP 0000010 /* X for group */
181
182 #define S_IRWXO 0000007 /* RWX mask for other */
183 #define S_IROTH 0000004 /* R for other */
184 #define S_IWOTH 0000002 /* W for other */
185 #define S_IXOTH 0000001 /* X for other */
186
187 #define _S_IFMT 0170000 /* type of file mask */
188 #define _S_IFIFO 0010000 /* named pipe (fifo) */
189 #define _S_IFCHR 0020000 /* character special */
190 #define _S_IFDIR 0040000 /* directory */
191 #define _S_IFBLK 0060000 /* block special */
192 #define _S_IFREG 0100000 /* regular */
193 #define _S_IFLNK 0120000 /* symbolic link */
194 #define _S_ISVTX 0001000 /* save swapped text even after use */
195 #define _S_IFSOCK 0140000 /* socket */
196 #define _S_IFWHT 0160000 /* whiteout */
197 #define _S_ARCH1 0200000 /* Archive state 1, ls -l shows 'a' */
198 #define _S_ARCH2 0400000 /* Archive state 2, ls -l shows 'A' */
199
200 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
201 #define S_IFMT _S_IFMT
202 #define S_IFIFO _S_IFIFO
203 #define S_IFCHR _S_IFCHR
204 #define S_IFDIR _S_IFDIR
205 #define S_IFBLK _S_IFBLK
206 #define S_IFREG _S_IFREG
207 #define S_IFLNK _S_IFLNK
208 #define S_ISVTX _S_ISVTX
209 #endif
210 #if ((_XOPEN_SOURCE - 0) >= 600) || defined(_NETBSD_SOURCE)
211 #define S_IFSOCK _S_IFSOCK
212 #endif
213 #if defined(_NETBSD_SOURCE)
214 #define S_IFWHT _S_IFWHT
215
216 #define S_ARCH1 _S_ARCH1
217 #define S_ARCH2 _S_ARCH2
218 #endif
219
220 #define S_ISDIR(m) ((m & _S_IFMT) == _S_IFDIR) /* directory */
221 #define S_ISCHR(m) ((m & _S_IFMT) == _S_IFCHR) /* char special */
222 #define S_ISBLK(m) ((m & _S_IFMT) == _S_IFBLK) /* block special */
223 #define S_ISREG(m) ((m & _S_IFMT) == _S_IFREG) /* regular file */
224 #define S_ISFIFO(m) ((m & _S_IFMT) == _S_IFIFO) /* fifo */
225 #if ((_POSIX_C_SOURCE - 0) >= 200112L) || defined(_XOPEN_SOURCE) || \
226 defined(_NETBSD_SOURCE)
227 #define S_ISLNK(m) ((m & _S_IFMT) == _S_IFLNK) /* symbolic link */
228 #endif
229 #if ((_POSIX_C_SOURCE - 0) >= 200112L) || ((_XOPEN_SOURCE - 0) >= 600) || \
230 defined(_NETBSD_SOURCE)
231 #define S_ISSOCK(m) ((m & _S_IFMT) == _S_IFSOCK) /* socket */
232 #endif
233 #if defined(_NETBSD_SOURCE)
234 #define S_ISWHT(m) ((m & _S_IFMT) == _S_IFWHT) /* whiteout */
235 #endif
236
237 #if defined(_NETBSD_SOURCE)
238 #define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
239 /* 7777 */
240 #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
241 /* 0666 */
242 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
243
244 #define S_BLKSIZE 512 /* block size used in the stat struct */
245
246 /*
247 * Definitions of flags stored in file flags word.
248 *
249 * Super-user and owner changeable flags.
250 */
251 #define UF_SETTABLE 0x0000ffff /* mask of owner changeable flags */
252 #define UF_NODUMP 0x00000001 /* do not dump file */
253 #define UF_IMMUTABLE 0x00000002 /* file may not be changed */
254 #define UF_APPEND 0x00000004 /* writes to file may only append */
255 #define UF_OPAQUE 0x00000008 /* directory is opaque wrt. union */
256 /*
257 * Super-user changeable flags.
258 */
259 #define SF_SETTABLE 0xffff0000 /* mask of superuser changeable flags */
260 #define SF_ARCHIVED 0x00010000 /* file is archived */
261 #define SF_IMMUTABLE 0x00020000 /* file may not be changed */
262 #define SF_APPEND 0x00040000 /* writes to file may only append */
263 #define SF_SNAPSHOT 0x00200000 /* snapshot inode */
264
265 #ifdef _KERNEL
266 /*
267 * Shorthand abbreviations of above.
268 */
269 #define OPAQUE (UF_OPAQUE)
270 #define APPEND (UF_APPEND | SF_APPEND)
271 #define IMMUTABLE (UF_IMMUTABLE | SF_IMMUTABLE)
272 #endif /* _KERNEL */
273 #endif /* _NETBSD_SOURCE */
274
275 #if !defined(_KERNEL) && !defined(_STANDALONE)
276 #include <sys/cdefs.h>
277
278 __BEGIN_DECLS
279 int chmod(const char *, mode_t);
280 int mkdir(const char *, mode_t);
281 int mkfifo(const char *, mode_t);
282 #ifdef __LIBC12_SOURCE__
283 int stat(const char *, struct stat12 *);
284 int fstat(int, struct stat12 *);
285 int __stat13(const char *, struct stat *);
286 int __fstat13(int, struct stat *);
287 #else
288 int stat(const char *, struct stat *) __RENAME(__stat13);
289 int fstat(int, struct stat *) __RENAME(__fstat13);
290 #endif
291 mode_t umask(mode_t);
292 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
293 int fchmod(int, mode_t);
294 #ifdef __LIBC12_SOURCE__
295 int lstat(const char *, struct stat12 *);
296 int __lstat13(const char *, struct stat *);
297 #else
298 int lstat(const char *, struct stat *) __RENAME(__lstat13);
299 #endif
300 int mknod(const char *, mode_t, dev_t);
301 #endif /* defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) */
302
303 #if defined(_NETBSD_SOURCE)
304 int chflags(const char *, unsigned long);
305 int fchflags(int, unsigned long);
306 int lchflags(const char *, unsigned long);
307 int lchmod(const char *, mode_t);
308 #endif /* defined(_NETBSD_SOURCE) */
309 __END_DECLS
310
311 #endif /* !_KERNEL && !_STANDALONE */
312 #endif /* !_SYS_STAT_H_ */
Cache object: c1664eaa5de92f68510ad2ef35d660e9
|