Linux — What is an inode?

Shlomi Boutnaru, Ph.D.
2 min readJul 8, 2023

--

An inode (aka index node) is a data structure used by Unix/Linux like filesystems in order to describe a filesystem object. Such an object could be a file or a directory. Every inode stores pointers to the disk block’s locations of the object’s data and metadata (https://www.bluematador.com/blog/what-is-an-inode-and-what-are-they-used-for). An illustration of that is shown below.

Overall, the metadata contained in an inode is: file type (regular file/directory/symbolic link/block special file/character special file/etc), permissions, owner id, group id, size, last accessed time, last modified time, change time and number of hard links (https://www.stackscale.com/blog/inodes-linux/).

By using inodes the filesystem tracks all files/directories saved on disk. Also, by using inodes we can read any specific byte in the data of a file very effectively. We can see the number of total inodes per mounted filesystem using the command “df -i” (https://linux.die.net/man/1/df). Also, we can see the inode of a file/directory and other metadata of the file using the command “ls -i” (https://man7.org/linux/man-pages/man1/ls.1.html) or “stat” (https://linux.die.net/man/1/stat). By the way, the “stat” command uses the “stat”/”lstat” syscall (https://linux.die.net/man/2/stat) or even “statx” depending on the fileystem and its version.

Lastly, you can check out “struct inode” in the source code of the Linux kernel (https://elixir.bootlin.com/linux/v6.4.2/source/include/linux/fs.h#L612). Not all the points/links are directly connected to the data blocks, however I will elaborate on that in a future writeup.

See you next time ;-) You can also follow me on twitter — @boutnaru (https://twitter.com/boutnaru).

https://www.sobyte.net/post/2022-05/linux-inode/

--

--