|
|
1.1 ! root 1: /* dir.h 4.4 82/07/25 */ ! 2: ! 3: /* ! 4: * A directory consists of some number of blocks of DIRBLKSIZ ! 5: * bytes, where DIRBLKSIZ is chosen such that it can be transferred ! 6: * to disk in a single atomic operation (e.g. 512 bytes on most machines). ! 7: * ! 8: * Each DIRBLKSIZ byte block contains some number of directory entry ! 9: * structures, which are of variable length. Each directory entry has ! 10: * a struct direct at the front of it, containing its inode number, ! 11: * the length of the entry, and the length of the name contained in ! 12: * the entry. These are followed by the name padded to a 4 byte boundary ! 13: * with null bytes. All names are guaranteed null terminated. ! 14: * The maximum length of a name in a directory is MAXNAMLEN. ! 15: * ! 16: * The macro DIRSIZ(dp) gives the amount of space required to represent ! 17: * a directory entry. Free space in a directory is represented by ! 18: * entries which have dp->d_reclen >= DIRSIZ(dp). All DIRBLKSIZ bytes ! 19: * in a directory block are claimed by the directory entries. This ! 20: * usually results in the last entry in a directory having a large ! 21: * dp->d_reclen. When entries are deleted from a directory, the ! 22: * space is returned to the previous entry in the same directory ! 23: * block by increasing its dp->d_reclen. If the first entry of ! 24: * a directory block is free, then its dp->d_ino is set to 0. ! 25: * Entries other than the first in a directory do not normally have ! 26: * dp->d_ino set to 0. ! 27: */ ! 28: #define DIRBLKSIZ 512 ! 29: #define MAXNAMLEN 255 ! 30: ! 31: struct direct { ! 32: u_long d_ino; /* inode number of entry */ ! 33: u_short d_reclen; /* length of this record */ ! 34: u_short d_namlen; /* length of string in d_name */ ! 35: char d_name[MAXNAMLEN + 1]; /* name must be no longer than this */ ! 36: }; ! 37: ! 38: /* ! 39: * The DIRSIZ macro gives the minimum record length which will hold ! 40: * the directory entry. This requires the amount of space in struct direct ! 41: * without the d_name field, plus enough space for the name with a terminating ! 42: * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary. ! 43: */ ! 44: #undef DIRSIZ ! 45: #define DIRSIZ(dp) \ ! 46: ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)) ! 47: ! 48: #ifndef KERNEL ! 49: /* ! 50: * Definitions for library routines operating on directories. ! 51: */ ! 52: typedef struct _dirdesc { ! 53: int dd_fd; ! 54: long dd_loc; ! 55: long dd_size; ! 56: char dd_buf[DIRBLKSIZ]; ! 57: } DIR; ! 58: #ifndef NULL ! 59: #define NULL 0 ! 60: #endif ! 61: extern DIR *opendir(); ! 62: extern struct direct *readdir(); ! 63: extern long telldir(); ! 64: extern void seekdir(); ! 65: #define rewinddir(dirp) seekdir((dirp), (long)0) ! 66: extern void closedir(); ! 67: #endif KERNEL
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.