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