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%

File System Layout

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

Introduction

The UNIX file system layout defines how data is physically organized on a disk (or disk partition). Understanding the layout is crucial for comprehending how the kernel stores and retrieves files.

A UNIX file system on disk is divided into distinct sections, each with a specific purpose.

Disk Partitioning

  • A physical disk can be divided into multiple partitions.
  • Each partition can contain an independent file system.
  • The kernel treats each partition as a logical device.

File System Layout on Disk

A typical UNIX file system partition has the following structure:

┌────────────┬─────────────┬────────────┬──────────────────────┐
│ Boot Block │ Super Block │ Inode List │     Data Blocks      │
└────────────┴─────────────┴────────────┴──────────────────────┘
  Block 0       Block 1      Blocks 2-N    Remaining Blocks

Detailed Description of Each Section

1. Boot Block (Block 0):

  • The first block of every file system.
  • Contains the bootstrap code — a small program that loads the operating system kernel into memory during system startup.
  • Only the boot block of the root file system is actually used for booting. Boot blocks of other partitions are typically empty but still reserved.
  • Size: Usually 1 block (512 bytes to 1 KB).

2. Super Block (Block 1):

  • Contains critical metadata about the entire file system:
  • Total size of the file system
  • Number of inodes
  • Number of data blocks
  • Size of each block
  • Number of free inodes and free data blocks
  • Pointers to the free inode list and free block list
  • Flags indicating if the file system has been modified
  • The super block is loaded into memory when the file system is mounted.
  • If the super block is corrupted, the entire file system becomes inaccessible.

3. Inode List (Inode Table):

  • A linear array of inodes (index nodes).
  • Each inode has a unique inode number within the file system.
  • The inode list starts right after the super block.
  • The number of inodes is determined when the file system is created (mkfs command) and cannot be changed later.
  • Inode 0 is reserved (unused).
  • Inode 1 is reserved for bad blocks.
  • Inode 2 is always the root directory (/) of the file system.

4. Data Blocks:

  • The remaining blocks on the disk, used to store:
  • File contents (actual data).
  • Directory entries (filename-to-inode mappings).
  • Indirect blocks (pointers to more data blocks for large files).
  • Data blocks occupy the majority of the disk space.

How File Access Works (Simplified)

  1. User requests a file by path (e.g., /home/user1/file.txt).
  2. Kernel starts at the root inode (inode 2).
  3. Reads the root directory data blocks to find the entry for home → gets its inode number.
  4. Reads home inode → finds data blocks → looks for user1 → gets its inode.
  5. Reads user1 inode → finds file.txt → gets its inode number.
  6. Reads file.txt inode → gets pointers to data blocks → reads the actual data.

Summary

  • A UNIX file system is divided into: Boot Block, Super Block, Inode List, and Data Blocks.
  • The Boot Block contains bootstrap code for OS loading.
  • The Super Block stores metadata about the entire file system.
  • The Inode List holds all file metadata (one inode per file).
  • Data Blocks store the actual file contents and directory entries.