Allegedly stands for “index node.”
We usually don’t care about all blocks in the File system, just the blocks for the currently opened files. Instead of spreading out the block numbers in a table (like FAT), can we group the block numbers of a single file together?
Inodes are data structures that contain file metadata and an array of 121 physical block numbers corresponding to the first 12 logical blocks in a file, plus some indirect pointers to other blocks for larger files. Inodes are only created for actual files. Each file has a unique inode number.
struct inode_st {
attributes_t metadata;
block_no_t blocks[12];
block_no_t* single_ind;
block_no_t** double_ind;
block_no_t*** triple_ind;
}
The inode data structure contains:
- Owner of the file
- Access permissions
- File size
- Time of last change to file, last access to file, and last change to inode of the file.
- An array containing the first 12 logical blocks
- Singly, doubly, triply indirect pointers to more blocks. These are not C address pointers, but refer to literal block numbers.
When we’re using inodes, Directory entries store the inode number for the file (instead of the file’s initial block like in FAT).
Disk layout
In the absence of FAT’s built-in way of knowing whether blocks are free or not, inodes require us to maintain a bitmap block.
Inodes are smaller than a block (literally just a C struct), so we can fit multiple inodes into a single block. We designate a certain block on the disk as a “inode block” that we always check. A file’s inode number would correspond to one of the inodes in this block.
On the physical disk, a certain number of contiguous physical blocks are reserved purely for inode purposes. This is usually at the beginning of the disk.
- Since every active inode has to refer to an existing file, many spaces in the inode blocks are not allocated
- We can think of this space as something like
inode_array[]
Reserved inodes
Linux reserves inode numbers 1-10 for special purposes. Interestingly, not all of them are actually used or implemented.
- Inode 2: corresponds to the root directory inode
Footnotes
-
Why 12? Great question. I dunno. That’s just what they decided on. Fuck 12 ↩