summaryrefslogtreecommitdiff
path: root/usr/src/ucbhead/sys/dir.h
blob: 1cf5567127a466829511854378d1f1f5f00c0802 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
/*	  All Rights Reserved	*/

/*
 * University Copyright- Copyright (c) 1982, 1986, 1988
 * The Regents of the University of California
 * All Rights Reserved
 *
 * University Acknowledgment- Portions of this document are derived from
 * software developed by the University of California, Berkeley, and its
 * contributors.
 */

#ifndef _SYS_DIR_H
#define	_SYS_DIR_H

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include <sys/isa_defs.h>
#include <sys/int_types.h>

/*
 * This header file provides BSD compatibility for DIR and direct structures.
 * The fields in the BSD DIR structure are identical to to the SVR4 DIR
 * structure, except for the fact that the dd_buf field in SVR4 is not
 * statically allocated.
 * The BSD direct structure is similar (not identical) to the dirent
 * structure. All fields of the direct structure can be obtained using
 * the information provided by dirent.
 * All routines manipulating DIR structures are compatible, only readdir
 * is not. The BSD version of this routine returns a direct structure.
 */

#ifdef __cplusplus
extern "C" {
#endif

#if !defined(KERNEL) && !defined(DEV_BSIZE)
#define	DEV_BSIZE	512
#endif
#define	DIRBUF		8192
#define	DIRBLKSIZ	DIRBUF
#define	MAXNAMLEN	255

#if _FILE_OFFSET_BITS == 32
struct	direct {
	ulong_t	d_ino;			/* inode number of entry */
	ushort_t d_reclen;		/* length of this record */
	ushort_t d_namlen;		/* length of string in d_name */
	char	d_name[MAXNAMLEN+1];	/* name of entry */
};
#elif _FILE_OFFSET_BITS == 64
struct	direct {
	ino_t	d_ino;			/* inode number of entry */
	ushort_t d_reclen;		/* length of this record */
	ushort_t d_namlen;		/* length of string in d_name */
	char	d_name[MAXNAMLEN+1];	/* name of entry */
};
#endif
#if	defined(_LARGEFILE64_SOURCE)
struct	direct64 {
	ino64_t	d_ino;			/* inode number of entry */
	ushort_t d_reclen;		/* length of this record */
	ushort_t d_namlen;		/* length of string in d_name */
	char	d_name[MAXNAMLEN+1];	/* name of entry */
};
#endif

/*
 * The macro DIRSIZ(dp) gives an amount of space required to represent
 * a directory entry.
 */
#undef DIRSIZ
#undef DIRSIZ64

#if _FILE_OFFSET_BITS == 32
#define	DIRSIZ(dp)  \
	((sizeof (struct direct) - sizeof ((dp)->d_name) + \
	(strlen((dp)->d_name)+1) + 3) & ~3)
#elif _FILE_OFFSET_BITS == 64
#define	DIRSIZ(dp)  \
	((sizeof (struct direct64) - sizeof ((dp)->d_name) + \
	(strlen((dp)->d_name)+1) + 3) & ~3)
#endif
#if	defined(_LARGEFILE64_SOURCE)
#define	DIRSIZ64(dp)  \
	((sizeof (struct direct64) - sizeof ((dp)->d_name) + \
	(strlen((dp)->d_name)+1) + 3) & ~3)
#endif

#ifndef KERNEL
/*
 * Definitions for library routines operating on directories.
 */
typedef struct _dirdesc {
	int	dd_fd;
	int	dd_loc;
	int	dd_size;
	char	*dd_buf;
} DIR;

#ifndef NULL
#define	NULL 0
#endif

#if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
#ifdef __PRAGMA_REDEFINE_EXTNAME
#pragma redefine_extname	readdir64		readdir
#pragma redefine_extname	scandir64		scandir
#pragma redefine_extname	alphasort64	alphasort
#else
#define	readdir64			readdir
#define	scandir64			scandir
#define	alphasort64		alphasort
#define	direct64		direct
#endif
#endif

#if !defined(_LP64) && (_FILE_OFFSET_BITS == 64)
#ifdef __PRAGMA_REDEFINE_EXTNAME
#pragma redefine_extname	readdir		readdir64
#pragma redefine_extname	scandir		scandir64
#pragma redefine_extname	alphasort	alphasort64
#else
#define	readdir			readdir64
#define	scandir			scandir64
#define	alphasort		alphasort64
#define	direct			direct64
#endif
#endif

#if defined(__STDC__)
extern DIR		*opendir(const char *);
extern struct direct    *readdir(DIR *);
extern long		telldir(DIR *);
extern void		seekdir(DIR *, long);
extern int		scandir(char *, struct direct *(*[]),
			    int (*)(struct direct *),
			    int (*)(struct direct **, struct direct **));
extern int		alphasort(struct direct **, struct direct **);
extern void		rewinddir(DIR *);
extern int		closedir(DIR *);
#else
extern	DIR *opendir();
extern	struct direct *readdir();
extern	long telldir();
extern	void seekdir();
extern	int scandir();
extern	int alphasort();
extern  void rewinddir();
extern	void closedir();
#endif

#if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
	    !defined(__PRAGMA_REDEFINE_EXTNAME))
#if defined(__STDC__)
extern struct direct64	*readdir64(DIR *);
extern int		scandir64(char *, struct direct64 *(*[]),
			    int (*)(struct direct64 *),
			    int (*)(struct direct64 **, struct direct64 **));
extern int		alphasort64(struct direct64 **, struct direct64 **);
#else
extern struct direct64	*readdir64();
extern int		scandir64();
extern int		alphasort64();
#endif
#endif	/* _LARGEFILE64_SOURCE... */

#define	rewinddir(dirp)	seekdir((dirp), 0)

#endif

#ifdef __cplusplus
}
#endif

#endif	/* _SYS_DIR_H */