100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

What is an Inode and What Does It Store?

Learn what an inode is — metadata, data block pointers, hard links — with examples and operating systems interview questions answered.

mediumQ105 of 224 in Operating Systems Est. time: 6 minsLast updated:
Open Code Lab
105 / 224

Expected Interview Answer

An inode is a fixed-size metadata record that a Unix-style file system keeps for every file, storing ownership, permissions, timestamps, size, and pointers to the data blocks on disk, while the file’s name lives separately in a directory entry that simply maps a name to an inode number.

Every file on an ext-family or similar file system is represented internally by an inode, identified by a unique inode number within that file system. The inode holds owner UID and GID, permission bits, file type, size, timestamps (access, modify, change), a link count, and either direct/indirect block pointers or extent maps describing where the file’s data physically lives — but critically, it does not store the file name. Directory entries are just tuples mapping a human-readable name to an inode number, which is why multiple hard links can point to the same inode (sharing one set of data blocks) and why renaming a file is a cheap directory-entry update rather than a data copy. A file is only truly deleted once its link count drops to zero and no process still holds it open; until then the inode and its blocks remain allocated.

  • Explains why hard links share data but symlinks do not
  • Explains why renaming a file within a file system is instant
  • Clarifies why deleting a file with open handles frees space only on close
  • Foundation for understanding df vs du discrepancies and inode exhaustion

AI Mentor Explanation

An inode is like a player's official registration record held by the cricket board: it lists date of birth, batting average, playing role, and a locker number pointing to where their kit is actually stored, but it never stores the nickname fans call them. Different scorecards or team sheets (directory entries) can refer to the same registration record by different nicknames, and changing a nickname on a scorecard does not touch the underlying record. Only when every scorecard reference to that player is removed and the board formally retires the registration does the locker get cleared for someone else.

Step-by-Step Explanation

  1. Step 1

    File creation

    The file system allocates a free inode and fills it with metadata: owner, permissions, timestamps, and type.

  2. Step 2

    Directory entry linked

    A name-to-inode-number pair is added to the containing directory's own data.

  3. Step 3

    Data block mapping

    The inode records direct/indirect pointers or extents describing where the file's actual bytes live on disk.

  4. Step 4

    Link count tracking

    Each additional hard link increments the inode's link count; the inode and its data persist until the count reaches zero and no process holds it open.

What Interviewer Expects

  • A clear statement that the inode holds metadata, not the file name
  • Understanding that directory entries map names to inode numbers
  • Why hard links share an inode and symlinks do not
  • Awareness that deletion only reclaims space when link count hits zero and the file is closed

Common Mistakes

  • Claiming the file name is stored inside the inode
  • Confusing hard links (shared inode) with symbolic links (separate inode pointing to a path)
  • Not knowing that inode counts are finite and can be exhausted independently of disk space
  • Assuming rm always frees space immediately, even with open file handles

Best Answer (HR Friendly)

An inode is basically the file system's internal record card for a file — it tracks who owns it, its permissions, timestamps, and where its actual data lives on disk, but not the file's name. The name is kept in the folder listing instead, which is why you can rename a file instantly or have two names pointing to the exact same data.

Code Example

Simplified inode structure and directory entry mapping
struct inode {
    unsigned long ino;         /* inode number, unique per filesystem */
    unsigned short mode;       /* file type + permission bits          */
    unsigned int   uid, gid;   /* owner and group                      */
    unsigned long  size;       /* file size in bytes                   */
    long           atime, mtime, ctime;
    unsigned short link_count; /* number of directory entries pointing here */
    unsigned long  blocks[12]; /* direct data block pointers (simplified)   */
};

/* A directory is just a list of (name -> inode number) pairs */
struct dirent {
    char          name[255];
    unsigned long ino;
};

/* Hard link: add a new dirent pointing at the SAME inode number */
void create_hard_link(struct dirent *dir, const char *name, unsigned long ino) {
    add_dirent(dir, name, ino);
    increment_link_count(ino);   /* no new inode, no new data blocks */
}

Follow-up Questions

  • What is the difference between a hard link and a symbolic link at the inode level?
  • Why can df and du report different free-space numbers?
  • What happens to open file descriptors when an inode's link count reaches zero?
  • How does inode exhaustion differ from disk-space exhaustion?

MCQ Practice

1. Which of the following is stored in an inode?

Inodes store file metadata and data-block locations; the human-readable name lives in a separate directory entry.

2. What happens to a file's data when its last hard link is removed and no process has it open?

Once link count reaches zero and no open file descriptors reference the inode, the file system reclaims the inode and its blocks.

3. A hard link to a file means two directory entries?

Hard links are multiple directory entries that reference the identical inode number, so they share the same underlying data.

Flash Cards

What does an inode store?Metadata — owner, permissions, timestamps, size, and data block pointers — but not the file name.

Where is a file's name kept?In a directory entry, which maps the name to an inode number.

What makes a hard link special?It is another directory entry pointing at the same inode number, sharing data blocks.

When is an inode's data actually freed?When its link count reaches zero and no process still has it open.

1 / 4

Continue Learning