sanify stat API & ABI
[unleashed.git] / include / sys / stat.h
blobbb880000373a13f03a61509eebe154b9a5c3abd1
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
27 /* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */
29 /* All Rights Reserved */
31 #ifndef _SYS_STAT_H
32 #define _SYS_STAT_H
34 #include <sys/feature_tests.h>
35 #include <sys/types.h>
36 #include <sys/time_impl.h>
38 #define _ST_FSTYPSZ 16 /* array size for file system type name */
40 #if !defined(_LP64)
42 * temporary additional symbols to provide ABI compat for 32-bit stat.
43 * libc performs translation from the new struct (returned by the kernel) to
44 * the old one expected by userland apps.
46 * newly compiled 32-bit binaries will use the '_new' symbols through these
47 * redefine_extnames - until we can recompile old binaries that depend on the
48 * old abi that is.
50 #ifndef _LIBC_STAT_C
51 #pragma redefine_extname fstatat fstatat_new
52 #pragma redefine_extname fstat fstat_new
53 #pragma redefine_extname lstat lstat_new
54 #pragma redefine_extname stat stat_new
55 #endif
56 #endif
58 struct stat {
59 dev_t st_dev;
60 ino_t st_ino;
61 mode_t st_mode;
62 nlink_t st_nlink;
63 uid_t st_uid;
64 gid_t st_gid;
65 dev_t st_rdev;
66 off_t st_size;
67 struct timespec st_atim;
68 struct timespec st_mtim;
69 struct timespec st_ctim;
70 blksize_t st_blksize;
71 blkcnt_t st_blocks;
72 char st_fstype[_ST_FSTYPSZ];
75 #if defined(_KERNEL) && defined(_SYSCALL32_IMPL)
77 * 32-bit process' stat struct, as viewed by the kernel.
79 * this is almost exactly same as above, with 3 differences:
80 * - dev_t (ulong_t) vs. dev32_t (uint32_t)
81 * - struct timespec vs. struct timespec32
82 * - member alignment (struct packing)
83 * if the first two differences were fixed, we could swap this around by always
84 * using the same struct, *but* with aligned(8) for 32-bit user processes.
86 struct stat32 {
87 dev32_t st_dev;
88 ino_t st_ino;
89 mode_t st_mode;
90 nlink_t st_nlink;
91 uid_t st_uid;
92 gid_t st_gid;
93 dev32_t st_rdev;
94 off_t st_size;
95 struct timespec32 st_atim;
96 struct timespec32 st_mtim;
97 struct timespec32 st_ctim;
98 blksize_t st_blksize;
99 blkcnt_t st_blocks;
100 char st_fstype[_ST_FSTYPSZ];
101 } __attribute__((packed));
102 #endif /* defined(_KERNEL) && defined(_SYSCALL32_IMPL) */
104 #define st_atime st_atim.tv_sec
105 #define st_mtime st_mtim.tv_sec
106 #define st_ctime st_ctim.tv_sec
108 /* MODE MASKS */
110 /* de facto standard definitions */
112 #define S_IFMT 0xF000 /* type of file */
113 #define S_IAMB 0x1FF /* access mode bits */
114 #define S_IFIFO 0x1000 /* fifo */
115 #define S_IFCHR 0x2000 /* character special */
116 #define S_IFDIR 0x4000 /* directory */
117 /* XENIX definitions are not relevant to Solaris */
118 #define S_IFNAM 0x5000 /* XENIX special named file */
119 #define S_INSEM 0x1 /* XENIX semaphore subtype of IFNAM */
120 #define S_INSHD 0x2 /* XENIX shared data subtype of IFNAM */
121 #define S_IFBLK 0x6000 /* block special */
122 #define S_IFREG 0x8000 /* regular */
123 #define S_IFLNK 0xA000 /* symbolic link */
124 #define S_IFSOCK 0xC000 /* socket */
125 #define S_IFDOOR 0xD000 /* door */
126 #define S_IFPORT 0xE000 /* event port */
127 #define S_ISUID 0x800 /* set user id on execution */
128 #define S_ISGID 0x400 /* set group id on execution */
129 #define S_ISVTX 0x200 /* save swapped text even after use */
130 #define S_IREAD 00400 /* read permission, owner */
131 #define S_IWRITE 00200 /* write permission, owner */
132 #define S_IEXEC 00100 /* execute/search permission, owner */
133 #define S_ENFMT S_ISGID /* record locking enforcement flag */
135 /* the following macros are for POSIX conformance */
137 #define S_IRWXU 00700 /* read, write, execute: owner */
138 #define S_IRUSR 00400 /* read permission: owner */
139 #define S_IWUSR 00200 /* write permission: owner */
140 #define S_IXUSR 00100 /* execute permission: owner */
141 #define S_IRWXG 00070 /* read, write, execute: group */
142 #define S_IRGRP 00040 /* read permission: group */
143 #define S_IWGRP 00020 /* write permission: group */
144 #define S_IXGRP 00010 /* execute permission: group */
145 #define S_IRWXO 00007 /* read, write, execute: other */
146 #define S_IROTH 00004 /* read permission: other */
147 #define S_IWOTH 00002 /* write permission: other */
148 #define S_IXOTH 00001 /* execute permission: other */
150 #define S_ISFIFO(mode) (((mode)&0xF000) == 0x1000)
151 #define S_ISCHR(mode) (((mode)&0xF000) == 0x2000)
152 #define S_ISDIR(mode) (((mode)&0xF000) == 0x4000)
153 #define S_ISBLK(mode) (((mode)&0xF000) == 0x6000)
154 #define S_ISREG(mode) (((mode)&0xF000) == 0x8000)
155 #define S_ISLNK(mode) (((mode)&0xF000) == 0xa000)
156 #define S_ISSOCK(mode) (((mode)&0xF000) == 0xc000)
157 #define S_ISDOOR(mode) (((mode)&0xF000) == 0xd000)
158 #define S_ISPORT(mode) (((mode)&0xF000) == 0xe000)
160 /* POSIX.4 macros */
161 #define S_TYPEISMQ(_buf) (0)
162 #define S_TYPEISSEM(_buf) (0)
163 #define S_TYPEISSHM(_buf) (0)
165 #if __POSIX_VISIBLE >= 200809 || defined(_KERNEL)
166 #define UTIME_NOW -1L
167 #define UTIME_OMIT -2L
168 #endif
170 #if !defined(_KERNEL)
172 #ifdef __cplusplus
173 extern "C" {
174 #endif
176 int chmod(const char *, mode_t);
177 int fstat(int, struct stat *);
178 int mkdir(const char *, mode_t);
179 int mkfifo(const char *, mode_t);
180 int stat(const char *_RESTRICT_KYWD, struct stat *_RESTRICT_KYWD);
181 mode_t umask(mode_t);
182 #if __XPG_VISIBLE >= 420
183 int fchmod(int, mode_t);
184 int lstat(const char *_RESTRICT_KYWD, struct stat *_RESTRICT_KYWD);
185 int mknod(const char *, mode_t, dev_t);
186 #endif
187 #if __POSIX_VISIBLE >= 200809
188 int fstatat(int, const char *, struct stat *, int);
189 int fchmodat(int, const char *, mode_t, int);
190 int futimens(int, const struct timespec[2]);
191 int mkdirat(int, const char *, mode_t);
192 int mkfifoat(int, const char *, mode_t);
193 int mknodat(int, const char *, mode_t, dev_t);
194 int utimensat(int, const char *, const struct timespec[2], int);
195 #endif
197 #ifdef __cplusplus
199 #endif
201 #endif /* !defined(_KERNEL) */
202 #endif /* _SYS_STAT_H */