In Unix-based operating systems, each file is identified by an Inode, which stands for Index Node. Inodes are special data structures created when the file system is initialized. The total number of inodes determines the maximum number of files and directories that the file system can hold.
An inode contains essential information about a file, such as its size, ownership, permissions, and pointers to the data blocks. When a file system is created, a fixed number of inodes is allocated, typically about 1% of the total disk space is reserved for the inode table. This allocation limits the number of files that can be stored, regardless of the available disk space.
Key Information Stored in an Inode
An inode contains important metadata about a file or directory. It contains the following information:
1. File Names of 14 Bytes and Corresponding Inodes of 2 Bytes. For example,
File name 1
i-node 1
File name 2
i-node 2
Directory name 1
i-node 3
Ownership Information
Numeric UID of the owner.
Numeric GUID of the owner.
File Size and Type
Size of the file in Bytes
File type: eg. regular, directory, device etc.
Timestamps
Date and Time of Last modification of the file data.
Date and Time of Last access of file data.
Date and Time of Last change of the I-node.
Administrative information like permissions, access control settings, and other metadata related to the file.
Data Block Pointers
A number of direct blocks (typically 12) that contains the first 12 blocks of the files.
A single indirect pointer that points to a disk block which in turn is used as an index block, if the file is too big to be indexed entirely by the direct blocks.
A double indirect pointer that points to a disk block which is a collection of pointers to disk blocks which are index blocks, used if the file is too big to beindexed by the direct and single indirect blocks.
A triple indirect pointer that points to an index block of index blocks of index blocks.
What is the Inode Total Size and Its Impact on File Storage
Number of disk block address possible to store in 1 disk block = (Disk Block Size / Disk Block Address).
Small files need only direct blocks, so there is little waste in space or extra disk reads in those cases. Medium-sized files may use indirect blocks. Only large files use double or triple indirect blocks, which is reasonable since those files are large anyway. The disk is now broken into two different types of blocks: Inode and Data Blocks.
There must be some way to determine where the Inodes are, and to keep track of free Inodes and disk blocks. This is done by a Superblock. Superblock is located at a fixed position in the file system. The Superblock is usually replicated on the disk to avoid catastrophic failure in case of corruption of the main Superblock.
Index allocation schemes suffer from some of the same performance problems. As does linked allocation. For example, the index blocks can be cached in memory, but the data blocks may be spread all over a partition.
The direct block refers to pointers stored directly in the inode, which point directly to the actual data blocks that hold the file's content. These are the first-level pointers that allow the file system to quickly access the data of small files.
For example, if a file is small enough, the inode might have a set of pointers (often 12) that directly address the first few data blocks of the file without needing any additional layers of indirection. This makes accessing small files efficient.
Single Indirect Block
If the file is larger than what the direct blocks can address, the single indirect block comes into play. Instead of directly pointing to data blocks, the inode stores a pointer to another block called the indirect block.
The indirect block, in turn, contains pointers to the actual data blocks of the file. This provides additional flexibility for the file system to handle files that are too large to fit within the capacity of the direct blocks.
Double Indirect Block
When a file becomes even larger, the double indirect block is used. This is a more advanced level of indirection where the inode points to a block that contains pointers to single indirect blocks.
Each of these single indirect blocks, as described above, will contain pointers to the data blocks of the file. The double indirection effectively extends the file system’s ability to handle even larger files by adding another layer of pointers.
Triple Indirect Block
For extremely large files, the triple indirect block is used. It points to a block that contains pointers to double indirect blocks. These, in turn, contain pointers to single indirect blocks, and the single indirect blocks finally point to the data blocks.
This multi-layered indirection system allows the file system to address massive files, even when the file size exceeds the typical limits of direct and indirect addressing.
Attribute Section
In addition to storing pointers to data blocks, an inode also stores important metadata or attributes about the file. These attributes may include:
File size: The size of the file in bytes.
Permissions: Information about who can read, write, or execute the file.
File type: Whether the file is a regular file, directory, symbolic link, etc.
Timestamps: When the file was last accessed, modified, or when the inode was last changed.
Owner and group: Information about the file's owner (user ID) and the associated group (group ID).