dirent.h revision 201602
1228753Smm/*- 2228753Smm * Copyright (c) 1989, 1993 3228753Smm * The Regents of the University of California. All rights reserved. 4228753Smm * 5228753Smm * Redistribution and use in source and binary forms, with or without 6228753Smm * modification, are permitted provided that the following conditions 7228753Smm * are met: 8228753Smm * 1. Redistributions of source code must retain the above copyright 9228753Smm * notice, this list of conditions and the following disclaimer. 10228753Smm * 2. Redistributions in binary form must reproduce the above copyright 11228753Smm * notice, this list of conditions and the following disclaimer in the 12228753Smm * documentation and/or other materials provided with the distribution. 13228753Smm * 3. All advertising materials mentioning features or use of this software 14228753Smm * must display the following acknowledgement: 15228753Smm * This product includes software developed by the University of 16228753Smm * California, Berkeley and its contributors. 17228753Smm * 4. Neither the name of the University nor the names of its contributors 18228753Smm * may be used to endorse or promote products derived from this software 19228753Smm * without specific prior written permission. 20228753Smm * 21228753Smm * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22228753Smm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23228753Smm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24228753Smm * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25229592Smm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26228753Smm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27228753Smm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28228753Smm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29228753Smm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30228753Smm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31228753Smm * SUCH DAMAGE. 32228753Smm * 33228753Smm * @(#)dirent.h 8.2 (Berkeley) 7/28/94 34228753Smm * $FreeBSD: head/include/dirent.h 201602 2010-01-05 20:17:13Z kib $ 35228753Smm */ 36228753Smm 37228753Smm#ifndef _DIRENT_H_ 38228753Smm#define _DIRENT_H_ 39228753Smm 40228753Smm/* 41228753Smm * The kernel defines the format of directory entries returned by 42228753Smm * the getdirentries(2) system call. 43228753Smm */ 44228753Smm#include <sys/cdefs.h> 45228753Smm#include <sys/dirent.h> 46228753Smm 47228753Smm#if __BSD_VISIBLE || __XSI_VISIBLE 48228753Smm/* 49228753Smm * XXX this is probably illegal in the __XSI_VISIBLE case, but brings us closer 50228753Smm * to the specification. 51228753Smm */ 52228753Smm#define d_ino d_fileno /* backward and XSI compatibility */ 53228753Smm#endif 54228753Smm 55228753Smm#if __BSD_VISIBLE 56228753Smm 57228753Smm#include <sys/_null.h> 58228753Smm 59228753Smm/* definitions for library routines operating on directories. */ 60228753Smm#define DIRBLKSIZ 1024 61228753Smm 62228753Smmstruct _telldir; /* see telldir.h */ 63228753Smmstruct pthread_mutex; 64228753Smm 65228753Smm/* structure describing an open directory. */ 66228753Smmtypedef struct _dirdesc { 67228753Smm int dd_fd; /* file descriptor associated with directory */ 68228753Smm long dd_loc; /* offset in current buffer */ 69228753Smm long dd_size; /* amount of data returned by getdirentries */ 70228753Smm char *dd_buf; /* data buffer */ 71228753Smm int dd_len; /* size of data buffer */ 72228753Smm long dd_seek; /* magic cookie returned by getdirentries */ 73228753Smm long dd_rewind; /* magic cookie for rewinding */ 74228753Smm int dd_flags; /* flags for readdir */ 75228753Smm struct pthread_mutex *dd_lock; /* lock */ 76228753Smm struct _telldir *dd_td; /* telldir position recording */ 77228753Smm} DIR; 78228753Smm 79228753Smm#define dirfd(dirp) ((dirp)->dd_fd) 80228753Smm 81228753Smm/* flags for opendir2 */ 82228753Smm#define DTF_HIDEW 0x0001 /* hide whiteout entries */ 83228753Smm#define DTF_NODUP 0x0002 /* don't return duplicate names */ 84228753Smm#define DTF_REWIND 0x0004 /* rewind after reading union stack */ 85228753Smm#define __DTF_READALL 0x0008 /* everything has been read */ 86228753Smm 87228753Smm#else /* !__BSD_VISIBLE */ 88228753Smm 89228753Smmtypedef void * DIR; 90228753Smm 91228753Smm#endif /* __BSD_VISIBLE */ 92228753Smm 93228753Smm#ifndef _KERNEL 94228753Smm 95228753Smm__BEGIN_DECLS 96228753Smm#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 700 97228753Smmint alphasort(const struct dirent **, const struct dirent **); 98228753Smm#endif 99228753Smm#if __BSD_VISIBLE 100228753SmmDIR *__opendir2(const char *, int); 101228753Smmint getdents(int, char *, int); 102228753Smmint getdirentries(int, char *, int, long *); 103228753Smm#endif 104228753SmmDIR *opendir(const char *); 105228753SmmDIR *fdopendir(int); 106228753Smmstruct dirent * 107228753Smm readdir(DIR *); 108228753Smm#if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE >= 500 109228753Smmint readdir_r(DIR *, struct dirent *, struct dirent **); 110228753Smm#endif 111228753Smmvoid rewinddir(DIR *); 112228753Smm#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 700 113228753Smmint scandir(const char *, struct dirent ***, 114228753Smm int (*)(const struct dirent *), int (*)(const struct dirent **, 115228753Smm const struct dirent **)); 116228753Smm#endif 117228753Smm#if __XSI_VISIBLE 118228753Smmvoid seekdir(DIR *, long); 119228753Smmlong telldir(DIR *); 120228753Smm#endif 121228753Smmint closedir(DIR *); 122228753Smm__END_DECLS 123228753Smm 124228753Smm#endif /* !_KERNEL */ 125228753Smm 126228753Smm#endif /* !_DIRENT_H_ */ 127228753Smm