Directory Structures
All the information about a file, apart from its name, is stored in the i-node. The file name and the i-number which identifies the i-node is stored in a directory entry. A directory is a regular file, however, in order to avoid file system integrity problems, the kernel will not allow a directory to be opened for writing using normal file system calls.
Older versions of Unix (System 5 and earlier) used a directory format consisting of a sequence of 16 byte records, the first 2 bytes held the i-number and the remaining 14 bytes held the file name. There was, thus, a limit of 14 characters on the maximum size of a file name. When a file was deleted the i-number of the associated directory record was set to zero to mark the record as free, however the name was not set to null.
More recent versions of Unix have adopted the more flexible structure for directory entries shown in the diagram.
When a file is deleted the space occupied by the directory entry is amalgamated with the free space at the end of the previous entry and the information block size field is incremented. This technique has the advantage of allowing usefully long file names without requiring large directory records. The disadvantage is that the manipulation of directories is more complex, directories can only be read via a special system call (getdent()). Normal manipulation of directories from within programs is handled via library routines.