xref: /original-bsd/sys/sys/dirent.h (revision 27393bdf)
1 /*-
2  * Copyright (c) 1989, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)dirent.h	8.3 (Berkeley) 08/10/94
8  */
9 
10 /*
11  * The dirent structure defines the format of directory entries returned by
12  * the getdirentries(2) system call.
13  *
14  * A directory entry has a struct dirent at the front of it, containing its
15  * inode number, the length of the entry, and the length of the name
16  * contained in the entry.  These are followed by the name padded to a 4
17  * byte boundary with null bytes.  All names are guaranteed null terminated.
18  * The maximum length of a name in a directory is MAXNAMLEN.
19  */
20 
21 struct dirent {
22 	u_int32_t d_fileno;		/* file number of entry */
23 	u_int16_t d_reclen;		/* length of this record */
24 	u_int8_t  d_type; 		/* file type, see below */
25 	u_int8_t  d_namlen;		/* length of string in d_name */
26 #ifdef _POSIX_SOURCE
27 	char	d_name[255 + 1];	/* name must be no longer than this */
28 #else
29 #define	MAXNAMLEN	255
30 	char	d_name[MAXNAMLEN + 1];	/* name must be no longer than this */
31 #endif
32 };
33 
34 /*
35  * File types
36  */
37 #define	DT_UNKNOWN	 0
38 #define	DT_FIFO		 1
39 #define	DT_CHR		 2
40 #define	DT_DIR		 4
41 #define	DT_BLK		 6
42 #define	DT_REG		 8
43 #define	DT_LNK		10
44 #define	DT_SOCK		12
45 #define	DT_WHT		14
46 
47 /*
48  * Convert between stat structure types and directory types.
49  */
50 #define	IFTODT(mode)	(((mode) & 0170000) >> 12)
51 #define	DTTOIF(dirtype)	((dirtype) << 12)
52