Problem Statement
What is an inode in Linux? Explain its structure and how it relates to files and hard links.
Explanation
An inode (index node) is a data structure that stores metadata about a file including permissions, ownership, timestamps, size, and pointers to data blocks containing the file's content. Every file has one inode, but directories map filenames to inode numbers. The filename isn't stored in the inode - it's stored in the directory entry.
Inodes contain file metadata but not the filename or data itself. They include file type, permissions (mode), owner UID, group GID, file size, timestamps (access, modification, change), link count, and pointers to data blocks. You can view inode numbers with ls -i and detailed inode information with stat command.
Hard links create multiple directory entries (filenames) pointing to the same inode. The link count in the inode tracks how many directory entries reference it. When you delete a file, you're removing a directory entry and decrementing the link count. The actual data is only deleted when link count reaches zero and no processes have the file open.
Understanding inodes explains why hard links can't cross filesystems (each filesystem has its own inode table), why directories can't be hard-linked (would create circular references), and how file deletion actually works. The number of available inodes limits how many files you can create regardless of disk space - important for systems with many small files.
