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