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 * User level stat structure definitions.
170 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
175 _timestruc_t st_atim
;
176 _timestruc_t st_mtim
;
177 _timestruc_t st_ctim
;
179 blksize_t st_blksize
;
181 char st_fstype
[_ST_FSTYPSZ
];
188 long st_pad1
[3]; /* reserved for network id */
197 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
202 _timestruc_t st_atim
;
203 _timestruc_t st_mtim
;
204 _timestruc_t st_ctim
;
206 blksize_t st_blksize
;
208 char st_fstype
[_ST_FSTYPSZ
];
209 long st_pad4
[8]; /* expansion area */
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.
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
);
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
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
258 timestruc32_t st_atim
;
259 timestruc32_t st_mtim
;
260 timestruc32_t st_ctim
;
262 blkcnt32_t st_blocks
;
263 char st_fstype
[_ST_FSTYPSZ
];
267 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
282 timestruc32_t st_atim
;
283 timestruc32_t st_mtim
;
284 timestruc32_t st_ctim
;
286 blkcnt64_t st_blocks
;
287 char st_fstype
[_ST_FSTYPSZ
];
291 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
295 #endif /* _SYSCALL32 */
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)
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) */
409 #endif /* _SYS_STAT_H */