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