xref: /titanic_52/usr/src/uts/common/sys/stat.h (revision 275c9da86e89f8abf71135cf63d9fc23671b2e60)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.	*/
28 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T	*/
29 /*	All Rights Reserved	*/
30 
31 #ifndef _SYS_STAT_H
32 #define	_SYS_STAT_H
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"
35 
36 #include <sys/feature_tests.h>
37 #include <sys/types.h>
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 /*
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.
55  */
56 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
57 #include <sys/time_impl.h>
58 #else
59 #include <sys/time_std_impl.h>
60 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
61 
62 #define	_ST_FSTYPSZ 16		/* array size for file system type name */
63 
64 /*
65  * stat structure, used by stat(2) and fstat(2)
66  */
67 
68 #if defined(_KERNEL)
69 
70 	/* Expanded stat structure */
71 
72 #if defined(_LP64)
73 
74 struct stat {
75 	dev_t		st_dev;
76 	ino_t		st_ino;
77 	mode_t		st_mode;
78 	nlink_t		st_nlink;
79 	uid_t		st_uid;
80 	gid_t		st_gid;
81 	dev_t		st_rdev;
82 	off_t		st_size;
83 	timestruc_t	st_atim;
84 	timestruc_t	st_mtim;
85 	timestruc_t	st_ctim;
86 	blksize_t	st_blksize;
87 	blkcnt_t	st_blocks;
88 	char		st_fstype[_ST_FSTYPSZ];
89 };
90 
91 struct stat64 {
92 	dev_t		st_dev;
93 	ino_t		st_ino;
94 	mode_t		st_mode;
95 	nlink_t		st_nlink;
96 	uid_t		st_uid;
97 	gid_t		st_gid;
98 	dev_t		st_rdev;
99 	off_t		st_size;
100 	timestruc_t	st_atim;
101 	timestruc_t	st_mtim;
102 	timestruc_t	st_ctim;
103 	blksize_t	st_blksize;
104 	blkcnt_t	st_blocks;
105 	char		st_fstype[_ST_FSTYPSZ];
106 };
107 
108 #else	/* _LP64 */
109 
110 struct	stat {
111 	dev_t		st_dev;
112 	long		st_pad1[3];	/* reserve for dev expansion, */
113 					/* sysid definition */
114 	ino_t		st_ino;
115 	mode_t		st_mode;
116 	nlink_t		st_nlink;
117 	uid_t		st_uid;
118 	gid_t		st_gid;
119 	dev_t		st_rdev;
120 	long		st_pad2[2];
121 	off_t		st_size;
122 	long		st_pad3;	/* pad for future off_t expansion */
123 	timestruc_t	st_atim;
124 	timestruc_t	st_mtim;
125 	timestruc_t	st_ctim;
126 	blksize_t	st_blksize;
127 	blkcnt_t	st_blocks;
128 	char		st_fstype[_ST_FSTYPSZ];
129 	long		st_pad4[8];	/* expansion area */
130 };
131 
132 struct  stat64 {
133 	dev_t		st_dev;
134 	long		st_pad1[3];	/* reserve for dev expansion, */
135 				/* sysid definition */
136 	ino64_t		st_ino;
137 	mode_t		st_mode;
138 	nlink_t		st_nlink;
139 	uid_t		st_uid;
140 	gid_t		st_gid;
141 	dev_t		st_rdev;
142 	long		st_pad2[2];
143 	off64_t		st_size;	/* large file support */
144 	timestruc_t	st_atim;
145 	timestruc_t	st_mtim;
146 	timestruc_t	st_ctim;
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 */
151 };
152 
153 #endif	/* _LP64 */
154 
155 #else /* !defined(_KERNEL) */
156 
157 /*
158  * large file compilation environment setup
159  */
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) */
168 
169 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG_2) || defined(__EXTENSIONS__)
170 #pragma	redefine_extname	lstat	lstat64
171 #endif
172 #else	/* __PRAGMA_REDEFINE_EXTNAME */
173 #define	fstat	fstat64
174 #define	stat	stat64
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
181 #endif
182 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
183 #endif	/* !_LP64 && _FILE_OFFSET_BITS == 64 */
184 
185 /*
186  * In the LP64 compilation environment, map large file interfaces
187  * back to native versions where possible.
188  */
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
199 #endif
200 #else	/* __PRAGMA_REDEFINE_EXTNAME */
201 #define	fstat64	fstat
202 #define	stat64	stat
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
209 #endif
210 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
211 #endif	/* _LP64 && _LARGEFILE64_SOURCE */
212 
213 /*
214  * User level stat structure definitions.
215  */
216 
217 #if defined(_LP64)
218 
219 struct stat {
220 	dev_t		st_dev;
221 	ino_t		st_ino;
222 	mode_t		st_mode;
223 	nlink_t		st_nlink;
224 	uid_t		st_uid;
225 	gid_t		st_gid;
226 	dev_t		st_rdev;
227 	off_t		st_size;
228 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
229 	timestruc_t	st_atim;
230 	timestruc_t	st_mtim;
231 	timestruc_t	st_ctim;
232 #else
233 	_timestruc_t	st_atim;
234 	_timestruc_t	st_mtim;
235 	_timestruc_t	st_ctim;
236 #endif
237 	blksize_t	st_blksize;
238 	blkcnt_t	st_blocks;
239 	char		st_fstype[_ST_FSTYPSZ];
240 };
241 
242 #else	/* _LP64 */
243 
244 struct	stat {
245 	dev_t		st_dev;
246 	long		st_pad1[3];	/* reserved for network id */
247 	ino_t		st_ino;
248 	mode_t		st_mode;
249 	nlink_t		st_nlink;
250 	uid_t		st_uid;
251 	gid_t		st_gid;
252 	dev_t		st_rdev;
253 	long		st_pad2[2];
254 	off_t		st_size;
255 #if _FILE_OFFSET_BITS != 64
256 	long		st_pad3;	/* future off_t expansion */
257 #endif
258 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
259 	timestruc_t	st_atim;
260 	timestruc_t	st_mtim;
261 	timestruc_t	st_ctim;
262 #else
263 	_timestruc_t	st_atim;
264 	_timestruc_t	st_mtim;
265 	_timestruc_t	st_ctim;
266 #endif
267 	blksize_t	st_blksize;
268 	blkcnt_t	st_blocks;
269 	char		st_fstype[_ST_FSTYPSZ];
270 	long		st_pad4[8];	/* expansion area */
271 };
272 
273 #endif	/* _LP64 */
274 
275 /* transitional large file interface version */
276 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
277 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
278 #if defined(_LP64)
279 
280 struct stat64 {
281 	dev_t		st_dev;
282 	ino_t		st_ino;
283 	mode_t		st_mode;
284 	nlink_t		st_nlink;
285 	uid_t		st_uid;
286 	gid_t		st_gid;
287 	dev_t		st_rdev;
288 	off_t		st_size;
289 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
290 	timestruc_t	st_atim;
291 	timestruc_t	st_mtim;
292 	timestruc_t	st_ctim;
293 #else
294 	_timestruc_t	st_atim;
295 	_timestruc_t	st_mtim;
296 	_timestruc_t	st_ctim;
297 #endif
298 	blksize_t	st_blksize;
299 	blkcnt_t	st_blocks;
300 	char		st_fstype[_ST_FSTYPSZ];
301 };
302 
303 #else	/* _LP64 */
304 
305 struct	stat64 {
306 	dev_t		st_dev;
307 	long		st_pad1[3];	/* reserved for network id */
308 	ino64_t		st_ino;
309 	mode_t		st_mode;
310 	nlink_t		st_nlink;
311 	uid_t		st_uid;
312 	gid_t		st_gid;
313 	dev_t		st_rdev;
314 	long		st_pad2[2];
315 	off64_t		st_size;
316 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
317 	timestruc_t	st_atim;
318 	timestruc_t	st_mtim;
319 	timestruc_t	st_ctim;
320 #else
321 	_timestruc_t    st_atim;
322 	_timestruc_t    st_mtim;
323 	_timestruc_t    st_ctim;
324 #endif
325 	blksize_t	st_blksize;
326 	blkcnt64_t	st_blocks;
327 	char		st_fstype[_ST_FSTYPSZ];
328 	long		st_pad4[8];	/* expansion area */
329 };
330 
331 #endif	/* _LP64 */
332 #endif
333 
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
338 #else
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__) */
343 
344 #endif /* end defined(_KERNEL) */
345 
346 #if defined(_SYSCALL32)
347 
348 /*
349  * Kernel's view of user ILP32 stat and stat64 structures
350  */
351 
352 struct stat32 {
353 	dev32_t		st_dev;
354 	int32_t		st_pad1[3];
355 	ino32_t		st_ino;
356 	mode32_t	st_mode;
357 	nlink32_t	st_nlink;
358 	uid32_t		st_uid;
359 	gid32_t		st_gid;
360 	dev32_t		st_rdev;
361 	int32_t		st_pad2[2];
362 	off32_t		st_size;
363 	int32_t		st_pad3;
364 	timestruc32_t	st_atim;
365 	timestruc32_t	st_mtim;
366 	timestruc32_t	st_ctim;
367 	int32_t		st_blksize;
368 	blkcnt32_t	st_blocks;
369 	char		st_fstype[_ST_FSTYPSZ];
370 	int32_t		st_pad4[8];
371 };
372 
373 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
374 #pragma pack(4)
375 #endif
376 
377 struct stat64_32 {
378 	dev32_t		st_dev;
379 	int32_t		st_pad1[3];
380 	ino64_t		st_ino;
381 	mode32_t	st_mode;
382 	nlink32_t	st_nlink;
383 	uid32_t		st_uid;
384 	gid32_t		st_gid;
385 	dev32_t		st_rdev;
386 	int32_t		st_pad2[2];
387 	off64_t		st_size;
388 	timestruc32_t	st_atim;
389 	timestruc32_t	st_mtim;
390 	timestruc32_t	st_ctim;
391 	int32_t		st_blksize;
392 	blkcnt64_t	st_blocks;
393 	char		st_fstype[_ST_FSTYPSZ];
394 	int32_t		st_pad4[8];
395 };
396 
397 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
398 #pragma pack()
399 #endif
400 
401 #endif	/* _SYSCALL32 */
402 
403 /* MODE MASKS */
404 
405 /* de facto standard definitions */
406 
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 */
429 
430 /* the following macros are for POSIX conformance */
431 
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 */
444 
445 
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)
455 
456 /* POSIX.4 macros */
457 #define	S_TYPEISMQ(_buf)	(0)
458 #define	S_TYPEISSEM(_buf)	(0)
459 #define	S_TYPEISSHM(_buf)	(0)
460 
461 #if defined(__i386) || (defined(__i386_COMPAT) && defined(_KERNEL))
462 
463 /*
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.
467  */
468 
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 */
473 
474 #endif	/* __i386 || (__i386_COMPAT && _KERNEL) */
475 
476 #if !defined(_KERNEL) || defined(_BOOT)
477 
478 #if defined(__STDC__)
479 
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)... */
484 
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);
489 
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) */
500 #endif
501 
502 #else /* !__STDC__ */
503 
504 #if !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2) || \
505 	defined(_XPG4_2) || defined(__EXTENSIONS__)
506 extern int fchmod();
507 #endif /* !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2)... */
508 
509 extern int chmod();
510 extern int mkdir();
511 extern int mkfifo();
512 extern mode_t umask();
513 
514 /* transitional large file interfaces */
515 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
516 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
517 extern int fstat64();
518 extern int stat64();
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) */
524 #endif
525 
526 #endif /* defined(__STDC__) */
527 
528 #include <sys/stat_impl.h>
529 
530 #endif /* !defined(_KERNEL) */
531 
532 #ifdef	__cplusplus
533 }
534 #endif
535 
536 #endif	/* _SYS_STAT_H */
537