dirent.h revision 201602
11539Srgrimes/*-
21539Srgrimes * Copyright (c) 1989, 1993
31539Srgrimes *	The Regents of the University of California.  All rights reserved.
41539Srgrimes *
51539Srgrimes * Redistribution and use in source and binary forms, with or without
61539Srgrimes * modification, are permitted provided that the following conditions
71539Srgrimes * are met:
81539Srgrimes * 1. Redistributions of source code must retain the above copyright
91539Srgrimes *    notice, this list of conditions and the following disclaimer.
101539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111539Srgrimes *    notice, this list of conditions and the following disclaimer in the
121539Srgrimes *    documentation and/or other materials provided with the distribution.
131539Srgrimes * 3. All advertising materials mentioning features or use of this software
141539Srgrimes *    must display the following acknowledgement:
151539Srgrimes *	This product includes software developed by the University of
161539Srgrimes *	California, Berkeley and its contributors.
171539Srgrimes * 4. Neither the name of the University nor the names of its contributors
181539Srgrimes *    may be used to endorse or promote products derived from this software
191539Srgrimes *    without specific prior written permission.
201539Srgrimes *
211539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241539Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311539Srgrimes * SUCH DAMAGE.
321539Srgrimes *
3323654Speter *	@(#)dirent.h	8.2 (Berkeley) 7/28/94
3453812Salfred * $FreeBSD: head/include/dirent.h 201602 2010-01-05 20:17:13Z kib $
351539Srgrimes */
361539Srgrimes
371539Srgrimes#ifndef _DIRENT_H_
381539Srgrimes#define _DIRENT_H_
391539Srgrimes
401539Srgrimes/*
418858Srgrimes * The kernel defines the format of directory entries returned by
421539Srgrimes * the getdirentries(2) system call.
431539Srgrimes */
44103192Smike#include <sys/cdefs.h>
451539Srgrimes#include <sys/dirent.h>
461539Srgrimes
47103192Smike#if __BSD_VISIBLE || __XSI_VISIBLE
48103192Smike/*
49103192Smike * XXX this is probably illegal in the __XSI_VISIBLE case, but brings us closer
50103192Smike * to the specification.
51103192Smike */
52103192Smike#define	d_ino		d_fileno	/* backward and XSI compatibility */
53103192Smike#endif
541539Srgrimes
55103192Smike#if __BSD_VISIBLE
561539Srgrimes
57123257Smarcel#include <sys/_null.h>
58123257Smarcel
591539Srgrimes/* definitions for library routines operating on directories. */
601539Srgrimes#define	DIRBLKSIZ	1024
611539Srgrimes
6269841Sdeischenstruct _telldir;		/* see telldir.h */
63173762Sjbstruct pthread_mutex;
6469655Sdeischen
651539Srgrimes/* structure describing an open directory. */
661539Srgrimestypedef struct _dirdesc {
671539Srgrimes	int	dd_fd;		/* file descriptor associated with directory */
681539Srgrimes	long	dd_loc;		/* offset in current buffer */
691539Srgrimes	long	dd_size;	/* amount of data returned by getdirentries */
701539Srgrimes	char	*dd_buf;	/* data buffer */
711539Srgrimes	int	dd_len;		/* size of data buffer */
721539Srgrimes	long	dd_seek;	/* magic cookie returned by getdirentries */
731539Srgrimes	long	dd_rewind;	/* magic cookie for rewinding */
7423654Speter	int	dd_flags;	/* flags for readdir */
75173762Sjb	struct pthread_mutex	*dd_lock;	/* lock */
7669841Sdeischen	struct _telldir *dd_td;	/* telldir position recording */
771539Srgrimes} DIR;
781539Srgrimes
791539Srgrimes#define	dirfd(dirp)	((dirp)->dd_fd)
801539Srgrimes
8123654Speter/* flags for opendir2 */
8223654Speter#define DTF_HIDEW	0x0001	/* hide whiteout entries */
8323654Speter#define DTF_NODUP	0x0002	/* don't return duplicate names */
8423654Speter#define DTF_REWIND	0x0004	/* rewind after reading union stack */
8523654Speter#define __DTF_READALL	0x0008	/* everything has been read */
8623654Speter
87103192Smike#else /* !__BSD_VISIBLE */
881539Srgrimes
89103192Smiketypedef	void *	DIR;
90103192Smike
91103192Smike#endif /* __BSD_VISIBLE */
92103192Smike
9355206Speter#ifndef _KERNEL
941539Srgrimes
951539Srgrimes__BEGIN_DECLS
96201602Skib#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 700
97201602Skibint	 alphasort(const struct dirent **, const struct dirent **);
98201602Skib#endif
99103192Smike#if __BSD_VISIBLE
100103192SmikeDIR	*__opendir2(const char *, int);
101103192Smikeint	 getdents(int, char *, int);
102103192Smikeint	 getdirentries(int, char *, int, long *);
103103192Smike#endif
104103111SmikeDIR	*opendir(const char *);
105178256SdelphijDIR	*fdopendir(int);
106103111Smikestruct dirent *
107103111Smike	 readdir(DIR *);
108103192Smike#if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE >= 500
109103192Smikeint	 readdir_r(DIR *, struct dirent *, struct dirent **);
110103192Smike#endif
111103111Smikevoid	 rewinddir(DIR *);
112201602Skib#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 700
113103111Smikeint	 scandir(const char *, struct dirent ***,
114201512Skib	    int (*)(const struct dirent *), int (*)(const struct dirent **,
115201512Skib	    const struct dirent **));
116103192Smike#endif
117103192Smike#if __XSI_VISIBLE
118103192Smikevoid	 seekdir(DIR *, long);
119103192Smikelong	 telldir(DIR *);
120103192Smike#endif
121103192Smikeint	 closedir(DIR *);
1221539Srgrimes__END_DECLS
1231539Srgrimes
12455206Speter#endif /* !_KERNEL */
1251539Srgrimes
1261539Srgrimes#endif /* !_DIRENT_H_ */
127