Inode Structure

Inode Structure


Another popular system file format is the extended format, commonly used in Linux. Each file on the disk has a data structure called an Inode associated with it. The Inode is fixed length. It contains the metadata for the file, and it serves as the glue linking the data blocks together in the right order. It is this gluing function that is the most interesting. The inode stores 15 data block addresses or pointers. The first 12 of these point directly to the first 12 data blocks of the file. This makes the strategy efficient for small files. The thirteenth of these addresses points to a block that consists of a table of addresses for the next blocks in the file. This vastly increases the number of blocks that we can use in a file. The downside is that we’ve introduced a layer of indirection. If this doesn’t give the file enough space, then we use this fourteenth pointer and not one but two layers of indirection, giving us even more space. And if this isn’t enough, we have a fifteenth pointer, which uses triple indirection for more space still. Juts like in FAT, directories are treated as files. Only instead of mapping a file name to the first file block, they map a file name to its inode. That path for accessing slash foo, slash file.txt, would look something like this. We’d start at the inode for the root directory and then following its data pointers we find the data for the root directory. There we find that foo maps to another inode, following that address we consult that inode and find that address for its data block. Looking in there, we find the contents of slash foo. That’s a directory. So it’s going to map the file name file.txt to the appropriate inode. And then using that inode structure, we’re able to peace together the data that we need.