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