|
|
1.1 ! root 1: .\" Copyright (c) 1983 Regents of the University of California. ! 2: .\" All rights reserved. The Berkeley software License Agreement ! 3: .\" specifies the terms and conditions for redistribution. ! 4: .\" ! 5: .\" @(#)dir.5 6.1 (Berkeley) 5/15/85 ! 6: .\" ! 7: .TH DIR 5 "May 15, 1985" ! 8: .UC 5 ! 9: .SH NAME ! 10: dir \- format of directories ! 11: .SH SYNOPSIS ! 12: .B #include <sys/types.h> ! 13: .br ! 14: .B #include <sys/dir.h> ! 15: .SH DESCRIPTION ! 16: A directory behaves exactly like an ordinary file, save that no ! 17: user may write into a directory. ! 18: The fact that a file is a directory is indicated by ! 19: a bit in the flag word of its i-node entry; see ! 20: .IR fs (5). ! 21: The structure of a directory entry as given in the include file is: ! 22: .RS ! 23: .ta 8n +10n +10n ! 24: .PP ! 25: .nf ! 26: /* ! 27: * A directory consists of some number of blocks of DIRBLKSIZ ! 28: * bytes, where DIRBLKSIZ is chosen such that it can be transferred ! 29: * to disk in a single atomic operation (e.g. 512 bytes on most machines). ! 30: * ! 31: * Each DIRBLKSIZ byte block contains some number of directory entry ! 32: * structures, which are of variable length. Each directory entry has ! 33: * a struct direct at the front of it, containing its inode number, ! 34: * the length of the entry, and the length of the name contained in ! 35: * the entry. These are followed by the name padded to a 4 byte boundary ! 36: * with null bytes. All names are guaranteed null terminated. ! 37: * The maximum length of a name in a directory is MAXNAMLEN. ! 38: * ! 39: * The macro DIRSIZ(dp) gives the amount of space required to represent ! 40: * a directory entry. Free space in a directory is represented by ! 41: * entries which have dp->d_reclen > DIRSIZ(dp). All DIRBLKSIZ bytes ! 42: * in a directory block are claimed by the directory entries. This ! 43: * usually results in the last entry in a directory having a large ! 44: * dp->d_reclen. When entries are deleted from a directory, the ! 45: * space is returned to the previous entry in the same directory ! 46: * block by increasing its dp->d_reclen. If the first entry of ! 47: * a directory block is free, then its dp->d_ino is set to 0. ! 48: * Entries other than the first in a directory do not normally have ! 49: * dp->d_ino set to 0. ! 50: */ ! 51: #ifdef KERNEL ! 52: #define DIRBLKSIZ DEV_BSIZE ! 53: #else ! 54: #define DIRBLKSIZ 512 ! 55: #endif ! 56: ! 57: #define MAXNAMLEN 255 ! 58: ! 59: /* ! 60: * The DIRSIZ macro gives the minimum record length which will hold ! 61: * the directory entry. This requires the amount of space in struct direct ! 62: * without the d_name field, plus enough space for the name with a terminating ! 63: * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary. ! 64: */ ! 65: #undef DIRSIZ ! 66: #define DIRSIZ(dp) \e ! 67: ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)) ! 68: ! 69: struct direct { ! 70: u_long d_ino; ! 71: short d_reclen; ! 72: short d_namlen; ! 73: char d_name[MAXNAMLEN + 1]; ! 74: /* typically shorter */ ! 75: }; ! 76: ! 77: struct _dirdesc { ! 78: int dd_fd; ! 79: long dd_loc; ! 80: long dd_size; ! 81: char dd_buf[DIRBLKSIZ]; ! 82: }; ! 83: .fi ! 84: .RE ! 85: .PP ! 86: By convention, the first two entries in each directory ! 87: are for `.' and `..'. The first is an entry for the ! 88: directory itself. The second is for the parent directory. ! 89: The meaning of `..' is modified for the root directory ! 90: of the master file system (\*(lq/\*(rq), ! 91: where `..' has the same meaning as `.'. ! 92: .SH "SEE ALSO" ! 93: fs(5)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.