11541Srgrimes/*-
21541Srgrimes * Copyright (c) 1989, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes * 4. Neither the name of the University nor the names of its contributors
141541Srgrimes *    may be used to endorse or promote products derived from this software
151541Srgrimes *    without specific prior written permission.
161541Srgrimes *
171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271541Srgrimes * SUCH DAMAGE.
281541Srgrimes *
2914477Shsu *	@(#)dirent.h	8.3 (Berkeley) 8/10/94
3050477Speter * $FreeBSD$
311541Srgrimes */
321541Srgrimes
3324778Sbde#ifndef	_SYS_DIRENT_H_
3424778Sbde#define	_SYS_DIRENT_H_
352165Spaul
36103192Smike#include <sys/cdefs.h>
37102227Smike#include <sys/_types.h>
3841929Sdt
391541Srgrimes/*
408876Srgrimes * The dirent structure defines the format of directory entries returned by
411541Srgrimes * the getdirentries(2) system call.
421541Srgrimes *
431541Srgrimes * A directory entry has a struct dirent at the front of it, containing its
441541Srgrimes * inode number, the length of the entry, and the length of the name
451541Srgrimes * contained in the entry.  These are followed by the name padded to a 4
461541Srgrimes * byte boundary with null bytes.  All names are guaranteed null terminated.
471541Srgrimes * The maximum length of a name in a directory is MAXNAMLEN.
481541Srgrimes */
491541Srgrimes
501541Srgrimesstruct dirent {
5141929Sdt	__uint32_t d_fileno;		/* file number of entry */
5241929Sdt	__uint16_t d_reclen;		/* length of this record */
5341929Sdt	__uint8_t  d_type; 		/* file type, see below */
5441929Sdt	__uint8_t  d_namlen;		/* length of string in d_name */
55103192Smike#if __BSD_VISIBLE
561541Srgrimes#define	MAXNAMLEN	255
571541Srgrimes	char	d_name[MAXNAMLEN + 1];	/* name must be no longer than this */
58103192Smike#else
59103192Smike	char	d_name[255 + 1];	/* name must be no longer than this */
601541Srgrimes#endif
611541Srgrimes};
621541Srgrimes
63103192Smike#if __BSD_VISIBLE
641541Srgrimes/*
651541Srgrimes * File types
661541Srgrimes */
671541Srgrimes#define	DT_UNKNOWN	 0
681541Srgrimes#define	DT_FIFO		 1
691541Srgrimes#define	DT_CHR		 2
701541Srgrimes#define	DT_DIR		 4
711541Srgrimes#define	DT_BLK		 6
721541Srgrimes#define	DT_REG		 8
731541Srgrimes#define	DT_LNK		10
741541Srgrimes#define	DT_SOCK		12
7514477Shsu#define	DT_WHT		14
761541Srgrimes
771541Srgrimes/*
781541Srgrimes * Convert between stat structure types and directory types.
791541Srgrimes */
801541Srgrimes#define	IFTODT(mode)	(((mode) & 0170000) >> 12)
811541Srgrimes#define	DTTOIF(dirtype)	((dirtype) << 12)
822165Spaul
8324778Sbde/*
8424778Sbde * The _GENERIC_DIRSIZ macro gives the minimum record length which will hold
85161347Smaxim * the directory entry.  This returns the amount of space in struct direct
8624778Sbde * without the d_name field, plus enough space for the name with a terminating
8724778Sbde * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
88103192Smike *
89103192Smike * XXX although this macro is in the implementation namespace, it requires
90103192Smike * a manifest constant that is not.
9124778Sbde */
9224778Sbde#define	_GENERIC_DIRSIZ(dp) \
9324778Sbde    ((sizeof (struct dirent) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
94103192Smike#endif /* __BSD_VISIBLE */
9524778Sbde
9655205Speter#ifdef _KERNEL
9724778Sbde#define	GENERIC_DIRSIZ(dp)	_GENERIC_DIRSIZ(dp)
982165Spaul#endif
9924778Sbde
10024778Sbde#endif /* !_SYS_DIRENT_H_ */
101