FreeBSD/Linux Kernel Cross Reference
sys/include/dirent.h
1 /* dirent.h - Declarations for directory reading routines.
2 * Author: Kees J. Bot
3 * 24 Apr 1989
4 *
5 * Note: The V7 format directory entries used under Minix must be transformed
6 * into a struct dirent with a d_name of at least 15 characters. Given that
7 * we have to transform V7 entries anyhow it is little trouble to let the
8 * routines understand the so-called "flex" directory format too.
9 */
10
11 #ifndef _DIRENT_H
12 #define _DIRENT_H
13
14 #ifndef _TYPES_H
15 #include <sys/types.h>
16 #endif
17
18 #include <sys/dir.h>
19
20 /* _fl_direct is a flexible directory entry. Actually it's a union of 8
21 * characters and the 3 fields defined below.
22 */
23
24 /* Flexible directory entry: */
25 struct _fl_direct { /* First slot in an entry */
26 ino_t d_ino;
27 unsigned char d_extent;
28 char d_name[3]; /* two characters for the shortest name */
29 };
30
31 /* Name of length len needs _EXTENT(len) extra slots. */
32 #define _EXTENT(len) (((len) + 5) >> 3)
33
34 /* Version 7 directory entry: */
35 struct _v7_direct {
36 ino_t d_ino;
37 char d_name[DIRSIZ];
38 };
39
40 /* The block size must be at least 1024 bytes, because otherwise
41 * the superblock (at 1024 bytes) overlaps with other filesystem data.
42 */
43 #define MIN_BLOCK_SIZE 1024
44
45 /* The below is allocated in some parts of the system as the largest
46 * a filesystem block can be. For instance, the boot monitor allocates
47 * 3 of these blocks and has to fit within 64kB, so this can't be
48 * increased without taking that into account.
49 */
50 #define MAX_BLOCK_SIZE 4096
51
52 /* This is the block size for the fixed versions of the filesystem (V1/V2) */
53 #define STATIC_BLOCK_SIZE 1024
54
55 #define STATIC_FLEX_PER_BLOCK (STATIC_BLOCK_SIZE/sizeof(struct _fl_direct))
56 #define FLEX_PER_V7 (_EXTENT(DIRSIZ) + 1)
57 #define FLEX_PER_BLOCK (STATIC_BLOCK_SIZE/sizeof(struct _fl_direct))
58
59 /* Definitions for the directory(3) routines: */
60 typedef struct {
61 char _fd; /* Filedescriptor of open directory */
62 char _v7; /* Directory is Version 7 */
63 short _count; /* This many objects in buf */
64 off_t _pos; /* Position in directory file */
65 struct _fl_direct *_ptr; /* Next slot in buf */
66 struct _fl_direct _buf[FLEX_PER_BLOCK]; /* One block of a directory file */
67 struct _fl_direct _v7f[FLEX_PER_V7]; /* V7 entry transformed to flex */
68 } DIR;
69
70 #define _DIRENT_NAME_LEN 61
71
72 struct dirent { /* Largest entry (8 slots) */
73 ino_t d_ino; /* I-node number */
74 unsigned char d_extent; /* Extended with this many slots */
75 char d_name[_DIRENT_NAME_LEN]; /* Null terminated name */
76 };
77
78 /* Function Prototypes. */
79 _PROTOTYPE( int closedir, (DIR *_dirp) );
80 _PROTOTYPE( DIR *opendir, (const char *_dirname) );
81 _PROTOTYPE( struct dirent *readdir, (DIR *_dirp) );
82 _PROTOTYPE( void rewinddir, (DIR *_dirp) );
83
84 #ifdef _MINIX
85 _PROTOTYPE( int seekdir, (DIR *_dirp, off_t _loc) );
86 _PROTOTYPE( off_t telldir, (DIR *_dirp) );
87 #endif
88
89 #endif /* _DIRENT_H */
Cache object: 7fe10a26cc00e1b7015b2e2feb752254
|