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%

Data Structures of the File System

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

Introduction

The UNIX kernel uses several important data structures to manage the file system efficiently. These data structures exist both on disk (persistent) and in memory (for performance). Understanding them is key to understanding how UNIX handles file operations internally.

On-Disk Data Structures

These are permanently stored on the disk and define the file system structure.

1. Inode (On-Disk):

  • Stores all metadata about a file except its name.
  • Fields include:
  • File type (regular, directory, device, etc.)
  • File permissions (rwx for owner, group, others)
  • Number of hard links (link count)
  • Owner UID and Group GID
  • File size in bytes
  • Timestamps: Access time, Modification time, Inode change time
  • Disk block addresses (pointers to data blocks)

2. Super Block (On-Disk):

  • Master record of the file system (detailed in the File System Layout lesson).
  • Contains free block list, free inode list, and file system metadata.

3. Directory Entries:

  • Each directory contains entries of the form: (inode number, filename).
  • This is how filenames are mapped to their inodes.

---

In-Memory Data Structures

When the system is running, the kernel maintains in-memory copies and additional structures for efficiency.

1. In-Core Inode (In-Memory Inode):

  • A copy of the on-disk inode, plus additional kernel-specific information:
  • Reference count — number of processes currently using this inode.
  • Lock status — whether the inode is locked by a process.
  • Modified flag — indicates if the inode has been changed and needs to be written back to disk.
  • Device number — identifies which file system the inode belongs to.
  • Inode number — the actual inode number on disk.

2. In-Core Super Block:

  • A copy of the on-disk super block kept in memory for faster access.
  • Modified super block is written back to disk periodically (by the sync command or the update daemon).

3. File Table (System-Wide Open File Table):

  • A global kernel table with one entry for each open file instance.
  • Each entry contains:
  • File offset — current read/write position in the file.
  • Access mode — read, write, or read-write.
  • Reference count — number of file descriptors pointing to this entry.
  • Pointer to the in-core inode.

4. User File Descriptor Table (Per-Process):

  • Each process has its own file descriptor table (part of the process's u-area).
  • Each entry is an index (file descriptor: 0, 1, 2, 3, ...) that points to an entry in the system-wide file table.
  • Default descriptors:
  • 0 — Standard Input (stdin)
  • 1 — Standard Output (stdout)
  • 2 — Standard Error (stderr)

5. Mount Table:

  • Maintains a list of all mounted file systems.
  • Each entry maps a device to its mount point.

Relationship Between Data Structures

Process A         Process B
┌──────────┐     ┌──────────┐
│ FD Table │     │ FD Table │
│  0 → ─┐  │     │  0 → ─┐  │
│  1 → ──┼──┐    │  3 → ──┼──┐
│  3 → ─┐│  │    └──────────┘ │
└───────┼┼──┼──────────────────┘
        ││  │
        ▼▼  ▼
  ┌─────────────────────┐
  │  System File Table   │
  │  Entry 1: offset,   │──→ In-Core Inode (file A)
  │  Entry 2: offset,   │──→ In-Core Inode (file B)
  │  Entry 3: offset,   │──→ In-Core Inode (file A)
  └─────────────────────┘
  • Multiple file descriptors (even from different processes) can point to the same file table entry (e.g., after a fork()).
  • Multiple file table entries can point to the same in-core inode (e.g., when two processes independently open the same file).

Summary

  • On-disk structures (inodes, super block, directory entries) persist across reboots.
  • In-memory structures (in-core inodes, file table, FD table) are created at runtime for efficiency.
  • The User FD Table → File Table → In-Core Inode chain is how the kernel connects a process to a file.
  • Multiple processes can share files through these layered data structures.