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