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 a 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.

*nix filesystem concept

To add jus a little to this an inode (Index Node) is a data structure used in Unix-like file systems (such as ext4, XFS, etc.) to store metadata about a file or directory. It contains information about the file’s attributes, such as its size, ownership, permissions, timestamps (creation, modification, access), and pointers to the data blocks on the disk where the actual content is stored. However, an inode does not contain the file's name or its data itself.

When a file is created, an inode is allocated to it, and the file name is stored separately in a directory entry that maps to that inode. Each file has a unique inode, and the file system uses the inode to retrieve the file's metadata and data blocks.

Key points:

  • Inodes store metadata, not the actual data or file name.
  • Inode number: A unique identifier for each inode in the file system.
  • Inodes play a crucial role in **file management** and access, helping the system locate files and manage their properties.

Why do I need to know about this? Because When you create a hard link to a file using ln, a new directory entry is created, but the inode number remains the same. Both filenames now refer to the same inode, and when either of the links is deleted, the inode is not removed until the last link to it is deleted. This feature allows files to be referenced by multiple names in different directories without duplicating the file's content on disk. ¹

In summary, inodes are essential for managing files in a file system, storing all crucial details about the file except its name and content. The stat command can be used to identify the inode number of a file, if needed.

¹This w-u is a little more complete than I'd originally left it thanks to remarks from C-Dawg, to whom gratitude.


$ xclip -o | wc -w
205

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