Annotation of cci/usr/src/man/man5/dir.5, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.