xref: /titanic_52/usr/src/uts/common/sys/stat.h (revision e0731422366620894c16c1ee6515551c5f00733d)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 /*	Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.	*/
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T	*/
28 /*	All Rights Reserved	*/
29 
30 #ifndef _SYS_STAT_H
31 #define	_SYS_STAT_H
32 
33 #include <sys/feature_tests.h>
34 #include <sys/types.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 /*
41  * The implementation specific header <sys/time_impl.h> includes a
42  * definition for timestruc_t needed by the stat structure.  However,
43  * including either <time.h>, which includes <sys/time_impl.h>, or
44  * including <sys/time_impl.h> directly will break both X/Open and
45  * POSIX namespace. Preceeding tag, structure, and structure member
46  * names with underscores eliminates the namespace breakage and at the
47  * same time, with unique type names, eliminates the possibility of
48  * timespec_t or timestruct_t naming conflicts that could otherwise
49  * result based on the order of inclusion of <sys/stat.h> and
50  * <sys/time.h>.  The header <sys/time_std_impl.h> contains the
51  * standards namespace safe versions of these definitions.
52  */
53 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
54 #include <sys/time_impl.h>
55 #else
56 #include <sys/time_std_impl.h>
57 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
58 
59 #define	_ST_FSTYPSZ 16		/* array size for file system type name */
60 
61 /*
62  * stat structure, used by stat(2) and fstat(2)
63  */
64 
65 #if defined(_KERNEL)
66 
67 	/* Expanded stat structure */
68 
69 #if defined(_LP64)
70 
71 struct stat {
72 	dev_t		st_dev;
73 	ino_t		st_ino;
74 	mode_t		st_mode;
75 	nlink_t		st_nlink;
76 	uid_t		st_uid;
77 	gid_t		st_gid;
78 	dev_t		st_rdev;
79 	off_t		st_size;
80 	timestruc_t	st_atim;
81 	timestruc_t	st_mtim;
82 	timestruc_t	st_ctim;
83 	blksize_t	st_blksize;
84 	blkcnt_t	st_blocks;
85 	char		st_fstype[_ST_FSTYPSZ];
86 };
87 
88 struct stat64 {
89 	dev_t		st_dev;
90 	ino_t		st_ino;
91 	mode_t		st_mode;
92 	nlink_t		st_nlink;
93 	uid_t		st_uid;
94 	gid_t		st_gid;
95 	dev_t		st_rdev;
96 	off_t		st_size;
97 	timestruc_t	st_atim;
98 	timestruc_t	st_mtim;
99 	timestruc_t	st_ctim;
100 	blksize_t	st_blksize;
101 	blkcnt_t	st_blocks;
102 	char		st_fstype[_ST_FSTYPSZ];
103 };
104 
105 #else	/* _LP64 */
106 
107 struct	stat {
108 	dev_t		st_dev;
109 	long		st_pad1[3];	/* reserve for dev expansion, */
110 					/* sysid definition */
111 	ino_t		st_ino;
112 	mode_t		st_mode;
113 	nlink_t		st_nlink;
114 	uid_t		st_uid;
115 	gid_t		st_gid;
116 	dev_t		st_rdev;
117 	long		st_pad2[2];
118 	off_t		st_size;
119 	long		st_pad3;	/* pad for future off_t expansion */
120 	timestruc_t	st_atim;
121 	timestruc_t	st_mtim;
122 	timestruc_t	st_ctim;
123 	blksize_t	st_blksize;
124 	blkcnt_t	st_blocks;
125 	char		st_fstype[_ST_FSTYPSZ];
126 	long		st_pad4[8];	/* expansion area */
127 };
128 
129 struct  stat64 {
130 	dev_t		st_dev;
131 	long		st_pad1[3];	/* reserve for dev expansion, */
132 				/* sysid definition */
133 	ino64_t		st_ino;
134 	mode_t		st_mode;
135 	nlink_t		st_nlink;
136 	uid_t		st_uid;
137 	gid_t		st_gid;
138 	dev_t		st_rdev;
139 	long		st_pad2[2];
140 	off64_t		st_size;	/* large file support */
141 	timestruc_t	st_atim;
142 	timestruc_t	st_mtim;
143 	timestruc_t	st_ctim;
144 	blksize_t	st_blksize;
145 	blkcnt64_t	st_blocks;	/* large file support */
146 	char		st_fstype[_ST_FSTYPSZ];
147 	long		st_pad4[8];	/* expansion area */
148 };
149 
150 #endif	/* _LP64 */
151 
152 #else /* !defined(_KERNEL) */
153 
154 /*
155  * large file compilation environment setup
156  */
157 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
158 #ifdef	__PRAGMA_REDEFINE_EXTNAME
159 #pragma redefine_extname	fstat	fstat64
160 #pragma redefine_extname	stat	stat64
161 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) || \
162 	defined(_ATFILE_SOURCE)
163 #pragma	redefine_extname	fstatat	fstatat64
164 #endif /* defined (_ATFILE_SOURCE) */
165 
166 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG_2) || defined(__EXTENSIONS__)
167 #pragma	redefine_extname	lstat	lstat64
168 #endif
169 #else	/* __PRAGMA_REDEFINE_EXTNAME */
170 #define	fstat	fstat64
171 #define	stat	stat64
172 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) || \
173 	defined(_ATFILE_SOURCE)
174 #define	fstatat	fstatat64
175 #endif /* defined (_ATFILE_SOURCE) */
176 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG_2) || defined(__EXTENSIONS__)
177 #define	lstat	lstat64
178 #endif
179 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
180 #endif	/* !_LP64 && _FILE_OFFSET_BITS == 64 */
181 
182 /*
183  * In the LP64 compilation environment, map large file interfaces
184  * back to native versions where possible.
185  */
186 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
187 #ifdef	__PRAGMA_REDEFINE_EXTNAME
188 #pragma	redefine_extname	fstat64	fstat
189 #pragma	redefine_extname	stat64	stat
190 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) || \
191 	defined(_ATFILE_SOURCE)
192 #pragma	redefine_extname	fstatat64 fstatat
193 #endif /* defined (_ATFILE_SOURCE) */
194 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG_2) || defined(__EXTENSIONS__)
195 #pragma	redefine_extname	lstat64	lstat
196 #endif
197 #else	/* __PRAGMA_REDEFINE_EXTNAME */
198 #define	fstat64	fstat
199 #define	stat64	stat
200 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) || \
201 	defined(_ATFILE_SOURCE)
202 #define	fstatat64	fstatat
203 #endif /* defined (_ATFILE_SOURCE) */
204 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG_2) || defined(__EXTENSIONS__)
205 #define	lstat64	lstat
206 #endif
207 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
208 #endif	/* _LP64 && _LARGEFILE64_SOURCE */
209 
210 /*
211  * User level stat structure definitions.
212  */
213 
214 #if defined(_LP64)
215 
216 struct stat {
217 	dev_t		st_dev;
218 	ino_t		st_ino;
219 	mode_t		st_mode;
220 	nlink_t		st_nlink;
221 	uid_t		st_uid;
222 	gid_t		st_gid;
223 	dev_t		st_rdev;
224 	off_t		st_size;
225 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
226 	timestruc_t	st_atim;
227 	timestruc_t	st_mtim;
228 	timestruc_t	st_ctim;
229 #else
230 	_timestruc_t	st_atim;
231 	_timestruc_t	st_mtim;
232 	_timestruc_t	st_ctim;
233 #endif
234 	blksize_t	st_blksize;
235 	blkcnt_t	st_blocks;
236 	char		st_fstype[_ST_FSTYPSZ];
237 };
238 
239 #else	/* _LP64 */
240 
241 struct	stat {
242 	dev_t		st_dev;
243 	long		st_pad1[3];	/* reserved for network id */
244 	ino_t		st_ino;
245 	mode_t		st_mode;
246 	nlink_t		st_nlink;
247 	uid_t		st_uid;
248 	gid_t		st_gid;
249 	dev_t		st_rdev;
250 	long		st_pad2[2];
251 	off_t		st_size;
252 #if _FILE_OFFSET_BITS != 64
253 	long		st_pad3;	/* future off_t expansion */
254 #endif
255 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
256 	timestruc_t	st_atim;
257 	timestruc_t	st_mtim;
258 	timestruc_t	st_ctim;
259 #else
260 	_timestruc_t	st_atim;
261 	_timestruc_t	st_mtim;
262 	_timestruc_t	st_ctim;
263 #endif
264 	blksize_t	st_blksize;
265 	blkcnt_t	st_blocks;
266 	char		st_fstype[_ST_FSTYPSZ];
267 	long		st_pad4[8];	/* expansion area */
268 };
269 
270 #endif	/* _LP64 */
271 
272 /* transitional large file interface version */
273 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
274 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
275 #if defined(_LP64)
276 
277 struct stat64 {
278 	dev_t		st_dev;
279 	ino_t		st_ino;
280 	mode_t		st_mode;
281 	nlink_t		st_nlink;
282 	uid_t		st_uid;
283 	gid_t		st_gid;
284 	dev_t		st_rdev;
285 	off_t		st_size;
286 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
287 	timestruc_t	st_atim;
288 	timestruc_t	st_mtim;
289 	timestruc_t	st_ctim;
290 #else
291 	_timestruc_t	st_atim;
292 	_timestruc_t	st_mtim;
293 	_timestruc_t	st_ctim;
294 #endif
295 	blksize_t	st_blksize;
296 	blkcnt_t	st_blocks;
297 	char		st_fstype[_ST_FSTYPSZ];
298 };
299 
300 #else	/* _LP64 */
301 
302 struct	stat64 {
303 	dev_t		st_dev;
304 	long		st_pad1[3];	/* reserved for network id */
305 	ino64_t		st_ino;
306 	mode_t		st_mode;
307 	nlink_t		st_nlink;
308 	uid_t		st_uid;
309 	gid_t		st_gid;
310 	dev_t		st_rdev;
311 	long		st_pad2[2];
312 	off64_t		st_size;
313 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
314 	timestruc_t	st_atim;
315 	timestruc_t	st_mtim;
316 	timestruc_t	st_ctim;
317 #else
318 	_timestruc_t    st_atim;
319 	_timestruc_t    st_mtim;
320 	_timestruc_t    st_ctim;
321 #endif
322 	blksize_t	st_blksize;
323 	blkcnt64_t	st_blocks;
324 	char		st_fstype[_ST_FSTYPSZ];
325 	long		st_pad4[8];	/* expansion area */
326 };
327 
328 #endif	/* _LP64 */
329 #endif
330 
331 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
332 #define	st_atime	st_atim.tv_sec
333 #define	st_mtime	st_mtim.tv_sec
334 #define	st_ctime	st_ctim.tv_sec
335 #else
336 #define	st_atime	st_atim.__tv_sec
337 #define	st_mtime	st_mtim.__tv_sec
338 #define	st_ctime	st_ctim.__tv_sec
339 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
340 
341 #endif /* end defined(_KERNEL) */
342 
343 #if defined(_SYSCALL32)
344 
345 /*
346  * Kernel's view of user ILP32 stat and stat64 structures
347  */
348 
349 struct stat32 {
350 	dev32_t		st_dev;
351 	int32_t		st_pad1[3];
352 	ino32_t		st_ino;
353 	mode32_t	st_mode;
354 	nlink32_t	st_nlink;
355 	uid32_t		st_uid;
356 	gid32_t		st_gid;
357 	dev32_t		st_rdev;
358 	int32_t		st_pad2[2];
359 	off32_t		st_size;
360 	int32_t		st_pad3;
361 	timestruc32_t	st_atim;
362 	timestruc32_t	st_mtim;
363 	timestruc32_t	st_ctim;
364 	int32_t		st_blksize;
365 	blkcnt32_t	st_blocks;
366 	char		st_fstype[_ST_FSTYPSZ];
367 	int32_t		st_pad4[8];
368 };
369 
370 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
371 #pragma pack(4)
372 #endif
373 
374 struct stat64_32 {
375 	dev32_t		st_dev;
376 	int32_t		st_pad1[3];
377 	ino64_t		st_ino;
378 	mode32_t	st_mode;
379 	nlink32_t	st_nlink;
380 	uid32_t		st_uid;
381 	gid32_t		st_gid;
382 	dev32_t		st_rdev;
383 	int32_t		st_pad2[2];
384 	off64_t		st_size;
385 	timestruc32_t	st_atim;
386 	timestruc32_t	st_mtim;
387 	timestruc32_t	st_ctim;
388 	int32_t		st_blksize;
389 	blkcnt64_t	st_blocks;
390 	char		st_fstype[_ST_FSTYPSZ];
391 	int32_t		st_pad4[8];
392 };
393 
394 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
395 #pragma pack()
396 #endif
397 
398 #endif	/* _SYSCALL32 */
399 
400 /* MODE MASKS */
401 
402 /* de facto standard definitions */
403 
404 #define	S_IFMT		0xF000	/* type of file */
405 #define	S_IAMB		0x1FF	/* access mode bits */
406 #define	S_IFIFO		0x1000	/* fifo */
407 #define	S_IFCHR		0x2000	/* character special */
408 #define	S_IFDIR		0x4000	/* directory */
409 /* XENIX definitions are not relevant to Solaris */
410 #define	S_IFNAM		0x5000  /* XENIX special named file */
411 #define	S_INSEM		0x1	/* XENIX semaphore subtype of IFNAM */
412 #define	S_INSHD		0x2	/* XENIX shared data subtype of IFNAM */
413 #define	S_IFBLK		0x6000	/* block special */
414 #define	S_IFREG		0x8000	/* regular */
415 #define	S_IFLNK		0xA000	/* symbolic link */
416 #define	S_IFSOCK	0xC000	/* socket */
417 #define	S_IFDOOR	0xD000	/* door */
418 #define	S_IFPORT	0xE000	/* event port */
419 #define	S_ISUID		0x800	/* set user id on execution */
420 #define	S_ISGID		0x400	/* set group id on execution */
421 #define	S_ISVTX		0x200	/* save swapped text even after use */
422 #define	S_IREAD		00400	/* read permission, owner */
423 #define	S_IWRITE	00200	/* write permission, owner */
424 #define	S_IEXEC		00100	/* execute/search permission, owner */
425 #define	S_ENFMT		S_ISGID	/* record locking enforcement flag */
426 
427 /* the following macros are for POSIX conformance */
428 
429 #define	S_IRWXU		00700	/* read, write, execute: owner */
430 #define	S_IRUSR		00400	/* read permission: owner */
431 #define	S_IWUSR		00200	/* write permission: owner */
432 #define	S_IXUSR		00100	/* execute permission: owner */
433 #define	S_IRWXG		00070	/* read, write, execute: group */
434 #define	S_IRGRP		00040	/* read permission: group */
435 #define	S_IWGRP		00020	/* write permission: group */
436 #define	S_IXGRP		00010	/* execute permission: group */
437 #define	S_IRWXO		00007	/* read, write, execute: other */
438 #define	S_IROTH		00004	/* read permission: other */
439 #define	S_IWOTH		00002	/* write permission: other */
440 #define	S_IXOTH		00001	/* execute permission: other */
441 
442 
443 #define	S_ISFIFO(mode)	(((mode)&0xF000) == 0x1000)
444 #define	S_ISCHR(mode)	(((mode)&0xF000) == 0x2000)
445 #define	S_ISDIR(mode)	(((mode)&0xF000) == 0x4000)
446 #define	S_ISBLK(mode)	(((mode)&0xF000) == 0x6000)
447 #define	S_ISREG(mode)	(((mode)&0xF000) == 0x8000)
448 #define	S_ISLNK(mode)	(((mode)&0xF000) == 0xa000)
449 #define	S_ISSOCK(mode)	(((mode)&0xF000) == 0xc000)
450 #define	S_ISDOOR(mode)	(((mode)&0xF000) == 0xd000)
451 #define	S_ISPORT(mode)	(((mode)&0xF000) == 0xe000)
452 
453 /* POSIX.4 macros */
454 #define	S_TYPEISMQ(_buf)	(0)
455 #define	S_TYPEISSEM(_buf)	(0)
456 #define	S_TYPEISSHM(_buf)	(0)
457 
458 #if defined(__i386) || (defined(__i386_COMPAT) && defined(_KERNEL))
459 
460 /*
461  * A version number is included in the x86 SVR4 stat and mknod interfaces
462  * so that SVR4 binaries can be supported.  An LP64 kernel that supports
463  * the i386 ABI need to be aware of this too.
464  */
465 
466 #define	_R3_MKNOD_VER	1	/* SVR3.0 mknod */
467 #define	_MKNOD_VER	2	/* current version of mknod */
468 #define	_R3_STAT_VER	1	/* SVR3.0 stat */
469 #define	_STAT_VER	2	/* current version of stat */
470 
471 #endif	/* __i386 || (__i386_COMPAT && _KERNEL) */
472 
473 #if defined(__EXTENSIONS__) || \
474 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
475 	/* || defined(_XPG7) */
476 /* for use with futimens() and utimensat() */
477 #define	UTIME_NOW	-1L
478 #define	UTIME_OMIT	-2L
479 #endif	/* defined(__EXTENSIONS__) ... */
480 
481 #if !defined(_KERNEL) || defined(_BOOT)
482 
483 #if defined(__STDC__)
484 
485 #if !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2) || \
486 	defined(_XPG4_2) || defined(__EXTENSIONS__)
487 extern int fchmod(int, mode_t);
488 #endif /* !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2)... */
489 
490 extern int chmod(const char *, mode_t);
491 extern int mkdir(const char *, mode_t);
492 extern int mkfifo(const char *, mode_t);
493 extern mode_t umask(mode_t);
494 
495 /* transitional large file interfaces */
496 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
497 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
498 extern int fstat64(int, struct stat64 *);
499 extern int stat64(const char *_RESTRICT_KYWD, struct stat64 *_RESTRICT_KYWD);
500 extern int lstat64(const char *_RESTRICT_KYWD, struct stat64 *_RESTRICT_KYWD);
501 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) || \
502 	defined(_ATFILE_SOURCE)
503 extern int fstatat64(int, const char *, struct stat64 *, int);
504 #endif /* defined (_ATFILE_SOURCE) */
505 #endif
506 
507 #if defined(__EXTENSIONS__) || defined(_ATFILE_SOURCE) || \
508 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
509 	/* || defined(_XPG7) */
510 extern int mkdirat(int, const char *, mode_t);
511 extern int mkfifoat(int, const char *, mode_t);
512 extern int mknodat(int, const char *, mode_t, dev_t);
513 extern int fchmodat(int, const char *, mode_t, int);
514 extern int futimens(int, const struct timespec[2]);
515 extern int utimensat(int, const char *, const struct timespec[2], int);
516 #endif	/* defined(__EXTENSIONS__) ... */
517 
518 #else /* !__STDC__ */
519 
520 #if !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2) || \
521 	defined(_XPG4_2) || defined(__EXTENSIONS__)
522 extern int fchmod();
523 #endif /* !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2)... */
524 
525 extern int chmod();
526 extern int mkdir();
527 extern int mkfifo();
528 extern mode_t umask();
529 
530 /* transitional large file interfaces */
531 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
532 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
533 extern int fstat64();
534 extern int stat64();
535 extern int lstat64();
536 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) || \
537 	defined(_ATFILE_SOURCE)
538 extern int fstatat64();
539 #endif /* defined (_ATFILE_SOURCE) */
540 #endif
541 
542 #if defined(__EXTENSIONS__) || defined(_ATFILE_SOURCE) || \
543 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
544 	/* || defined(_XPG7) */
545 extern int mkdirat();
546 extern int mkfifoat();
547 extern int mknodat();
548 extern int fchmodat();
549 extern int futimens();
550 extern int utimensat();
551 #endif	/* defined(__EXTENSIONS__) ... */
552 
553 #endif /* defined(__STDC__) */
554 
555 #include <sys/stat_impl.h>
556 
557 #endif /* !defined(_KERNEL) */
558 
559 #ifdef	__cplusplus
560 }
561 #endif
562 
563 #endif	/* _SYS_STAT_H */
564