xref: /titanic_51/usr/src/uts/common/sys/dirent.h (revision 450396635f70344c58b6b1e4db38cf17ff34445c)
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 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #ifndef _SYS_DIRENT_H
32 #define	_SYS_DIRENT_H
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 11.11 */
35 
36 #include <sys/feature_tests.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  * File-system independent directory entry.
44  */
45 typedef struct dirent {
46 	ino_t		d_ino;		/* "inode number" of entry */
47 	off_t		d_off;		/* offset of disk directory entry */
48 	unsigned short	d_reclen;	/* length of this record */
49 	char		d_name[1];	/* name of file */
50 } dirent_t;
51 
52 #if defined(_SYSCALL32)
53 
54 /* kernel's view of user ILP32 dirent */
55 
56 typedef	struct dirent32 {
57 	ino32_t		d_ino;		/* "inode number" of entry */
58 	off32_t		d_off;		/* offset of disk directory entry */
59 	uint16_t	d_reclen;	/* length of this record */
60 	char		d_name[1];	/* name of file */
61 } dirent32_t;
62 
63 #endif	/* _SYSCALL32 */
64 
65 #ifdef	_LARGEFILE64_SOURCE
66 
67 /*
68  * transitional large file interface version AND kernel internal version
69  */
70 typedef struct dirent64 {
71 	ino64_t		d_ino;		/* "inode number" of entry */
72 	off64_t		d_off;		/* offset of disk directory entry */
73 	unsigned short	d_reclen;	/* length of this record */
74 	char		d_name[1];	/* name of file */
75 } dirent64_t;
76 
77 #endif	/* _LARGEFILE64_SOURCE */
78 
79 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
80 #if defined(_KERNEL)
81 #define	DIRENT64_RECLEN(namelen)	\
82 	((offsetof(dirent64_t, d_name[0]) + 1 + (namelen) + 7) & ~ 7)
83 #define	DIRENT64_NAMELEN(reclen)	\
84 	((reclen) - (offsetof(dirent64_t, d_name[0])))
85 #define	DIRENT32_RECLEN(namelen)	\
86 	((offsetof(dirent32_t, d_name[0]) + 1 + (namelen) + 3) & ~ 3)
87 #define	DIRENT32_NAMELEN(reclen)	\
88 	((reclen) - (offsetof(dirent32_t, d_name[0])))
89 #endif
90 
91 #if !defined(_KERNEL)
92 
93 /*
94  * large file compilation environment setup
95  *
96  * In the LP64 compilation environment, map large file interfaces
97  * back to native versions where possible. (This only works because
98  * a 'struct dirent' == 'struct dirent64').
99  */
100 
101 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
102 #ifdef	__PRAGMA_REDEFINE_EXTNAME
103 #pragma redefine_extname	getdents	getdents64
104 #else
105 #define	getdents		getdents64
106 #endif
107 #endif	/* !_LP64 && _FILE_OFFSET_BITS == 64 */
108 
109 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
110 #ifdef	__PRAGMA_REDEFINE_EXTNAME
111 #pragma	redefine_extname	getdents64	getdents
112 #else
113 #define	getdents64		getdents
114 #define	dirent64		dirent
115 #define	dirent64_t		dirent_t
116 #endif
117 #endif	/* _LP64 && _LARGEFILE64_SOURCE */
118 
119 #if defined(__STDC__)
120 extern int getdents(int, struct dirent *, size_t);
121 #else
122 extern int getdents();
123 #endif
124 
125 /* N.B.: transitional large file interface version deliberately not provided */
126 
127 #endif /* !defined(_KERNEL) */
128 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
129 
130 #ifdef	__cplusplus
131 }
132 #endif
133 
134 #endif	/* _SYS_DIRENT_H */
135