Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Internal Representation: Inodes

Lesson 13 of 32 in the free Design of Unix Operating System notes on Siksha Sarovar, written by Rohit Jangra.

Introduction

The inode (index node) is the most critical data structure in the UNIX file system. Every file in UNIX is internally represented by an inode. The inode contains all the information the kernel needs to manage a file — except the file's name.

What is an Inode?

  • An inode is a fixed-size data structure stored on disk in the inode list.
  • Each file has exactly one inode.
  • Each inode has a unique inode number within its file system.
  • The inode number serves as the file's internal identity.

Inode Contents (Fields)

FieldDescription
File TypeRegular, directory, character/block device, pipe, socket, symlink
PermissionsRead, write, execute for owner, group, others (9 bits + setuid, setgid, sticky)
Link CountNumber of hard links (directory entries) pointing to this inode
Owner UIDUser ID of the file owner
Group GIDGroup ID associated with the file
File SizeSize of the file in bytes
Access TimeLast time the file was read (atime)
Modification TimeLast time the file data was modified (mtime)
Change TimeLast time the inode was modified (ctime)
Block AddressesPointers to the disk blocks that store the file's data
Block CountNumber of disk blocks allocated to the file

Block Addressing in Inodes

A key challenge is: how does an inode locate the data blocks of a file, especially for large files?

UNIX uses a combination of direct and indirect pointers:

1. Direct Blocks (10 pointers):

  • The first 10 entries in the block address array point directly to data blocks.
  • For a block size of 1 KB, direct blocks can address up to 10 KB of data.

2. Single Indirect Block (1 pointer):

  • Points to a block that contains pointers to data blocks.
  • If a block can hold 256 pointers (1 KB block / 4-byte pointer), this adds 256 KB.

3. Double Indirect Block (1 pointer):

  • Points to a block of pointers, each pointing to another block of pointers to data blocks.
  • Adds 256 × 256 = 65,536 blocks = 64 MB.

4. Triple Indirect Block (1 pointer):

  • Three levels of indirection.
  • Adds 256 × 256 × 256 = 16,777,216 blocks = 16 GB.

Block Addressing Diagram

Inode Block Address Array:
┌────────────┐
│ Direct 0   │──→ Data Block
│ Direct 1   │──→ Data Block
│ ...        │
│ Direct 9   │──→ Data Block
│ Single Ind │──→ [Ptr Block] ──→ Data Blocks
│ Double Ind │──→ [Ptr Block] ──→ [Ptr Block] ──→ Data Blocks
│ Triple Ind │──→ [Ptr Block] ──→ [Ptr Block] ──→ [Ptr Block] ──→ Data Blocks
└────────────┘

Maximum File Size Calculation (Example: 1 KB block, 4-byte pointer)

LevelPointersBlocksSize
Direct101010 KB
Single Indirect256256256 KB
Double Indirect256 × 25665,53664 MB
Triple Indirect256³16,777,21616 GB
Total~16 GB

What an Inode Does NOT Contain

  • File name — stored in the directory (as filename-to-inode mapping).
  • File data — stored in data blocks (inode only contains pointers to them).

Summary

  • An inode stores all file metadata except the filename.
  • Block addressing uses 10 direct, 1 single indirect, 1 double indirect, and 1 triple indirect pointer.
  • This scheme allows UNIX to support very large files efficiently.
  • Understanding inodes is essential for understanding how UNIX manages files internally.