abolish ino32_t
[unleashed.git] / include / sys / stat.h
blobd65affc5da4a58d7c1d96cdb5f6e862b1051abf0
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>
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
42 * The implementation specific header <sys/time_impl.h> includes a
43 * definition for timestruc_t needed by the stat structure. However,
44 * including either <time.h>, which includes <sys/time_impl.h>, or
45 * including <sys/time_impl.h> directly will break both X/Open and
46 * POSIX namespace. Preceeding tag, structure, and structure member
47 * names with underscores eliminates the namespace breakage and at the
48 * same time, with unique type names, eliminates the possibility of
49 * timespec_t or timestruct_t naming conflicts that could otherwise
50 * result based on the order of inclusion of <sys/stat.h> and
51 * <sys/time.h>. The header <sys/time_std_impl.h> contains the
52 * standards namespace safe versions of these definitions.
54 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
55 #include <sys/time_impl.h>
56 #else
57 #include <sys/time_std_impl.h>
58 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
60 #define _ST_FSTYPSZ 16 /* array size for file system type name */
63 * stat structure, used by stat(2) and fstat(2)
66 #if defined(_KERNEL)
68 /* Expanded stat structure */
70 #if defined(_LP64)
72 struct stat {
73 dev_t st_dev;
74 ino_t st_ino;
75 mode_t st_mode;
76 nlink_t st_nlink;
77 uid_t st_uid;
78 gid_t st_gid;
79 dev_t st_rdev;
80 off_t st_size;
81 timestruc_t st_atim;
82 timestruc_t st_mtim;
83 timestruc_t st_ctim;
84 blksize_t st_blksize;
85 blkcnt_t st_blocks;
86 char st_fstype[_ST_FSTYPSZ];
89 struct stat64 {
90 dev_t st_dev;
91 ino_t st_ino;
92 mode_t st_mode;
93 nlink_t st_nlink;
94 uid_t st_uid;
95 gid_t st_gid;
96 dev_t st_rdev;
97 off_t st_size;
98 timestruc_t st_atim;
99 timestruc_t st_mtim;
100 timestruc_t st_ctim;
101 blksize_t st_blksize;
102 blkcnt_t st_blocks;
103 char st_fstype[_ST_FSTYPSZ];
106 #else /* _LP64 */
108 struct stat {
109 dev_t st_dev;
110 long st_pad1[3]; /* reserve for dev expansion, */
111 /* sysid definition */
112 ino_t st_ino;
113 mode_t st_mode;
114 nlink_t st_nlink;
115 uid_t st_uid;
116 gid_t st_gid;
117 dev_t st_rdev;
118 long st_pad2[2];
119 off_t st_size;
120 long st_pad3; /* pad for future off_t expansion */
121 timestruc_t st_atim;
122 timestruc_t st_mtim;
123 timestruc_t st_ctim;
124 blksize_t st_blksize;
125 blkcnt_t st_blocks;
126 char st_fstype[_ST_FSTYPSZ];
127 long st_pad4[8]; /* expansion area */
130 struct stat64 {
131 dev_t st_dev;
132 long st_pad1[3]; /* reserve for dev expansion, */
133 /* sysid definition */
134 ino64_t st_ino;
135 mode_t st_mode;
136 nlink_t st_nlink;
137 uid_t st_uid;
138 gid_t st_gid;
139 dev_t st_rdev;
140 long st_pad2[2];
141 off64_t st_size; /* large file support */
142 timestruc_t st_atim;
143 timestruc_t st_mtim;
144 timestruc_t st_ctim;
145 blksize_t st_blksize;
146 blkcnt64_t st_blocks; /* large file support */
147 char st_fstype[_ST_FSTYPSZ];
148 long st_pad4[8]; /* expansion area */
151 #endif /* _LP64 */
153 #else /* !defined(_KERNEL) */
156 * User level stat structure definitions.
159 #if defined(_LP64)
161 struct stat {
162 dev_t st_dev;
163 ino_t st_ino;
164 mode_t st_mode;
165 nlink_t st_nlink;
166 uid_t st_uid;
167 gid_t st_gid;
168 dev_t st_rdev;
169 off_t st_size;
170 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
171 timestruc_t st_atim;
172 timestruc_t st_mtim;
173 timestruc_t st_ctim;
174 #else
175 _timestruc_t st_atim;
176 _timestruc_t st_mtim;
177 _timestruc_t st_ctim;
178 #endif
179 blksize_t st_blksize;
180 blkcnt_t st_blocks;
181 char st_fstype[_ST_FSTYPSZ];
184 #else /* _LP64 */
186 struct stat {
187 dev_t st_dev;
188 long st_pad1[3]; /* reserved for network id */
189 ino_t st_ino;
190 mode_t st_mode;
191 nlink_t st_nlink;
192 uid_t st_uid;
193 gid_t st_gid;
194 dev_t st_rdev;
195 long st_pad2[2];
196 off_t st_size;
197 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
198 timestruc_t st_atim;
199 timestruc_t st_mtim;
200 timestruc_t st_ctim;
201 #else
202 _timestruc_t st_atim;
203 _timestruc_t st_mtim;
204 _timestruc_t st_ctim;
205 #endif
206 blksize_t st_blksize;
207 blkcnt_t st_blocks;
208 char st_fstype[_ST_FSTYPSZ];
209 long st_pad4[8]; /* expansion area */
212 #endif /* _LP64 */
214 #ifndef _KERNEL
216 * FIXME: source compat: *stat64 syms are aliased to non-64 ones in libc, but
217 * because one of the args is a "struct stat *" and the *64 versions use
218 * "struct stat64 *", we have to use a #define here for stat. the other
219 * functions can use a normal decl here. NOTE: the actual decls live in
220 * sys/stat_impl.h for some reason.
222 #define stat64 stat
223 int fstat64(int, struct stat *);
224 int fstatat64(int, const char *, struct stat *, int);
225 int lstat64(const char *_RESTRICT_KYWD, struct stat *_RESTRICT_KYWD);
226 #endif
228 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
229 #define st_atime st_atim.tv_sec
230 #define st_mtime st_mtim.tv_sec
231 #define st_ctime st_ctim.tv_sec
232 #else
233 #define st_atime st_atim.__tv_sec
234 #define st_mtime st_mtim.__tv_sec
235 #define st_ctime st_ctim.__tv_sec
236 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
238 #endif /* end defined(_KERNEL) */
240 #if defined(_SYSCALL32)
243 * Kernel's view of user ILP32 stat and stat64 structures
246 struct stat32 {
247 dev32_t st_dev;
248 int32_t st_pad1[3];
249 ino_t st_ino;
250 mode32_t st_mode;
251 nlink32_t st_nlink;
252 uid32_t st_uid;
253 gid32_t st_gid;
254 dev32_t st_rdev;
255 int32_t st_pad2[2];
256 off_t st_size;
257 int32_t st_pad3;
258 timestruc32_t st_atim;
259 timestruc32_t st_mtim;
260 timestruc32_t st_ctim;
261 int32_t st_blksize;
262 blkcnt32_t st_blocks;
263 char st_fstype[_ST_FSTYPSZ];
264 int32_t st_pad4[8];
267 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
268 #pragma pack(4)
269 #endif
271 struct stat64_32 {
272 dev32_t st_dev;
273 int32_t st_pad1[3];
274 ino64_t st_ino;
275 mode32_t st_mode;
276 nlink32_t st_nlink;
277 uid32_t st_uid;
278 gid32_t st_gid;
279 dev32_t st_rdev;
280 int32_t st_pad2[2];
281 off64_t st_size;
282 timestruc32_t st_atim;
283 timestruc32_t st_mtim;
284 timestruc32_t st_ctim;
285 int32_t st_blksize;
286 blkcnt64_t st_blocks;
287 char st_fstype[_ST_FSTYPSZ];
288 int32_t st_pad4[8];
291 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
292 #pragma pack()
293 #endif
295 #endif /* _SYSCALL32 */
297 /* MODE MASKS */
299 /* de facto standard definitions */
301 #define S_IFMT 0xF000 /* type of file */
302 #define S_IAMB 0x1FF /* access mode bits */
303 #define S_IFIFO 0x1000 /* fifo */
304 #define S_IFCHR 0x2000 /* character special */
305 #define S_IFDIR 0x4000 /* directory */
306 /* XENIX definitions are not relevant to Solaris */
307 #define S_IFNAM 0x5000 /* XENIX special named file */
308 #define S_INSEM 0x1 /* XENIX semaphore subtype of IFNAM */
309 #define S_INSHD 0x2 /* XENIX shared data subtype of IFNAM */
310 #define S_IFBLK 0x6000 /* block special */
311 #define S_IFREG 0x8000 /* regular */
312 #define S_IFLNK 0xA000 /* symbolic link */
313 #define S_IFSOCK 0xC000 /* socket */
314 #define S_IFDOOR 0xD000 /* door */
315 #define S_IFPORT 0xE000 /* event port */
316 #define S_ISUID 0x800 /* set user id on execution */
317 #define S_ISGID 0x400 /* set group id on execution */
318 #define S_ISVTX 0x200 /* save swapped text even after use */
319 #define S_IREAD 00400 /* read permission, owner */
320 #define S_IWRITE 00200 /* write permission, owner */
321 #define S_IEXEC 00100 /* execute/search permission, owner */
322 #define S_ENFMT S_ISGID /* record locking enforcement flag */
324 /* the following macros are for POSIX conformance */
326 #define S_IRWXU 00700 /* read, write, execute: owner */
327 #define S_IRUSR 00400 /* read permission: owner */
328 #define S_IWUSR 00200 /* write permission: owner */
329 #define S_IXUSR 00100 /* execute permission: owner */
330 #define S_IRWXG 00070 /* read, write, execute: group */
331 #define S_IRGRP 00040 /* read permission: group */
332 #define S_IWGRP 00020 /* write permission: group */
333 #define S_IXGRP 00010 /* execute permission: group */
334 #define S_IRWXO 00007 /* read, write, execute: other */
335 #define S_IROTH 00004 /* read permission: other */
336 #define S_IWOTH 00002 /* write permission: other */
337 #define S_IXOTH 00001 /* execute permission: other */
340 #define S_ISFIFO(mode) (((mode)&0xF000) == 0x1000)
341 #define S_ISCHR(mode) (((mode)&0xF000) == 0x2000)
342 #define S_ISDIR(mode) (((mode)&0xF000) == 0x4000)
343 #define S_ISBLK(mode) (((mode)&0xF000) == 0x6000)
344 #define S_ISREG(mode) (((mode)&0xF000) == 0x8000)
345 #define S_ISLNK(mode) (((mode)&0xF000) == 0xa000)
346 #define S_ISSOCK(mode) (((mode)&0xF000) == 0xc000)
347 #define S_ISDOOR(mode) (((mode)&0xF000) == 0xd000)
348 #define S_ISPORT(mode) (((mode)&0xF000) == 0xe000)
350 /* POSIX.4 macros */
351 #define S_TYPEISMQ(_buf) (0)
352 #define S_TYPEISSEM(_buf) (0)
353 #define S_TYPEISSHM(_buf) (0)
355 #if defined(__i386) || (defined(__i386_COMPAT) && defined(_KERNEL))
358 * A version number is included in the x86 SVR4 stat and mknod interfaces
359 * so that SVR4 binaries can be supported. An LP64 kernel that supports
360 * the i386 ABI need to be aware of this too.
363 #define _R3_MKNOD_VER 1 /* SVR3.0 mknod */
364 #define _MKNOD_VER 2 /* current version of mknod */
365 #define _R3_STAT_VER 1 /* SVR3.0 stat */
366 #define _STAT_VER 2 /* current version of stat */
368 #endif /* __i386 || (__i386_COMPAT && _KERNEL) */
370 #if defined(__EXTENSIONS__) || \
371 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
372 /* || defined(_XPG7) */
373 /* for use with futimens() and utimensat() */
374 #define UTIME_NOW -1L
375 #define UTIME_OMIT -2L
376 #endif /* defined(__EXTENSIONS__) ... */
378 #if !defined(_KERNEL) || defined(_BOOT)
380 #if !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2) || \
381 defined(_XPG4_2) || defined(__EXTENSIONS__)
382 extern int fchmod(int, mode_t);
383 #endif /* !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2)... */
385 extern int chmod(const char *, mode_t);
386 extern int mkdir(const char *, mode_t);
387 extern int mkfifo(const char *, mode_t);
388 extern mode_t umask(mode_t);
390 #if defined(__EXTENSIONS__) || defined(_ATFILE_SOURCE) || \
391 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
392 /* || defined(_XPG7) */
393 extern int mkdirat(int, const char *, mode_t);
394 extern int mkfifoat(int, const char *, mode_t);
395 extern int mknodat(int, const char *, mode_t, dev_t);
396 extern int fchmodat(int, const char *, mode_t, int);
397 extern int futimens(int, const struct timespec[2]);
398 extern int utimensat(int, const char *, const struct timespec[2], int);
399 #endif /* defined(__EXTENSIONS__) ... */
401 #include <sys/stat_impl.h>
403 #endif /* !defined(_KERNEL) */
405 #ifdef __cplusplus
407 #endif
409 #endif /* _SYS_STAT_H */