4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
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 #pragma ident "%Z%%M% %I% %E% SMI"
36 #include <sys/feature_tests.h>
37 #include <sys/types.h>
44 * The implementation specific header <sys/time_impl.h> includes a
45 * definition for timestruc_t needed by the stat structure. However,
46 * including either <time.h>, which includes <sys/time_impl.h>, or
47 * including <sys/time_impl.h> directly will break both X/Open and
48 * POSIX namespace. Preceeding tag, structure, and structure member
49 * names with underscores eliminates the namespace breakage and at the
50 * same time, with unique type names, eliminates the possibility of
51 * timespec_t or timestruct_t naming conflicts that could otherwise
52 * result based on the order of inclusion of <sys/stat.h> and
53 * <sys/time.h>. The header <sys/time_std_impl.h> contains the
54 * standards namespace safe versions of these definitions.
56 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
57 #include <sys/time_impl.h>
59 #include <sys/time_std_impl.h>
60 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
62 #define _ST_FSTYPSZ 16 /* array size for file system type name */
65 * stat structure, used by stat(2) and fstat(2)
70 /* Expanded stat structure */
88 char st_fstype
[_ST_FSTYPSZ
];
103 blksize_t st_blksize
;
105 char st_fstype
[_ST_FSTYPSZ
];
112 long st_pad1
[3]; /* reserve for dev expansion, */
113 /* sysid definition */
122 long st_pad3
; /* pad for future off_t expansion */
126 blksize_t st_blksize
;
128 char st_fstype
[_ST_FSTYPSZ
];
129 long st_pad4
[8]; /* expansion area */
134 long st_pad1
[3]; /* reserve for dev expansion, */
135 /* sysid definition */
143 off64_t st_size
; /* large file support */
147 blksize_t st_blksize
;
148 blkcnt64_t st_blocks
; /* large file support */
149 char st_fstype
[_ST_FSTYPSZ
];
150 long st_pad4
[8]; /* expansion area */
155 #else /* !defined(_KERNEL) */
158 * large file compilation environment setup
160 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
161 #ifdef __PRAGMA_REDEFINE_EXTNAME
162 #pragma redefine_extname fstat fstat64
163 #pragma redefine_extname stat stat64
164 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) || \
165 defined(_ATFILE_SOURCE)
166 #pragma redefine_extname fstatat fstatat64
167 #endif /* defined (_ATFILE_SOURCE) */
169 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG_2) || defined(__EXTENSIONS__)
170 #pragma redefine_extname lstat lstat64
172 #else /* __PRAGMA_REDEFINE_EXTNAME */
173 #define fstat fstat64
175 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) || \
176 defined(_ATFILE_SOURCE)
177 #define fstatat fstatat64
178 #endif /* defined (_ATFILE_SOURCE) */
179 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG_2) || defined(__EXTENSIONS__)
180 #define lstat lstat64
182 #endif /* __PRAGMA_REDEFINE_EXTNAME */
183 #endif /* !_LP64 && _FILE_OFFSET_BITS == 64 */
186 * In the LP64 compilation environment, map large file interfaces
187 * back to native versions where possible.
189 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
190 #ifdef __PRAGMA_REDEFINE_EXTNAME
191 #pragma redefine_extname fstat64 fstat
192 #pragma redefine_extname stat64 stat
193 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) || \
194 defined(_ATFILE_SOURCE)
195 #pragma redefine_extname fstatat64 fstatat
196 #endif /* defined (_ATFILE_SOURCE) */
197 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG_2) || defined(__EXTENSIONS__)
198 #pragma redefine_extname lstat64 lstat
200 #else /* __PRAGMA_REDEFINE_EXTNAME */
201 #define fstat64 fstat
203 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) || \
204 defined(_ATFILE_SOURCE)
205 #define fstatat64 fstatat
206 #endif /* defined (_ATFILE_SOURCE) */
207 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG_2) || defined(__EXTENSIONS__)
208 #define lstat64 lstat
210 #endif /* __PRAGMA_REDEFINE_EXTNAME */
211 #endif /* _LP64 && _LARGEFILE64_SOURCE */
214 * User level stat structure definitions.
228 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
233 _timestruc_t st_atim
;
234 _timestruc_t st_mtim
;
235 _timestruc_t st_ctim
;
237 blksize_t st_blksize
;
239 char st_fstype
[_ST_FSTYPSZ
];
246 long st_pad1
[3]; /* reserved for network id */
255 #if _FILE_OFFSET_BITS != 64
256 long st_pad3
; /* future off_t expansion */
258 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
263 _timestruc_t st_atim
;
264 _timestruc_t st_mtim
;
265 _timestruc_t st_ctim
;
267 blksize_t st_blksize
;
269 char st_fstype
[_ST_FSTYPSZ
];
270 long st_pad4
[8]; /* expansion area */
275 /* transitional large file interface version */
276 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
277 !defined(__PRAGMA_REDEFINE_EXTNAME))
289 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
294 _timestruc_t st_atim
;
295 _timestruc_t st_mtim
;
296 _timestruc_t st_ctim
;
298 blksize_t st_blksize
;
300 char st_fstype
[_ST_FSTYPSZ
];
307 long st_pad1
[3]; /* reserved for network id */
316 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
321 _timestruc_t st_atim
;
322 _timestruc_t st_mtim
;
323 _timestruc_t st_ctim
;
325 blksize_t st_blksize
;
326 blkcnt64_t st_blocks
;
327 char st_fstype
[_ST_FSTYPSZ
];
328 long st_pad4
[8]; /* expansion area */
334 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
335 #define st_atime st_atim.tv_sec
336 #define st_mtime st_mtim.tv_sec
337 #define st_ctime st_ctim.tv_sec
339 #define st_atime st_atim.__tv_sec
340 #define st_mtime st_mtim.__tv_sec
341 #define st_ctime st_ctim.__tv_sec
342 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
344 #endif /* end defined(_KERNEL) */
346 #if defined(_SYSCALL32)
349 * Kernel's view of user ILP32 stat and stat64 structures
364 timestruc32_t st_atim
;
365 timestruc32_t st_mtim
;
366 timestruc32_t st_ctim
;
368 blkcnt32_t st_blocks
;
369 char st_fstype
[_ST_FSTYPSZ
];
373 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
388 timestruc32_t st_atim
;
389 timestruc32_t st_mtim
;
390 timestruc32_t st_ctim
;
392 blkcnt64_t st_blocks
;
393 char st_fstype
[_ST_FSTYPSZ
];
397 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
401 #endif /* _SYSCALL32 */
405 /* de facto standard definitions */
407 #define S_IFMT 0xF000 /* type of file */
408 #define S_IAMB 0x1FF /* access mode bits */
409 #define S_IFIFO 0x1000 /* fifo */
410 #define S_IFCHR 0x2000 /* character special */
411 #define S_IFDIR 0x4000 /* directory */
412 /* XENIX definitions are not relevant to Solaris */
413 #define S_IFNAM 0x5000 /* XENIX special named file */
414 #define S_INSEM 0x1 /* XENIX semaphore subtype of IFNAM */
415 #define S_INSHD 0x2 /* XENIX shared data subtype of IFNAM */
416 #define S_IFBLK 0x6000 /* block special */
417 #define S_IFREG 0x8000 /* regular */
418 #define S_IFLNK 0xA000 /* symbolic link */
419 #define S_IFSOCK 0xC000 /* socket */
420 #define S_IFDOOR 0xD000 /* door */
421 #define S_IFPORT 0xE000 /* event port */
422 #define S_ISUID 0x800 /* set user id on execution */
423 #define S_ISGID 0x400 /* set group id on execution */
424 #define S_ISVTX 0x200 /* save swapped text even after use */
425 #define S_IREAD 00400 /* read permission, owner */
426 #define S_IWRITE 00200 /* write permission, owner */
427 #define S_IEXEC 00100 /* execute/search permission, owner */
428 #define S_ENFMT S_ISGID /* record locking enforcement flag */
430 /* the following macros are for POSIX conformance */
432 #define S_IRWXU 00700 /* read, write, execute: owner */
433 #define S_IRUSR 00400 /* read permission: owner */
434 #define S_IWUSR 00200 /* write permission: owner */
435 #define S_IXUSR 00100 /* execute permission: owner */
436 #define S_IRWXG 00070 /* read, write, execute: group */
437 #define S_IRGRP 00040 /* read permission: group */
438 #define S_IWGRP 00020 /* write permission: group */
439 #define S_IXGRP 00010 /* execute permission: group */
440 #define S_IRWXO 00007 /* read, write, execute: other */
441 #define S_IROTH 00004 /* read permission: other */
442 #define S_IWOTH 00002 /* write permission: other */
443 #define S_IXOTH 00001 /* execute permission: other */
446 #define S_ISFIFO(mode) (((mode)&0xF000) == 0x1000)
447 #define S_ISCHR(mode) (((mode)&0xF000) == 0x2000)
448 #define S_ISDIR(mode) (((mode)&0xF000) == 0x4000)
449 #define S_ISBLK(mode) (((mode)&0xF000) == 0x6000)
450 #define S_ISREG(mode) (((mode)&0xF000) == 0x8000)
451 #define S_ISLNK(mode) (((mode)&0xF000) == 0xa000)
452 #define S_ISSOCK(mode) (((mode)&0xF000) == 0xc000)
453 #define S_ISDOOR(mode) (((mode)&0xF000) == 0xd000)
454 #define S_ISPORT(mode) (((mode)&0xF000) == 0xe000)
457 #define S_TYPEISMQ(_buf) (0)
458 #define S_TYPEISSEM(_buf) (0)
459 #define S_TYPEISSHM(_buf) (0)
461 #if defined(__i386) || (defined(__i386_COMPAT) && defined(_KERNEL))
464 * A version number is included in the x86 SVR4 stat and mknod interfaces
465 * so that SVR4 binaries can be supported. An LP64 kernel that supports
466 * the i386 ABI need to be aware of this too.
469 #define _R3_MKNOD_VER 1 /* SVR3.0 mknod */
470 #define _MKNOD_VER 2 /* current version of mknod */
471 #define _R3_STAT_VER 1 /* SVR3.0 stat */
472 #define _STAT_VER 2 /* current version of stat */
474 #endif /* __i386 || (__i386_COMPAT && _KERNEL) */
476 #if !defined(_KERNEL) || defined(_BOOT)
478 #if defined(__STDC__)
480 #if !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2) || \
481 defined(_XPG4_2) || defined(__EXTENSIONS__)
482 extern int fchmod(int, mode_t
);
483 #endif /* !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2)... */
485 extern int chmod(const char *, mode_t
);
486 extern int mkdir(const char *, mode_t
);
487 extern int mkfifo(const char *, mode_t
);
488 extern mode_t
umask(mode_t
);
490 /* transitional large file interfaces */
491 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
492 !defined(__PRAGMA_REDEFINE_EXTNAME))
493 extern int fstat64(int, struct stat64
*);
494 extern int stat64(const char *_RESTRICT_KYWD
, struct stat64
*_RESTRICT_KYWD
);
495 extern int lstat64(const char *_RESTRICT_KYWD
, struct stat64
*_RESTRICT_KYWD
);
496 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) || \
497 defined(_ATFILE_SOURCE)
498 extern int fstatat64(int, const char *, struct stat64
*, int);
499 #endif /* defined (_ATFILE_SOURCE) */
502 #else /* !__STDC__ */
504 #if !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2) || \
505 defined(_XPG4_2) || defined(__EXTENSIONS__)
507 #endif /* !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2)... */
512 extern mode_t
umask();
514 /* transitional large file interfaces */
515 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
516 !defined(__PRAGMA_REDEFINE_EXTNAME))
517 extern int fstat64();
519 extern int lstat64();
520 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) || \
521 defined(_ATFILE_SOURCE)
522 extern int fstatat64();
523 #endif /* defined (_ATFILE_SOURCE) */
526 #endif /* defined(__STDC__) */
528 #include <sys/stat_impl.h>
530 #endif /* !defined(_KERNEL) */
536 #endif /* _SYS_STAT_H */