master
1/*
2 * Copyright (c) 2000-2014 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_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. 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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28/* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
29/*-
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.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
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.
53 *
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
64 * SUCH DAMAGE.
65 *
66 * @(#)stat.h 8.9 (Berkeley) 8/17/94
67 */
68
69
70#ifndef _SYS_STAT_H_
71#define _SYS_STAT_H_
72
73#include <sys/_types.h>
74#include <sys/cdefs.h>
75#include <Availability.h>
76
77/* [XSI] The timespec structure may be defined as described in <time.h> */
78#include <sys/_types/_timespec.h>
79
80/*
81 * [XSI] The blkcnt_t, blksize_t, dev_t, ino_t, mode_t, nlink_t, uid_t,
82 * gid_t, off_t, and time_t types shall be defined as described in
83 * <sys/types.h>.
84 */
85#include <sys/_types/_blkcnt_t.h>
86#include <sys/_types/_blksize_t.h>
87#include <sys/_types/_dev_t.h> /* device number */
88#include <sys/_types/_ino_t.h>
89
90#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
91#include <sys/_types/_ino64_t.h>
92#endif /* !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) */
93
94#include <sys/_types/_mode_t.h>
95#include <sys/_types/_nlink_t.h>
96#include <sys/_types/_uid_t.h>
97#include <sys/_types/_gid_t.h>
98#include <sys/_types/_off_t.h>
99#include <sys/_types/_time_t.h>
100
101#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
102/*
103 * XXX So deprecated, it would make your head spin
104 *
105 * The old stat structure. In fact, this is not used by the kernel at all,
106 * and should not be used by user space, and should be removed from this
107 * header file entirely (along with the unused cvtstat() prototype in
108 * vnode_internal.h).
109 */
110struct ostat {
111 __uint16_t st_dev; /* inode's device */
112 ino_t st_ino; /* inode's number */
113 mode_t st_mode; /* inode protection mode */
114 nlink_t st_nlink; /* number of hard links */
115 __uint16_t st_uid; /* user ID of the file's owner */
116 __uint16_t st_gid; /* group ID of the file's group */
117 __uint16_t st_rdev; /* device type */
118 __int32_t st_size; /* file size, in bytes */
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 __int32_t st_blksize; /* optimal blocksize for I/O */
123 __int32_t st_blocks; /* blocks allocated for file */
124 __uint32_t st_flags; /* user defined flags for file */
125 __uint32_t st_gen; /* file generation number */
126};
127
128#define __DARWIN_STRUCT_STAT64_TIMES \
129 struct timespec st_atimespec; /* time of last access */ \
130 struct timespec st_mtimespec; /* time of last data modification */ \
131 struct timespec st_ctimespec; /* time of last status change */ \
132 struct timespec st_birthtimespec; /* time of file creation(birth) */
133
134#else /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
135
136#define __DARWIN_STRUCT_STAT64_TIMES \
137 time_t st_atime; /* [XSI] Time of last access */ \
138 long st_atimensec; /* nsec of last access */ \
139 time_t st_mtime; /* [XSI] Last data modification time */ \
140 long st_mtimensec; /* last data modification nsec */ \
141 time_t st_ctime; /* [XSI] Time of last status change */ \
142 long st_ctimensec; /* nsec of last status change */ \
143 time_t st_birthtime; /* File creation time(birth) */ \
144 long st_birthtimensec; /* nsec of File creation time */
145
146#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
147
148/*
149 * This structure is used as the second parameter to the fstat64(),
150 * lstat64(), and stat64() functions, and for struct stat when
151 * __DARWIN_64_BIT_INO_T is set. __DARWIN_STRUCT_STAT64 is defined
152 * above, depending on whether we use struct timespec or the direct
153 * components.
154 *
155 * This is simillar to stat except for 64bit inode number
156 * number instead of 32bit ino_t and the addition of create(birth) time.
157 */
158#define __DARWIN_STRUCT_STAT64 { \
159 dev_t st_dev; /* [XSI] ID of device containing file */ \
160 mode_t st_mode; /* [XSI] Mode of file (see below) */ \
161 nlink_t st_nlink; /* [XSI] Number of hard links */ \
162 __darwin_ino64_t st_ino; /* [XSI] File serial number */ \
163 uid_t st_uid; /* [XSI] User ID of the file */ \
164 gid_t st_gid; /* [XSI] Group ID of the file */ \
165 dev_t st_rdev; /* [XSI] Device ID */ \
166 __DARWIN_STRUCT_STAT64_TIMES \
167 off_t st_size; /* [XSI] file size, in bytes */ \
168 blkcnt_t st_blocks; /* [XSI] blocks allocated for file */ \
169 blksize_t st_blksize; /* [XSI] optimal blocksize for I/O */ \
170 __uint32_t st_flags; /* user defined flags for file */ \
171 __uint32_t st_gen; /* file generation number */ \
172 __int32_t st_lspare; /* RESERVED: DO NOT USE! */ \
173 __int64_t st_qspare[2]; /* RESERVED: DO NOT USE! */ \
174}
175
176/*
177 * [XSI] This structure is used as the second parameter to the fstat(),
178 * lstat(), and stat() functions.
179 */
180#if __DARWIN_64_BIT_INO_T
181
182struct stat __DARWIN_STRUCT_STAT64;
183
184#else /* !__DARWIN_64_BIT_INO_T */
185
186struct 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#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_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#endif /* __DARWIN_64_BIT_INO_T */
216
217#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
218
219#if !__DARWIN_ONLY_64_BIT_INO_T
220
221struct stat64 __DARWIN_STRUCT_STAT64;
222
223#endif /* !__DARWIN_ONLY_64_BIT_INO_T */
224
225#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
226
227
228
229
230#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
231#define st_atime st_atimespec.tv_sec
232#define st_mtime st_mtimespec.tv_sec
233#define st_ctime st_ctimespec.tv_sec
234#define st_birthtime st_birthtimespec.tv_sec
235#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
236
237/*
238 * [XSI] The following are symbolic names for the values of type mode_t. They
239 * are bitmap values.
240 */
241#include <sys/_types/_s_ifmt.h>
242
243/*
244 * [XSI] The following macros shall be provided to test whether a file is
245 * of the specified type. The value m supplied to the macros is the value
246 * of st_mode from a stat structure. The macro shall evaluate to a non-zero
247 * value if the test is true; 0 if the test is false.
248 */
249#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) /* block special */
250#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) /* char special */
251#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) /* directory */
252#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) /* fifo or socket */
253#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) /* regular file */
254#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) /* symbolic link */
255#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) /* socket */
256#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
257#define S_ISWHT(m) (((m) & S_IFMT) == S_IFWHT) /* OBSOLETE: whiteout */
258#endif
259
260/*
261 * [XSI] The implementation may implement message queues, semaphores, or
262 * shared memory objects as distinct file types. The following macros
263 * shall be provided to test whether a file is of the specified type.
264 * The value of the buf argument supplied to the macros is a pointer to
265 * a stat structure. The macro shall evaluate to a non-zero value if
266 * the specified object is implemented as a distinct file type and the
267 * specified file type is contained in the stat structure referenced by
268 * buf. Otherwise, the macro shall evaluate to zero.
269 *
270 * NOTE: The current implementation does not do this, although
271 * this may change in future revisions, and co currently only
272 * provides these macros to ensure source compatability with
273 * implementations which do.
274 */
275#define S_TYPEISMQ(buf) (0) /* Test for a message queue */
276#define S_TYPEISSEM(buf) (0) /* Test for a semaphore */
277#define S_TYPEISSHM(buf) (0) /* Test for a shared memory object */
278
279/*
280 * [TYM] The implementation may implement typed memory objects as distinct
281 * file types, and the following macro shall test whether a file is of the
282 * specified type. The value of the buf argument supplied to the macros is
283 * a pointer to a stat structure. The macro shall evaluate to a non-zero
284 * value if the specified object is implemented as a distinct file type and
285 * the specified file type is contained in the stat structure referenced by
286 * buf. Otherwise, the macro shall evaluate to zero.
287 *
288 * NOTE: The current implementation does not do this, although
289 * this may change in future revisions, and co currently only
290 * provides this macro to ensure source compatability with
291 * implementations which do.
292 */
293#define S_TYPEISTMO(buf) (0) /* Test for a typed memory object */
294
295
296#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
297#define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
298 /* 7777 */
299#define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
300/* 0666 */
301#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
302
303#define S_BLKSIZE 512 /* block size used in the stat struct */
304
305/*
306 * Definitions of flags stored in file flags word.
307 *
308 * Super-user and owner changeable flags.
309 */
310#define UF_SETTABLE 0x0000ffff /* mask of owner changeable flags */
311#define UF_NODUMP 0x00000001 /* do not dump file */
312#define UF_IMMUTABLE 0x00000002 /* file may not be changed */
313#define UF_APPEND 0x00000004 /* writes to file may only append */
314#define UF_OPAQUE 0x00000008 /* directory is opaque wrt. union */
315/*
316 * The following bit is reserved for FreeBSD. It is not implemented
317 * in Mac OS X.
318 */
319/* #define UF_NOUNLINK 0x00000010 */ /* file may not be removed or renamed */
320#define UF_COMPRESSED 0x00000020 /* file is compressed (some file-systems) */
321
322/* UF_TRACKED is used for dealing with document IDs. We no longer issue
323 * notifications for deletes or renames for files which have UF_TRACKED set. */
324#define UF_TRACKED 0x00000040
325
326#define UF_DATAVAULT 0x00000080 /* entitlement required for reading */
327 /* and writing */
328
329/* Bits 0x0100 through 0x4000 are currently undefined. */
330#define UF_HIDDEN 0x00008000 /* hint that this item should not be */
331 /* displayed in a GUI */
332/*
333 * Super-user changeable flags.
334 */
335#define SF_SUPPORTED 0x009f0000 /* mask of superuser supported flags */
336#define SF_SETTABLE 0x3fff0000 /* mask of superuser changeable flags */
337#define SF_SYNTHETIC 0xc0000000 /* mask of system read-only synthetic flags */
338#define SF_ARCHIVED 0x00010000 /* file is archived */
339#define SF_IMMUTABLE 0x00020000 /* file may not be changed */
340#define SF_APPEND 0x00040000 /* writes to file may only append */
341#define SF_RESTRICTED 0x00080000 /* entitlement required for writing */
342#define SF_NOUNLINK 0x00100000 /* Item may not be removed, renamed or mounted on */
343
344/*
345 * The following two bits are reserved for FreeBSD. They are not
346 * implemented in Mac OS X.
347 */
348/* #define SF_SNAPSHOT 0x00200000 */ /* snapshot inode */
349/* NOTE: There is no SF_HIDDEN bit. */
350
351#define SF_FIRMLINK 0x00800000 /* file is a firmlink */
352
353/*
354 * Synthetic flags.
355 *
356 * These are read-only. We keep them out of SF_SUPPORTED so that
357 * attempts to set them will fail.
358 */
359#define SF_DATALESS 0x40000000 /* file is dataless object */
360
361
362#endif
363
364#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
365/*
366 * Extended flags ("EF") returned by ATTR_CMNEXT_EXT_FLAGS from getattrlist/getattrlistbulk
367 */
368#define EF_MAY_SHARE_BLOCKS 0x00000001 /* file may share blocks with another file */
369#define EF_NO_XATTRS 0x00000002 /* file has no xattrs at all */
370#define EF_IS_SYNC_ROOT 0x00000004 /* file is a sync root for iCloud */
371#define EF_IS_PURGEABLE 0x00000008 /* file is purgeable */
372#define EF_IS_SPARSE 0x00000010 /* file has at least one sparse region */
373#define EF_IS_SYNTHETIC 0x00000020 /* a synthetic directory/symlink */
374#define EF_SHARES_ALL_BLOCKS 0x00000040 /* file shares all of its blocks with another file */
375#endif
376
377
378
379__BEGIN_DECLS
380/* [XSI] */
381int chmod(const char *, mode_t) __DARWIN_ALIAS(chmod);
382int fchmod(int, mode_t) __DARWIN_ALIAS(fchmod);
383int fstat(int, struct stat *) __DARWIN_INODE64(fstat);
384int lstat(const char *, struct stat *) __DARWIN_INODE64(lstat);
385int mkdir(const char *, mode_t);
386int mkfifo(const char *, mode_t);
387int stat(const char *, struct stat *) __DARWIN_INODE64(stat);
388int mknod(const char *, mode_t, dev_t);
389mode_t umask(mode_t);
390
391#if __DARWIN_C_LEVEL >= 200809L
392int fchmodat(int, const char *, mode_t, int) __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0);
393int fstatat(int, const char *, struct stat *, int) __DARWIN_INODE64(fstatat) __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0);
394int mkdirat(int, const char *, mode_t) __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0);
395int mkfifoat(int, const char *, mode_t) __API_AVAILABLE(macos(13.0), ios(16.0), tvos(16.0), watchos(9.0));
396int mknodat(int, const char *, mode_t, dev_t) __API_AVAILABLE(macos(13.0), ios(16.0), tvos(16.0), watchos(9.0));
397
398#define UTIME_NOW -1
399#define UTIME_OMIT -2
400
401int futimens(int __fd, const struct timespec __times[2]) __API_AVAILABLE(macosx(10.13), ios(11.0), tvos(11.0), watchos(4.0));
402int utimensat(int __fd, const char *__path, const struct timespec __times[2],
403 int __flag) __API_AVAILABLE(macosx(10.13), ios(11.0), tvos(11.0), watchos(4.0));
404#endif
405__END_DECLS
406
407#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
408
409#include <sys/_types/_filesec_t.h>
410
411__BEGIN_DECLS
412int chflags(const char *, __uint32_t);
413int chmodx_np(const char *, filesec_t);
414int fchflags(int, __uint32_t);
415int fchmodx_np(int, filesec_t);
416int fstatx_np(int, struct stat *, filesec_t) __DARWIN_INODE64(fstatx_np);
417int lchflags(const char *, __uint32_t) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
418int lchmod(const char *, mode_t) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
419int lstatx_np(const char *, struct stat *, filesec_t) __DARWIN_INODE64(lstatx_np);
420int mkdirx_np(const char *, filesec_t);
421int mkfifox_np(const char *, filesec_t);
422int statx_np(const char *, struct stat *, filesec_t) __DARWIN_INODE64(statx_np);
423int umaskx_np(filesec_t) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_4, __MAC_10_6, __IPHONE_NA, __IPHONE_NA);
424
425#if !__DARWIN_ONLY_64_BIT_INO_T
426/* The following deprecated routines are simillar to stat and friends except provide struct stat64 instead of struct stat */
427int fstatx64_np(int, struct stat64 *, filesec_t) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_NA, __IPHONE_NA);
428int lstatx64_np(const char *, struct stat64 *, filesec_t) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_NA, __IPHONE_NA);
429int statx64_np(const char *, struct stat64 *, filesec_t) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_NA, __IPHONE_NA);
430int fstat64(int, struct stat64 *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_NA, __IPHONE_NA);
431int lstat64(const char *, struct stat64 *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_NA, __IPHONE_NA);
432int stat64(const char *, struct stat64 *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_NA, __IPHONE_NA);
433#endif /* !__DARWIN_ONLY_64_BIT_INO_T */
434__END_DECLS
435
436#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
437
438#endif /* !_SYS_STAT_H_ */