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 $
35 * $DragonFly: src/sys/sys/dirent.h,v 1.5 2005/08/27 20:23:05 joerg Exp $
38 #ifndef _SYS_DIRENT_H_
39 #define _SYS_DIRENT_H_
42 * The dirent structure defines the format of directory entries returned by
43 * the getdirentries(2) system call.
45 * A directory entry has a struct dirent at the front of it, containing its
46 * inode number, the length of the entry, and the length of the name
47 * contained in the entry. These are followed by the name padded to a 8
48 * byte boundary with null bytes. All names are guaranteed null terminated.
52 * XXX Temporary bandaids to keep changes small:
53 * XXX - for userland programs which don't specify any C or POSIX options,
54 * XXX keep the old d_fileno and map d_ino via macro. Everything else gets
55 * XXX the POSIX d_ino and only that.
56 * XXX - d_name is declared with the current maximum directory entry length,
57 * XXX instead of being incomplete. Code must allocate space for the
58 * XXX directory itself.
61 #include <sys/cdefs.h>
62 #include <sys/types.h>
65 #if defined(_KERNEL) || !defined(__BSD_VISIBLE)
66 ino_t d_ino
; /* file number of entry */
68 ino_t d_fileno
; /* file number of entry */
70 uint16_t d_namlen
; /* strlen(d_name) */
71 uint8_t d_type
; /* file type, see blow */
72 uint8_t d_unused1
; /* padding, reserved */
73 uint32_t d_unused2
; /* reserved */
75 /* name, NUL-terminated */
78 #if !defined(_KERNEL) && defined(__BSD_VISIBLE)
79 #define d_ino d_fileno
96 * The _DIRENT_DIRSIZ macro gives the minimum record length which will hold
97 * the directory entry. This requires the amount of space in struct direct
98 * without the d_name field, plus enough space for the name with a terminating
99 * null byte (dp->d_namlen+1), rounded up to an 8 byte boundary.
101 * The _DIRENT_MINSIZ macro gives space needed for the directory entry without
102 * the padding _DIRENT_DIRSIZ adds at the end.
104 #define _DIRENT_MINSIZ(dp) \
105 (__offsetof(struct dirent, d_name) + (dp)->d_namlen + 1)
106 #define _DIRENT_RECLEN(namelen) \
107 ((__offsetof(struct dirent, d_name) + (namelen) + 1 + 7) & ~7)
108 #define _DIRENT_DIRSIZ(dp) _DIRENT_RECLEN((dp)->d_namlen)
109 #define _DIRENT_NEXT(dp) \
110 ((struct dirent *)((uint8_t *)(dp) + _DIRENT_DIRSIZ(dp)))
112 #endif /* !_SYS_DIRENT_H_ */