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%

Superblocks

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

Introduction

The super block is the most important administrative data structure in a UNIX file system. It contains essential metadata that describes the entire file system. If the super block is corrupted, the file system becomes unusable.

What is a Super Block?

  • A data structure stored at a fixed location on disk (typically block 1 of the partition).
  • It is the master record of the file system.
  • The kernel reads the super block into memory when the file system is mounted and writes it back periodically.

Super Block Fields

FieldDescription
File System SizeTotal size of the file system in blocks
Number of InodesTotal number of inodes in the file system
Number of Data BlocksTotal number of data blocks
Free Block CountNumber of currently free data blocks
Free Inode CountNumber of currently free inodes
Free Block ListA partial list/cache of free data block numbers
Free Inode ListA partial list/cache of free inode numbers
Block SizeSize of each block (512 bytes, 1 KB, 4 KB, etc.)
Lock FieldsLocks for the free block and free inode lists
Modified FlagIndicates if the super block has been modified in memory
Read-Only FlagIndicates if the file system is mounted read-only
Last Update TimeTimestamp of last super block update

Free Block List Management

  • The super block maintains a linked list of free data blocks.
  • It caches a batch of free block numbers directly in the super block for fast access.
  • When the cached list is exhausted, the kernel follows a link to the next batch of free blocks.
  • This is more efficient than scanning the entire disk for free blocks.

How it works:

Super Block Free List:
[50, 48, 47, 46, 45, ...] → Next batch pointer → [120, 119, 118, ...]
  • When a block is needed, the kernel takes one from the cached list.
  • When the cache is empty, it loads the next batch using the pointer.
  • When a block is freed, it is added back to the cache.

Free Inode List Management

  • The super block also caches a list of free inode numbers.
  • When this cache is empty, the kernel scans the inode list on disk to refill it.
  • Unlike free blocks, the free inode list uses a linear search to refill because inodes are stored sequentially.

The remembered inode:

  • The super block remembers the highest inode number from which it last filled the free list.
  • On the next refill, it starts searching from this point to avoid rescanning already-allocated inodes.

In-Core Super Block

When a file system is mounted, the kernel:

  1. Reads the super block from disk into an in-core (in-memory) super block.
  2. All file system operations use this in-memory copy.
  3. The modified flag is set whenever changes are made.
  4. The super block is synced (written back to disk) periodically by:
  • The sync command.
  • The update daemon (runs every 30 seconds typically).
  • The umount command (when unmounting).

Why Super Block is Critical

  • If the super block is corrupted, the file system cannot be mounted.
  • UNIX (and Linux) maintain backup super blocks at regular intervals on the disk.
  • The fsck (file system check) utility can use a backup super block to repair the primary one.

Summary

  • The super block is the master control structure of the UNIX file system.
  • It tracks total and free inodes and data blocks.
  • It caches free block and inode lists for fast allocation.
  • It is loaded into memory at mount time and synced to disk periodically.
  • Corruption of the super block can make the entire file system inaccessible.