Basic stuff here that most folks already know, but it might help some newbies understand what's going on.
Files and directories are stored in a volume (filesystem) using a table of inodes and a pool of data blocks. Each file and directory is represented by an inode, a 128 byte data structure. A data block is 4k and is used for storing file data. A data block is either unused (free) or is assigned to a file.
The number of inodes determines how many files and directories the volume can hold. The number of data blocks determines how much file data the volume can hold. You can increase the number of inodes in a volume with the maxfiles command, but that decreases the number of data blocks, since some data blocks must be reassigned to the inode table to enlarge it. You cannot decrease the size of the inode table except by destroying the volume and rebuilding it. Whenever you add a new disk to a volume, both the data block pool and the inode table are enlarged.
Each inode contains information about a file or directory, including:
owner (UID number) group (GID number) permission bits (read/write/execute for user/group/other) file type bits (regular file, directory, device, symlink, etc.) device id (identifies volume containing the file) quota tree id (identifies quota tree containing the file) file size (length of file in bytes) link count (number of hard links to the file) timestamps (data access time, data mod time, inode mod time) data block list (specifies which data blocks hold file contents)
For files up to 64 bytes long, the file data is stored in the inode in the space used for the data block list. This avoids consuming an entire 4k data block to hold just a few bytes.
Each inode is identified by an inode number, which can be thought of as an index into the inode table. An inode is accessed by calculating its offset in the table using its inode number.
In particular, an inode does NOT store the file name. The file name is stored in the parent directory.
A directory is just a file that contains of a list of directory entries called "dirents". A dirent consists of a file name and an inode number. Dirents are variable length depending on the length of the file name. To see a sorted list of the dirents in a directory, run "ls -ai"
When you access a file (or directory) the parent directory is read to find the dirent with the file name. Using the corresponding inode number, the inode for the file is located in the inode table.
A newly created directory contains two dirents for the file names "." and "..". The "." dirent has the directory's own inode number while ".." has the parent directory's inode number. So these are not just a notational convention; they actually exist. A data block is assigned to the directory to store these two dirents. So the new directory consumes 1 inode, 1 data block, and a dirent in the parent directory.
Steve Losen scl@virginia.edu phone: 804-924-0640
University of Virginia ITC Unix Support