2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)dirent.h 8.3 (Berkeley) 8/10/94
34 * $FreeBSD: src/sys/sys/dirent.h,v 1.11 1999/12/29 04:24:39 peter Exp $
37 #ifndef _SYS_DIRENT_H_
38 #define _SYS_DIRENT_H_
41 * The dirent structure defines the format of directory entries returned by
42 * the getdirentries(2) system call.
44 * A directory entry has a struct dirent at the front of it, containing its
45 * inode number, the length of the entry, and the length of the name
46 * contained in the entry. These are followed by the name padded to a 8
47 * byte boundary with null bytes. All names are guaranteed null terminated.
51 * XXX Temporary bandaids to keep changes small:
52 * XXX - for userland programs which don't specify any C or POSIX options,
53 * XXX keep the old d_fileno and map d_ino via macro. Everything else gets
54 * XXX the POSIX d_ino and only that.
55 * XXX - d_name is declared with the current maximum directory entry length,
56 * XXX instead of being incomplete. Code must allocate space for the
57 * XXX directory itself.
60 #include <sys/cdefs.h>
61 #include <sys/types.h>
64 #if defined(_KERNEL) || !__BSD_VISIBLE
65 ino_t d_ino; /* file number of entry */
67 ino_t d_fileno; /* file number of entry */
69 uint16_t d_namlen; /* strlen(d_name) */
70 uint8_t d_type; /* file type, see blow */
71 uint8_t d_unused1; /* padding, reserved */
72 uint32_t d_unused2; /* reserved */
74 /* name, NUL-terminated */
78 * Linux compatibility, but its a good idea anyhow
80 #define _DIRENT_HAVE_D_NAMLEN
81 #define _DIRENT_HAVE_D_TYPE
83 #if !defined(_KERNEL) && __BSD_VISIBLE
84 #define d_ino d_fileno
99 #define DT_DBF 15 /* database record file */
102 * The _DIRENT_DIRSIZ macro gives the minimum record length which will hold
103 * the directory entry. This requires the amount of space in struct dirent
104 * without the d_name field, plus enough space for the name with a terminating
105 * null byte (dp->d_namlen+1), rounded up to an 8 byte boundary.
107 * The _DIRENT_MINSIZ macro gives space needed for the directory entry without
108 * the padding _DIRENT_DIRSIZ adds at the end.
110 #define _DIRENT_MINSIZ(dp) \
111 (__offsetof(struct dirent, d_name) + (dp)->d_namlen + 1)
112 #define _DIRENT_RECLEN(namelen) \
113 ((__offsetof(struct dirent, d_name) + (namelen) + 1 + 7) & ~7)
114 #define _DIRENT_DIRSIZ(dp) _DIRENT_RECLEN((dp)->d_namlen)
115 #define _DIRENT_NEXT(dp) \
116 ((struct dirent *)((uint8_t *)(dp) + _DIRENT_DIRSIZ(dp)))
118 #endif /* !_SYS_DIRENT_H_ */