]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/stat.h
dc59799f933e8b0cb8ee5c6f98944b6f62ea9651
[apple/xnu.git] / bsd / sys / stat.h
1 /*
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
31 /*-
32 * Copyright (c) 1982, 1986, 1989, 1993
33 * The Regents of the University of California. All rights reserved.
34 * (c) UNIX System Laboratories, Inc.
35 * All or some portions of this file are derived from material licensed
36 * to the University of California by American Telephone and Telegraph
37 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
38 * the permission of UNIX System Laboratories, Inc.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. All advertising materials mentioning features or use of this software
49 * must display the following acknowledgement:
50 * This product includes software developed by the University of
51 * California, Berkeley and its contributors.
52 * 4. Neither the name of the University nor the names of its contributors
53 * may be used to endorse or promote products derived from this software
54 * without specific prior written permission.
55 *
56 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
57 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 * SUCH DAMAGE.
67 *
68 * @(#)stat.h 8.9 (Berkeley) 8/17/94
69 */
70
71
72 #ifndef _SYS_STAT_H_
73 #define _SYS_STAT_H_
74
75 #include <sys/_types.h>
76 #include <sys/cdefs.h>
77
78 /*
79 * [XSI] The blkcnt_t, blksize_t, dev_t, ino_t, mode_t, nlink_t, uid_t,
80 * gid_t, off_t, and time_t types shall be defined as described in
81 * <sys/types.h>.
82 */
83 #ifndef _BLKCNT_T
84 typedef __darwin_blkcnt_t blkcnt_t;
85 #define _BLKCNT_T
86 #endif
87
88 #ifndef _BLKSIZE_T
89 typedef __darwin_blksize_t blksize_t;
90 #define _BLKSIZE_T
91 #endif
92
93 #ifndef _DEV_T
94 typedef __darwin_dev_t dev_t; /* device number */
95 #define _DEV_T
96 #endif
97
98 #ifndef _INO_T
99 typedef __darwin_ino_t ino_t; /* inode number */
100 #define _INO_T
101 #endif
102
103 #ifndef _MODE_T
104 typedef __darwin_mode_t mode_t;
105 #define _MODE_T
106 #endif
107
108 #ifndef _NLINK_T
109 typedef __uint16_t nlink_t; /* link count */
110 #define _NLINK_T
111 #endif
112
113 #ifndef _UID_T
114 typedef __darwin_uid_t uid_t; /* user id */
115 #define _UID_T
116 #endif
117
118 #ifndef _GID_T
119 typedef __darwin_gid_t gid_t;
120 #define _GID_T
121 #endif
122
123 #ifndef _OFF_T
124 typedef __darwin_off_t off_t;
125 #define _OFF_T
126 #endif
127
128 #ifndef _TIME_T
129 #define _TIME_T
130 typedef __darwin_time_t time_t;
131 #endif
132
133 /* [XSI] The timespec structure may be defined as described in <time.h> */
134 #ifndef _TIMESPEC
135 #define _TIMESPEC
136 struct timespec {
137 time_t tv_sec; /* seconds */
138 long tv_nsec; /* and nanoseconds */
139 };
140 // LP64todo - should this move?
141 #ifdef KERNEL
142 /* LP64 version of struct timespec. time_t is a long and must grow when
143 * we're dealing with a 64-bit process.
144 * WARNING - keep in sync with struct timespec
145 */
146 struct user_timespec {
147 user_time_t tv_sec; /* seconds */
148 __int64_t tv_nsec; /* and nanoseconds */
149 };
150 #endif // KERNEL
151 #endif /* _TIMESPEC */
152
153
154 #ifndef _POSIX_C_SOURCE
155 /*
156 * XXX So deprecated, it would make your head spin
157 *
158 * The old stat structure. In fact, this is not used by the kernel at all,
159 * and should not be used by user space, and should be removed from this
160 * header file entirely (along with the unused cvtstat() prototype in
161 * vnode_internal.h).
162 */
163 struct ostat {
164 __uint16_t st_dev; /* inode's device */
165 ino_t st_ino; /* inode's number */
166 mode_t st_mode; /* inode protection mode */
167 nlink_t st_nlink; /* number of hard links */
168 __uint16_t st_uid; /* user ID of the file's owner */
169 __uint16_t st_gid; /* group ID of the file's group */
170 __uint16_t st_rdev; /* device type */
171 __int32_t st_size; /* file size, in bytes */
172 struct timespec st_atimespec; /* time of last access */
173 struct timespec st_mtimespec; /* time of last data modification */
174 struct timespec st_ctimespec; /* time of last file status change */
175 __int32_t st_blksize; /* optimal blocksize for I/O */
176 __int32_t st_blocks; /* blocks allocated for file */
177 __uint32_t st_flags; /* user defined flags for file */
178 __uint32_t st_gen; /* file generation number */
179 };
180 #endif /* !_POSIX_C_SOURCE */
181
182 /*
183 * [XSI] This structure is used as the second parameter to the fstat(),
184 * lstat(), and stat() functions.
185 */
186 struct stat {
187 dev_t st_dev; /* [XSI] ID of device containing file */
188 ino_t st_ino; /* [XSI] File serial number */
189 mode_t st_mode; /* [XSI] Mode of file (see below) */
190 nlink_t st_nlink; /* [XSI] Number of hard links */
191 uid_t st_uid; /* [XSI] User ID of the file */
192 gid_t st_gid; /* [XSI] Group ID of the file */
193 dev_t st_rdev; /* [XSI] Device ID */
194 #ifndef _POSIX_C_SOURCE
195 struct timespec st_atimespec; /* time of last access */
196 struct timespec st_mtimespec; /* time of last data modification */
197 struct timespec st_ctimespec; /* time of last status change */
198 #else
199 time_t st_atime; /* [XSI] Time of last access */
200 long st_atimensec; /* nsec of last access */
201 time_t st_mtime; /* [XSI] Last data modification time */
202 long st_mtimensec; /* last data modification nsec */
203 time_t st_ctime; /* [XSI] Time of last status change */
204 long st_ctimensec; /* nsec of last status change */
205 #endif
206 off_t st_size; /* [XSI] file size, in bytes */
207 blkcnt_t st_blocks; /* [XSI] blocks allocated for file */
208 blksize_t st_blksize; /* [XSI] optimal blocksize for I/O */
209 __uint32_t st_flags; /* user defined flags for file */
210 __uint32_t st_gen; /* file generation number */
211 __int32_t st_lspare; /* RESERVED: DO NOT USE! */
212 __int64_t st_qspare[2]; /* RESERVED: DO NOT USE! */
213 };
214
215 // LP64todo - should this move?
216 #ifdef KERNEL
217 #include <machine/types.h>
218
219 /* LP64 version of struct stat. time_t (see timespec) is a long and must
220 * grow when we're dealing with a 64-bit process.
221 * WARNING - keep in sync with struct stat
222 */
223 #if __DARWIN_ALIGN_NATURAL
224 #pragma options align=natural
225 #endif
226
227 struct user_stat {
228 dev_t st_dev; /* [XSI] ID of device containing file */
229 ino_t st_ino; /* [XSI] File serial number */
230 mode_t st_mode; /* [XSI] Mode of file (see below) */
231 nlink_t st_nlink; /* [XSI] Number of hard links */
232 uid_t st_uid; /* [XSI] User ID of the file */
233 gid_t st_gid; /* [XSI] Group ID of the file */
234 dev_t st_rdev; /* [XSI] Device ID */
235 #ifndef _POSIX_C_SOURCE
236 struct user_timespec st_atimespec; /* time of last access */
237 struct user_timespec st_mtimespec; /* time of last data modification */
238 struct user_timespec st_ctimespec; /* time of last status change */
239 #else
240 user_time_t st_atime; /* [XSI] Time of last access */
241 __int64_t st_atimensec; /* nsec of last access */
242 user_time_t st_mtime; /* [XSI] Last data modification */
243 __int64_t st_mtimensec; /* last data modification nsec */
244 user_time_t st_ctime; /* [XSI] Time of last status change */
245 __int64_t st_ctimensec; /* nsec of last status change */
246 #endif
247 off_t st_size; /* [XSI] File size, in bytes */
248 blkcnt_t st_blocks; /* [XSI] Blocks allocated for file */
249 blksize_t st_blksize; /* [XSI] Optimal blocksize for I/O */
250 __uint32_t st_flags; /* user defined flags for file */
251 __uint32_t st_gen; /* file generation number */
252 __int32_t st_lspare; /* RESERVED: DO NOT USE! */
253 __int64_t st_qspare[2]; /* RESERVED: DO NOT USE! */
254 };
255
256 #if __DARWIN_ALIGN_NATURAL
257 #pragma options align=reset
258 #endif
259
260 extern void munge_stat(struct stat *sbp, struct user_stat *usbp);
261
262 #endif // KERNEL
263
264
265 #ifndef _POSIX_C_SOURCE
266 #define st_atime st_atimespec.tv_sec
267 #define st_mtime st_mtimespec.tv_sec
268 #define st_ctime st_ctimespec.tv_sec
269 #endif
270
271 /*
272 * [XSI] The following are symbolic names for the values of type mode_t. They
273 * are bitmap values.
274 */
275 #ifndef S_IFMT
276 /* File type */
277 #define S_IFMT 0170000 /* [XSI] type of file mask */
278 #define S_IFIFO 0010000 /* [XSI] named pipe (fifo) */
279 #define S_IFCHR 0020000 /* [XSI] character special */
280 #define S_IFDIR 0040000 /* [XSI] directory */
281 #define S_IFBLK 0060000 /* [XSI] block special */
282 #define S_IFREG 0100000 /* [XSI] regular */
283 #define S_IFLNK 0120000 /* [XSI] symbolic link */
284 #define S_IFSOCK 0140000 /* [XSI] socket */
285 #ifndef _POSIX_C_SOURCE
286 #define S_IFWHT 0160000 /* whiteout */
287 #define S_IFXATTR 0200000 /* extended attribute */
288 #endif
289
290 /* File mode */
291 /* Read, write, execute/search by owner */
292 #define S_IRWXU 0000700 /* [XSI] RWX mask for owner */
293 #define S_IRUSR 0000400 /* [XSI] R for owner */
294 #define S_IWUSR 0000200 /* [XSI] W for owner */
295 #define S_IXUSR 0000100 /* [XSI] X for owner */
296 /* Read, write, execute/search by group */
297 #define S_IRWXG 0000070 /* [XSI] RWX mask for group */
298 #define S_IRGRP 0000040 /* [XSI] R for group */
299 #define S_IWGRP 0000020 /* [XSI] W for group */
300 #define S_IXGRP 0000010 /* [XSI] X for group */
301 /* Read, write, execute/search by others */
302 #define S_IRWXO 0000007 /* [XSI] RWX mask for other */
303 #define S_IROTH 0000004 /* [XSI] R for other */
304 #define S_IWOTH 0000002 /* [XSI] W for other */
305 #define S_IXOTH 0000001 /* [XSI] X for other */
306
307 #define S_ISUID 0004000 /* [XSI] set user id on execution */
308 #define S_ISGID 0002000 /* [XSI] set group id on execution */
309 #define S_ISVTX 0001000 /* [XSI] directory restrcted delete */
310
311 #ifndef _POSIX_C_SOURCE
312 #define S_ISTXT S_ISVTX /* sticky bit: not supported */
313 #define S_IREAD S_IRUSR /* backward compatability */
314 #define S_IWRITE S_IWUSR /* backward compatability */
315 #define S_IEXEC S_IXUSR /* backward compatability */
316 #endif
317 #endif /* !S_IFMT */
318
319 /*
320 * [XSI] The following macros shall be provided to test whether a file is
321 * of the specified type. The value m supplied to the macros is the value
322 * of st_mode from a stat structure. The macro shall evaluate to a non-zero
323 * value if the test is true; 0 if the test is false.
324 */
325 #define S_ISBLK(m) (((m) & 0170000) == 0060000) /* block special */
326 #define S_ISCHR(m) (((m) & 0170000) == 0020000) /* char special */
327 #define S_ISDIR(m) (((m) & 0170000) == 0040000) /* directory */
328 #define S_ISFIFO(m) (((m) & 0170000) == 0010000) /* fifo or socket */
329 #define S_ISREG(m) (((m) & 0170000) == 0100000) /* regular file */
330 #define S_ISLNK(m) (((m) & 0170000) == 0120000) /* symbolic link */
331 #define S_ISSOCK(m) (((m) & 0170000) == 0140000) /* socket */
332 #ifndef _POSIX_C_SOURCE
333 #define S_ISWHT(m) (((m) & 0170000) == 0160000) /* whiteout */
334 #define S_ISXATTR(m) (((m) & 0200000) == 0200000) /* extended attribute */
335 #endif
336
337 /*
338 * [XSI] The implementation may implement message queues, semaphores, or
339 * shared memory objects as distinct file types. The following macros
340 * shall be provided to test whether a file is of the specified type.
341 * The value of the buf argument supplied to the macros is a pointer to
342 * a stat structure. The macro shall evaluate to a non-zero value if
343 * the specified object is implemented as a distinct file type and the
344 * specified file type is contained in the stat structure referenced by
345 * buf. Otherwise, the macro shall evaluate to zero.
346 *
347 * NOTE: The current implementation does not do this, although
348 * this may change in future revisions, and co currently only
349 * provides these macros to ensure source compatability with
350 * implementations which do.
351 */
352 #define S_TYPEISMQ(buf) (0) /* Test for a message queue */
353 #define S_TYPEISSEM(buf) (0) /* Test for a semaphore */
354 #define S_TYPEISSHM(buf) (0) /* Test for a shared memory object */
355
356 /*
357 * [TYM] The implementation may implement typed memory objects as distinct
358 * file types, and the following macro shall test whether a file is of the
359 * specified type. The value of the buf argument supplied to the macros is
360 * a pointer to a stat structure. The macro shall evaluate to a non-zero
361 * value if the specified object is implemented as a distinct file type and
362 * the specified file type is contained in the stat structure referenced by
363 * buf. Otherwise, the macro shall evaluate to zero.
364 *
365 * NOTE: The current implementation does not do this, although
366 * this may change in future revisions, and co currently only
367 * provides this macro to ensure source compatability with
368 * implementations which do.
369 */
370 #define S_TYPEISTMO(buf) (0) /* Test for a typed memory object */
371
372
373 #ifndef _POSIX_C_SOURCE
374 #define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
375 /* 7777 */
376 #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
377 /* 0666 */
378 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
379
380 #define S_BLKSIZE 512 /* block size used in the stat struct */
381
382 /*
383 * Definitions of flags stored in file flags word.
384 *
385 * Super-user and owner changeable flags.
386 */
387 #define UF_SETTABLE 0x0000ffff /* mask of owner changeable flags */
388 #define UF_NODUMP 0x00000001 /* do not dump file */
389 #define UF_IMMUTABLE 0x00000002 /* file may not be changed */
390 #define UF_APPEND 0x00000004 /* writes to file may only append */
391 #define UF_OPAQUE 0x00000008 /* directory is opaque wrt. union */
392 /*
393 * Super-user changeable flags.
394 */
395 #define SF_SETTABLE 0xffff0000 /* mask of superuser changeable flags */
396 #define SF_ARCHIVED 0x00010000 /* file is archived */
397 #define SF_IMMUTABLE 0x00020000 /* file may not be changed */
398 #define SF_APPEND 0x00040000 /* writes to file may only append */
399
400 #ifdef KERNEL
401 /*
402 * Shorthand abbreviations of above.
403 */
404 #define OPAQUE (UF_OPAQUE)
405 #define APPEND (UF_APPEND | SF_APPEND)
406 #define IMMUTABLE (UF_IMMUTABLE | SF_IMMUTABLE)
407 #endif
408 #endif
409
410 #ifndef KERNEL
411
412 __BEGIN_DECLS
413 /* [XSI] */
414 int chmod(const char *, mode_t);
415 int fchmod(int, mode_t);
416 int fstat(int, struct stat *);
417 int lstat(const char *, struct stat *);
418 int mkdir(const char *, mode_t);
419 int mkfifo(const char *, mode_t);
420 int stat(const char *, struct stat *);
421 int mknod(const char *, mode_t, dev_t);
422 mode_t umask(mode_t);
423
424 #ifndef _POSIX_C_SOURCE
425 #ifndef _FILESEC_T
426 struct _filesec;
427 typedef struct _filesec *filesec_t;
428 #define _FILESEC_T
429 #endif
430 int chflags(const char *, __uint32_t);
431 int chmodx_np(const char *, filesec_t);
432 int fchflags(int, __uint32_t);
433 int fchmodx_np(int, filesec_t);
434 int fstatx_np(int, struct stat *, filesec_t);
435 int lstatx_np(const char *, struct stat *, filesec_t);
436 int mkdirx_np(const char *, filesec_t);
437 int mkfifox_np(const char *, filesec_t);
438 int statx_np(const char *, struct stat *, filesec_t);
439 int umaskx_np(filesec_t);
440 #endif /* POSIX_C_SOURCE */
441 __END_DECLS
442 #endif
443 #endif /* !_SYS_STAT_H_ */