xref: /titanic_54/usr/src/uts/common/sys/dirent.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate /*
27*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
29*7c478bd9Sstevel@tonic-gate  */
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #ifndef _SYS_DIRENT_H
32*7c478bd9Sstevel@tonic-gate #define	_SYS_DIRENT_H
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 11.11 */
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
39*7c478bd9Sstevel@tonic-gate extern "C" {
40*7c478bd9Sstevel@tonic-gate #endif
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate /*
43*7c478bd9Sstevel@tonic-gate  * File-system independent directory entry.
44*7c478bd9Sstevel@tonic-gate  */
45*7c478bd9Sstevel@tonic-gate typedef struct dirent {
46*7c478bd9Sstevel@tonic-gate 	ino_t		d_ino;		/* "inode number" of entry */
47*7c478bd9Sstevel@tonic-gate 	off_t		d_off;		/* offset of disk directory entry */
48*7c478bd9Sstevel@tonic-gate 	unsigned short	d_reclen;	/* length of this record */
49*7c478bd9Sstevel@tonic-gate 	char		d_name[1];	/* name of file */
50*7c478bd9Sstevel@tonic-gate } dirent_t;
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate /* kernel's view of user ILP32 dirent */
55*7c478bd9Sstevel@tonic-gate 
56*7c478bd9Sstevel@tonic-gate typedef	struct dirent32 {
57*7c478bd9Sstevel@tonic-gate 	ino32_t		d_ino;		/* "inode number" of entry */
58*7c478bd9Sstevel@tonic-gate 	off32_t		d_off;		/* offset of disk directory entry */
59*7c478bd9Sstevel@tonic-gate 	uint16_t	d_reclen;	/* length of this record */
60*7c478bd9Sstevel@tonic-gate 	char		d_name[1];	/* name of file */
61*7c478bd9Sstevel@tonic-gate } dirent32_t;
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate #ifdef	_LARGEFILE64_SOURCE
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate /*
68*7c478bd9Sstevel@tonic-gate  * transitional large file interface version AND kernel internal version
69*7c478bd9Sstevel@tonic-gate  */
70*7c478bd9Sstevel@tonic-gate typedef struct dirent64 {
71*7c478bd9Sstevel@tonic-gate 	ino64_t		d_ino;		/* "inode number" of entry */
72*7c478bd9Sstevel@tonic-gate 	off64_t		d_off;		/* offset of disk directory entry */
73*7c478bd9Sstevel@tonic-gate 	unsigned short	d_reclen;	/* length of this record */
74*7c478bd9Sstevel@tonic-gate 	char		d_name[1];	/* name of file */
75*7c478bd9Sstevel@tonic-gate } dirent64_t;
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate #endif	/* _LARGEFILE64_SOURCE */
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
80*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
81*7c478bd9Sstevel@tonic-gate #define	DIRENT64_RECLEN(namelen)	\
82*7c478bd9Sstevel@tonic-gate 	((offsetof(dirent64_t, d_name[0]) + 1 + (namelen) + 7) & ~ 7)
83*7c478bd9Sstevel@tonic-gate #define	DIRENT64_NAMELEN(reclen)	\
84*7c478bd9Sstevel@tonic-gate 	((reclen) - (offsetof(dirent64_t, d_name[0])))
85*7c478bd9Sstevel@tonic-gate #define	DIRENT32_RECLEN(namelen)	\
86*7c478bd9Sstevel@tonic-gate 	((offsetof(dirent32_t, d_name[0]) + 1 + (namelen) + 3) & ~ 3)
87*7c478bd9Sstevel@tonic-gate #define	DIRENT32_NAMELEN(reclen)	\
88*7c478bd9Sstevel@tonic-gate 	((reclen) - (offsetof(dirent32_t, d_name[0])))
89*7c478bd9Sstevel@tonic-gate #endif
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate #if !defined(_KERNEL)
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate /*
94*7c478bd9Sstevel@tonic-gate  * large file compilation environment setup
95*7c478bd9Sstevel@tonic-gate  *
96*7c478bd9Sstevel@tonic-gate  * In the LP64 compilation environment, map large file interfaces
97*7c478bd9Sstevel@tonic-gate  * back to native versions where possible. (This only works because
98*7c478bd9Sstevel@tonic-gate  * a 'struct dirent' == 'struct dirent64').
99*7c478bd9Sstevel@tonic-gate  */
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
102*7c478bd9Sstevel@tonic-gate #ifdef	__PRAGMA_REDEFINE_EXTNAME
103*7c478bd9Sstevel@tonic-gate #pragma redefine_extname	getdents	getdents64
104*7c478bd9Sstevel@tonic-gate #else
105*7c478bd9Sstevel@tonic-gate #define	getdents		getdents64
106*7c478bd9Sstevel@tonic-gate #endif
107*7c478bd9Sstevel@tonic-gate #endif	/* !_LP64 && _FILE_OFFSET_BITS == 64 */
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
110*7c478bd9Sstevel@tonic-gate #ifdef	__PRAGMA_REDEFINE_EXTNAME
111*7c478bd9Sstevel@tonic-gate #pragma	redefine_extname	getdents64	getdents
112*7c478bd9Sstevel@tonic-gate #else
113*7c478bd9Sstevel@tonic-gate #define	getdents64		getdents
114*7c478bd9Sstevel@tonic-gate #define	dirent64		dirent
115*7c478bd9Sstevel@tonic-gate #define	dirent64_t		dirent_t
116*7c478bd9Sstevel@tonic-gate #endif
117*7c478bd9Sstevel@tonic-gate #endif	/* _LP64 && _LARGEFILE64_SOURCE */
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate #if defined(__STDC__)
120*7c478bd9Sstevel@tonic-gate extern int getdents(int, struct dirent *, size_t);
121*7c478bd9Sstevel@tonic-gate #else
122*7c478bd9Sstevel@tonic-gate extern int getdents();
123*7c478bd9Sstevel@tonic-gate #endif
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate /* N.B.: transitional large file interface version deliberately not provided */
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate #endif /* !defined(_KERNEL) */
128*7c478bd9Sstevel@tonic-gate #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
131*7c478bd9Sstevel@tonic-gate }
132*7c478bd9Sstevel@tonic-gate #endif
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_DIRENT_H */
135