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]
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 */
34 #include <sys/feature_tests.h>
35 #include <sys/types.h>
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>
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)
68 /* Expanded stat structure */
86 char st_fstype
[_ST_FSTYPSZ
];
101 blksize_t st_blksize
;
103 char st_fstype
[_ST_FSTYPSZ
];
110 long st_pad1
[3]; /* reserve for dev expansion, */
111 /* sysid definition */
120 long st_pad3
; /* pad for future off_t expansion */
124 blksize_t st_blksize
;
126 char st_fstype
[_ST_FSTYPSZ
];
127 long st_pad4
[8]; /* expansion area */
132 long st_pad1
[3]; /* reserve for dev expansion, */
133 /* sysid definition */
141 off64_t st_size
; /* large file support */
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 */
153 #else /* !defined(_KERNEL) */
156 * large file compilation environment setup
158 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
159 #ifdef __PRAGMA_REDEFINE_EXTNAME
160 #pragma redefine_extname fstat fstat64
161 #pragma redefine_extname stat stat64
162 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) || \
163 defined(_ATFILE_SOURCE)
164 #pragma redefine_extname fstatat fstatat64
165 #endif /* defined (_ATFILE_SOURCE) */
167 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG_2) || defined(__EXTENSIONS__)
168 #pragma redefine_extname lstat lstat64
170 #else /* __PRAGMA_REDEFINE_EXTNAME */
171 #define fstat fstat64
173 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) || \
174 defined(_ATFILE_SOURCE)
175 #define fstatat fstatat64
176 #endif /* defined (_ATFILE_SOURCE) */
177 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG_2) || defined(__EXTENSIONS__)
178 #define lstat lstat64
180 #endif /* __PRAGMA_REDEFINE_EXTNAME */
181 #endif /* !_LP64 && _FILE_OFFSET_BITS == 64 */
184 * In the LP64 compilation environment, map large file interfaces
185 * back to native versions where possible.
187 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
188 #ifdef __PRAGMA_REDEFINE_EXTNAME
189 #pragma redefine_extname fstat64 fstat
190 #pragma redefine_extname stat64 stat
191 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) || \
192 defined(_ATFILE_SOURCE)
193 #pragma redefine_extname fstatat64 fstatat
194 #endif /* defined (_ATFILE_SOURCE) */
195 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG_2) || defined(__EXTENSIONS__)
196 #pragma redefine_extname lstat64 lstat
198 #else /* __PRAGMA_REDEFINE_EXTNAME */
199 #define fstat64 fstat
201 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) || \
202 defined(_ATFILE_SOURCE)
203 #define fstatat64 fstatat
204 #endif /* defined (_ATFILE_SOURCE) */
205 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG_2) || defined(__EXTENSIONS__)
206 #define lstat64 lstat
208 #endif /* __PRAGMA_REDEFINE_EXTNAME */
209 #endif /* _LP64 && _LARGEFILE64_SOURCE */
212 * User level stat structure definitions.
226 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
231 _timestruc_t st_atim
;
232 _timestruc_t st_mtim
;
233 _timestruc_t st_ctim
;
235 blksize_t st_blksize
;
237 char st_fstype
[_ST_FSTYPSZ
];
244 long st_pad1
[3]; /* reserved for network id */
253 #if _FILE_OFFSET_BITS != 64
254 long st_pad3
; /* future off_t expansion */
256 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
261 _timestruc_t st_atim
;
262 _timestruc_t st_mtim
;
263 _timestruc_t st_ctim
;
265 blksize_t st_blksize
;
267 char st_fstype
[_ST_FSTYPSZ
];
268 long st_pad4
[8]; /* expansion area */
273 /* transitional large file interface version */
274 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
275 !defined(__PRAGMA_REDEFINE_EXTNAME))
287 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
292 _timestruc_t st_atim
;
293 _timestruc_t st_mtim
;
294 _timestruc_t st_ctim
;
296 blksize_t st_blksize
;
298 char st_fstype
[_ST_FSTYPSZ
];
305 long st_pad1
[3]; /* reserved for network id */
314 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
319 _timestruc_t st_atim
;
320 _timestruc_t st_mtim
;
321 _timestruc_t st_ctim
;
323 blksize_t st_blksize
;
324 blkcnt64_t st_blocks
;
325 char st_fstype
[_ST_FSTYPSZ
];
326 long st_pad4
[8]; /* expansion area */
332 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
333 #define st_atime st_atim.tv_sec
334 #define st_mtime st_mtim.tv_sec
335 #define st_ctime st_ctim.tv_sec
337 #define st_atime st_atim.__tv_sec
338 #define st_mtime st_mtim.__tv_sec
339 #define st_ctime st_ctim.__tv_sec
340 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
342 #endif /* end defined(_KERNEL) */
344 #if defined(_SYSCALL32)
347 * Kernel's view of user ILP32 stat and stat64 structures
362 timestruc32_t st_atim
;
363 timestruc32_t st_mtim
;
364 timestruc32_t st_ctim
;
366 blkcnt32_t st_blocks
;
367 char st_fstype
[_ST_FSTYPSZ
];
371 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
386 timestruc32_t st_atim
;
387 timestruc32_t st_mtim
;
388 timestruc32_t st_ctim
;
390 blkcnt64_t st_blocks
;
391 char st_fstype
[_ST_FSTYPSZ
];
395 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
399 #endif /* _SYSCALL32 */
403 /* de facto standard definitions */
405 #define S_IFMT 0xF000 /* type of file */
406 #define S_IAMB 0x1FF /* access mode bits */
407 #define S_IFIFO 0x1000 /* fifo */
408 #define S_IFCHR 0x2000 /* character special */
409 #define S_IFDIR 0x4000 /* directory */
410 /* XENIX definitions are not relevant to Solaris */
411 #define S_IFNAM 0x5000 /* XENIX special named file */
412 #define S_INSEM 0x1 /* XENIX semaphore subtype of IFNAM */
413 #define S_INSHD 0x2 /* XENIX shared data subtype of IFNAM */
414 #define S_IFBLK 0x6000 /* block special */
415 #define S_IFREG 0x8000 /* regular */
416 #define S_IFLNK 0xA000 /* symbolic link */
417 #define S_IFSOCK 0xC000 /* socket */
418 #define S_IFDOOR 0xD000 /* door */
419 #define S_IFPORT 0xE000 /* event port */
420 #define S_ISUID 0x800 /* set user id on execution */
421 #define S_ISGID 0x400 /* set group id on execution */
422 #define S_ISVTX 0x200 /* save swapped text even after use */
423 #define S_IREAD 00400 /* read permission, owner */
424 #define S_IWRITE 00200 /* write permission, owner */
425 #define S_IEXEC 00100 /* execute/search permission, owner */
426 #define S_ENFMT S_ISGID /* record locking enforcement flag */
428 /* the following macros are for POSIX conformance */
430 #define S_IRWXU 00700 /* read, write, execute: owner */
431 #define S_IRUSR 00400 /* read permission: owner */
432 #define S_IWUSR 00200 /* write permission: owner */
433 #define S_IXUSR 00100 /* execute permission: owner */
434 #define S_IRWXG 00070 /* read, write, execute: group */
435 #define S_IRGRP 00040 /* read permission: group */
436 #define S_IWGRP 00020 /* write permission: group */
437 #define S_IXGRP 00010 /* execute permission: group */
438 #define S_IRWXO 00007 /* read, write, execute: other */
439 #define S_IROTH 00004 /* read permission: other */
440 #define S_IWOTH 00002 /* write permission: other */
441 #define S_IXOTH 00001 /* execute permission: other */
444 #define S_ISFIFO(mode) (((mode)&0xF000) == 0x1000)
445 #define S_ISCHR(mode) (((mode)&0xF000) == 0x2000)
446 #define S_ISDIR(mode) (((mode)&0xF000) == 0x4000)
447 #define S_ISBLK(mode) (((mode)&0xF000) == 0x6000)
448 #define S_ISREG(mode) (((mode)&0xF000) == 0x8000)
449 #define S_ISLNK(mode) (((mode)&0xF000) == 0xa000)
450 #define S_ISSOCK(mode) (((mode)&0xF000) == 0xc000)
451 #define S_ISDOOR(mode) (((mode)&0xF000) == 0xd000)
452 #define S_ISPORT(mode) (((mode)&0xF000) == 0xe000)
455 #define S_TYPEISMQ(_buf) (0)
456 #define S_TYPEISSEM(_buf) (0)
457 #define S_TYPEISSHM(_buf) (0)
459 #if defined(__i386) || (defined(__i386_COMPAT) && defined(_KERNEL))
462 * A version number is included in the x86 SVR4 stat and mknod interfaces
463 * so that SVR4 binaries can be supported. An LP64 kernel that supports
464 * the i386 ABI need to be aware of this too.
467 #define _R3_MKNOD_VER 1 /* SVR3.0 mknod */
468 #define _MKNOD_VER 2 /* current version of mknod */
469 #define _R3_STAT_VER 1 /* SVR3.0 stat */
470 #define _STAT_VER 2 /* current version of stat */
472 #endif /* __i386 || (__i386_COMPAT && _KERNEL) */
474 #if defined(__EXTENSIONS__) || \
475 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
476 /* || defined(_XPG7) */
477 /* for use with futimens() and utimensat() */
478 #define UTIME_NOW -1L
479 #define UTIME_OMIT -2L
480 #endif /* defined(__EXTENSIONS__) ... */
482 #if !defined(_KERNEL) || defined(_BOOT)
484 #if !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2) || \
485 defined(_XPG4_2) || defined(__EXTENSIONS__)
486 extern int fchmod(int, mode_t
);
487 #endif /* !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2)... */
489 extern int chmod(const char *, mode_t
);
490 extern int mkdir(const char *, mode_t
);
491 extern int mkfifo(const char *, mode_t
);
492 extern mode_t
umask(mode_t
);
494 /* transitional large file interfaces */
495 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
496 !defined(__PRAGMA_REDEFINE_EXTNAME))
497 extern int fstat64(int, struct stat64
*);
498 extern int stat64(const char *_RESTRICT_KYWD
, struct stat64
*_RESTRICT_KYWD
);
499 extern int lstat64(const char *_RESTRICT_KYWD
, struct stat64
*_RESTRICT_KYWD
);
500 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) || \
501 defined(_ATFILE_SOURCE)
502 extern int fstatat64(int, const char *, struct stat64
*, int);
503 #endif /* defined (_ATFILE_SOURCE) */
506 #if defined(__EXTENSIONS__) || defined(_ATFILE_SOURCE) || \
507 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
508 /* || defined(_XPG7) */
509 extern int mkdirat(int, const char *, mode_t
);
510 extern int mkfifoat(int, const char *, mode_t
);
511 extern int mknodat(int, const char *, mode_t
, dev_t
);
512 extern int fchmodat(int, const char *, mode_t
, int);
513 extern int futimens(int, const struct timespec
[2]);
514 extern int utimensat(int, const char *, const struct timespec
[2], int);
515 #endif /* defined(__EXTENSIONS__) ... */
517 #include <sys/stat_impl.h>
519 #endif /* !defined(_KERNEL) */
525 #endif /* _SYS_STAT_H */