xref: /illumos-gate/usr/src/ucbhead/sys/dir.h (revision 8c0b080c)
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) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved	*/
29 
30 /*
31  * University Copyright- Copyright (c) 1982, 1986, 1988
32  * The Regents of the University of California
33  * All Rights Reserved
34  *
35  * University Acknowledgment- Portions of this document are derived from
36  * software developed by the University of California, Berkeley, and its
37  * contributors.
38  */
39 
40 #ifndef _SYS_DIR_H
41 #define	_SYS_DIR_H
42 
43 #include <sys/isa_defs.h>
44 #include <sys/int_types.h>
45 
46 /*
47  * This header file provides BSD compatibility for DIR and direct structures.
48  * The fields in the BSD DIR structure are identical to to the SVR4 DIR
49  * structure, except for the fact that the dd_buf field in SVR4 is not
50  * statically allocated.
51  * The BSD direct structure is similar (not identical) to the dirent
52  * structure. All fields of the direct structure can be obtained using
53  * the information provided by dirent.
54  * All routines manipulating DIR structures are compatible, only readdir
55  * is not. The BSD version of this routine returns a direct structure.
56  */
57 
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
62 #if !defined(KERNEL) && !defined(DEV_BSIZE)
63 #define	DEV_BSIZE	512
64 #endif
65 #define	DIRBUF		8192
66 #define	DIRBLKSIZ	DIRBUF
67 #define	MAXNAMLEN	255
68 
69 #if _FILE_OFFSET_BITS == 32
70 struct	direct {
71 	ulong_t	d_ino;			/* inode number of entry */
72 	ushort_t d_reclen;		/* length of this record */
73 	ushort_t d_namlen;		/* length of string in d_name */
74 	char	d_name[MAXNAMLEN+1];	/* name of entry */
75 };
76 #elif _FILE_OFFSET_BITS == 64
77 struct	direct {
78 	ino_t	d_ino;			/* inode number of entry */
79 	ushort_t d_reclen;		/* length of this record */
80 	ushort_t d_namlen;		/* length of string in d_name */
81 	char	d_name[MAXNAMLEN+1];	/* name of entry */
82 };
83 #endif
84 #if	defined(_LARGEFILE64_SOURCE)
85 struct	direct64 {
86 	ino64_t	d_ino;			/* inode number of entry */
87 	ushort_t d_reclen;		/* length of this record */
88 	ushort_t d_namlen;		/* length of string in d_name */
89 	char	d_name[MAXNAMLEN+1];	/* name of entry */
90 };
91 #endif
92 
93 /*
94  * The macro DIRSIZ(dp) gives an amount of space required to represent
95  * a directory entry.
96  */
97 #undef DIRSIZ
98 #undef DIRSIZ64
99 
100 #if _FILE_OFFSET_BITS == 32
101 #define	DIRSIZ(dp)  \
102 	((sizeof (struct direct) - sizeof ((dp)->d_name) + \
103 	(strlen((dp)->d_name)+1) + 3) & ~3)
104 #elif _FILE_OFFSET_BITS == 64
105 #define	DIRSIZ(dp)  \
106 	((sizeof (struct direct64) - sizeof ((dp)->d_name) + \
107 	(strlen((dp)->d_name)+1) + 3) & ~3)
108 #endif
109 #if	defined(_LARGEFILE64_SOURCE)
110 #define	DIRSIZ64(dp)  \
111 	((sizeof (struct direct64) - sizeof ((dp)->d_name) + \
112 	(strlen((dp)->d_name)+1) + 3) & ~3)
113 #endif
114 
115 #ifndef KERNEL
116 /*
117  * Definitions for library routines operating on directories.
118  */
119 typedef struct _dirdesc {
120 	int	dd_fd;
121 	int	dd_loc;
122 	int	dd_size;
123 	char	*dd_buf;
124 } DIR;
125 
126 #ifndef NULL
127 #define	NULL 0
128 #endif
129 
130 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
131 #ifdef __PRAGMA_REDEFINE_EXTNAME
132 #pragma redefine_extname	readdir64		readdir
133 #pragma redefine_extname	scandir64		scandir
134 #pragma redefine_extname	alphasort64	alphasort
135 #else
136 #define	readdir64			readdir
137 #define	scandir64			scandir
138 #define	alphasort64		alphasort
139 #define	direct64		direct
140 #endif
141 #endif
142 
143 #if !defined(_LP64) && (_FILE_OFFSET_BITS == 64)
144 #ifdef __PRAGMA_REDEFINE_EXTNAME
145 #pragma redefine_extname	readdir		readdir64
146 #pragma redefine_extname	scandir		scandir64
147 #pragma redefine_extname	alphasort	alphasort64
148 #else
149 #define	readdir			readdir64
150 #define	scandir			scandir64
151 #define	alphasort		alphasort64
152 #define	direct			direct64
153 #endif
154 #endif
155 
156 #if defined(__STDC__)
157 extern DIR		*opendir(const char *);
158 extern struct direct    *readdir(DIR *);
159 extern long		telldir(DIR *);
160 extern void		seekdir(DIR *, long);
161 extern int		scandir(char *, struct direct *(*[]),
162 			    int (*)(struct direct *),
163 			    int (*)(struct direct **, struct direct **));
164 extern int		alphasort(struct direct **, struct direct **);
165 extern void		rewinddir(DIR *);
166 extern int		closedir(DIR *);
167 #else
168 extern	DIR *opendir();
169 extern	struct direct *readdir();
170 extern	long telldir();
171 extern	void seekdir();
172 extern	int scandir();
173 extern	int alphasort();
174 extern  void rewinddir();
175 extern	void closedir();
176 #endif
177 
178 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
179 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
180 #if defined(__STDC__)
181 extern struct direct64	*readdir64(DIR *);
182 extern int		scandir64(char *, struct direct64 *(*[]),
183 			    int (*)(struct direct64 *),
184 			    int (*)(struct direct64 **, struct direct64 **));
185 extern int		alphasort64(struct direct64 **, struct direct64 **);
186 #else
187 extern struct direct64	*readdir64();
188 extern int		scandir64();
189 extern int		alphasort64();
190 #endif
191 #endif	/* _LARGEFILE64_SOURCE... */
192 
193 #define	rewinddir(dirp)	seekdir((dirp), 0)
194 
195 #endif
196 
197 #ifdef __cplusplus
198 }
199 #endif
200 
201 #endif	/* _SYS_DIR_H */
202