Inodes are not necessarily a feature particular to unix-like operating systems. They are a distinctive feature of a particular family of file systems that is most often used under Unix.

An inode contains basically all the information about file, with one surprising exception: its name. Filenames are defined through directory entries, so the same file can appear in different places in the directory hiearchy, with different names (see hardlink).

Apart from meta information such as access times, the inode in modern filesystems (after the Berkeley FFS) also contains the numbers of the disk blocks that contain the actual file data - or the numbers of disk blocks that contain the numbers of disk blocks where the actual file data is, for larger files (there are also second and third levels of indirection, for really large files). This is important because it means you can access any position within a file with relatively little overhead - something that made the Berkeley FFS much faster than previous file systems.

In unix, the inode is the central concept of the filesystem, and contains all the interesting file attributes, all of which can be read by the user using the stat or fstat system calls.

The inode also lists other data less interesting to the user that can't be read with stat, including the location of the first 12 data blocks of the file, and the first indirect, double indirect, and tripple indirect blocks. (The first indirect block is a list of the next BLOCKSIZE/4 blocks, and the first double indirect block is the list of the next BLOCKSIZE/4 indirect blocks, etc..., assuming 32 bit block numbers.) This pattern of direct and indirect blocks has not really changed since the first unix file system, and limits the maximum file size to (12+BLOCKSIZE/4 + (BLOCKSIZE/4)**2 + (BLOCKSIZE/4)**3) blocks, which is usually much larger than st_size anyway, so st_size limits the real maximum file size (if the size of your disk doesn't first).

The inode and indirect blocks contain all the metadata and attributes for the file. (The filename is not part of the file nor an attribute of the file in unix. Some files don't have names at all.) All files in unix have inodes; if the underlying filesystem does not have inodes, the file will still have one in memory. (Some unixes call an inode cached in memory a vnode.)

The inode may also contain other unix flavor specific information, such as fragmentation maps, extended attributes, or pointers to extended attributes.

Log in or register to write something here or to contact authors.