Monday, November 24, 2008

A basic look on Inodes

Inode stores basic information about a regular file, directory, or other file system object. The inode number is a unique integer assigned to the device upon which it is stored. All files are hard links to inodes.
n the Linux kernel, there are three storage areas where inodes are saved. First, there are two lists (both maintained as doubly linked lists). One of these lists saves used inodes, while another stores unused inodes. There is a hash table that stores all used inodes as well, since hash tables makes searching for inodes faster. The hash value is based on super block address and inode number of the index. And then, finally, there is a structure that stores the number of used and unused inodes. This structure resembles the following:

struct{
int nr_inodes;
int nr_free-inodes;
}inodes_stat;


nr_inodes variable stores the number of inodes, while nr_free_inodes stores the number of unused inodes.

The inodes structure is widely used in file system implementation. This structure is defined in /include/linux/fs.h

Now that we have looked into the inode structure, how should we create and destroy inodes? Linux kernel implementers provide two functions for this:
Iget() and iput()

A file's inode number can be found using the ls -i command, while the ls -l command will retrieve inode information.