File System Organization (Overview)

 

File System Organization (Overview)

A file system (like vsfs – Very Simple File System) organizes disk storage into structured regions. The disk is divided into fixed-size blocks (e.g., 4 KB each).

๐Ÿงฉ Main Components on Disk

  • Superblock (S) → overall information about the file system

  • Inode Bitmap (i) → tracks free/used inodes

  • Data Bitmap (d) → tracks free/used data blocks

  • Inode Table (I) → stores metadata of files

  • Data Region (D) → stores actual file contents

๐Ÿ‘‰ Layout (simplified):

[S | i | d | Inodes | Data Blocks]





1. Superblock (Heart of File System)

๐Ÿ“Œ What is a Superblock?

The superblock is a special structure that contains global metadata about the file system.

๐Ÿ“Š It stores:

  • Total number of inodes

  • Total number of data blocks

  • Location of:

    • inode table

    • data region

  • File system type (via magic number)

⚙️ Role:

  • When the OS mounts a file system, it first reads the superblock

  • Helps OS understand:

    • where everything is

    • how to access files

๐Ÿ‘‰ Think of it as the “table of contents” of the disk.


2.Inode Bitmap

The inode bitmap is used to track which inodes are free or allocated in the file system.

๐Ÿ“Œ How it works:

  • Each bit represents one inode

    • 0 → inode is free

    • 1 → inode is in use

⚙️ Purpose:

  • Helps the OS quickly find a free inode when creating a new file

  • Updated when files are created or deleted

๐Ÿ‘‰ In simple terms:
Inode bitmap = which files (inodes) exist or are available


3.Data Bitmap

The data bitmap is used to track free and used data blocks on the disk.

๐Ÿ“Œ How it works:

  • Each bit represents one data block

    • 0 → free block

    • 1 → allocated block

⚙️ Purpose:

  • Helps the OS find free space to store file data

  • Updated when data is written or deleted

๐Ÿ‘‰ In simple terms:
Data bitmap = which storage blocks are free or occupied


4. Inode (Core File Metadata Structure)

๐Ÿ“Œ What is an inode?

An inode (index node) is a data structure that stores all metadata about a file, except its name.

Each file is identified internally by an inode number (inumber).


๐Ÿ“Š Information Stored in an Inode

  • File type (file, directory, link)

  • File size

  • Owner (user ID, group ID)

  • Permissions (read/write/execute)

  • Timestamps:

    • last access

    • last modification

    • creation/change time

  • Number of links (hard links)

  • Pointers to data blocks

๐Ÿ‘‰ Important:

  • File name is NOT stored in inode

  • Name is stored in directories


๐Ÿ“ Locating an Inode

Given an inode number:

  • OS calculates its position in the inode table

  • Reads the corresponding disk block

๐Ÿ‘‰ Formula idea:

inode address = inode_start + (inode_number × inode_size)

Example(vsfs): inode size=256bytes = 16 inodes in 4K block


๐Ÿ“ฆ Data Block Pointers in Inode

To store file data, inodes use a multi-level index structure:

๐Ÿ”น Types of pointers:

  1. Direct pointers

    • Directly point to data blocks

    • Fast access for small files

  2. Single Indirect pointer

    • Points to a block containing more pointers

  3. Double Indirect pointer

    • Points to block → points to indirect blocks → data blocks

  4. Triple Indirect pointer

    • Adds another level for very large files


๐ŸŽฏ Why this design?

  • Most files are small → direct pointers are enough

  • Large files are supported using indirect levels

๐Ÿ‘‰ This is called:

Multi-level indexing


๐Ÿ“  Directory Organization

๐Ÿ“Œ What is a Directory?

A directory is a special file that maps:

(filename → inode number)

๐Ÿ“Š Directory Structure

Each directory entry contains:

  • File name (string)

  • Inode number

  • Record length

  • Name length

Directory Entry Format 

๐Ÿงพ Example Directory: dir (inode = 5)

This directory contains three files:

  • foo → inode 12

  • bar → inode 13

  • foobar → inode 24


๐Ÿ“Š On-Disk Representation

inum    reclen    strlen    name
5    4    2    .
2    4    3    ..
12    4    4    foo
13    4    4    bar
24    8    7    foobar

๐Ÿ” Field Explanation

1. inum (inode number)

  • Identifies the file/directory

  • Used to locate metadata in the inode table


2. reclen (record length)

  • Total size of this directory entry

  • Includes:

    • name length

    • extra unused space (if any)

๐Ÿ‘‰ Helps in:

  • Skipping to next entry

  • Reusing space after deletion


3. strlen (string length)

  • Actual length of the file name


4. name

  • Human-readable file/directory name


Special Entries

Every directory contains:

๐Ÿ”น . (dot)

  • Refers to current directory

  • Here → inode 5 (dir itself)

๐Ÿ”น .. (dot-dot)

  • Refers to parent directory

  • Here → inode 2 (root directory)


Key Concepts Explained

๐Ÿ”„ 1. Directory = List of Mappings

A directory is simply:

(filename → inode number)

Example:

foo12 bar → 13

๐Ÿ—‘️ 2. Deletion (unlink)

When a file is deleted:

  • Its directory entry is removed

  • But space may remain unused in the directory

๐Ÿ‘‰ Example:

[ foo ][ bar ][ foobar ] ↓ delete bar [ foo ][ empty ][ foobar ]

♻️ 3. Why reclen is Important

  • Directory entries are variable-sized

  • After deletion, gaps appear

  • New entries can reuse these gaps

๐Ÿ‘‰ Example:

  • If foobar (larger entry) is deleted

  • A smaller file can reuse that space


Final Understanding

  • Directory is a special file

  • It stores entries (name + inode)

  • Special entries:

    • . → current

    • .. → parent

  • reclen enables efficient space reuse



๐Ÿ‘‰ A directory is a structured list of entries mapping file names to inode numbers, with extra fields to manage space efficiently.


๐Ÿ“ Special Entries

Every directory contains:

  • . → current directory

  • .. → parent directory


⚙️ How Directories Work

  • Directory itself has:

    • an inode

    • data blocks (just like files)

  • These data blocks store the list of entries


๐Ÿ”„ File Access Flow

When accessing /foo/bar.txt:

  1. Start at root /

  2. Look up foo → get inode number

  3. Read inode → locate its data blocks

  4. Find bar.txt entry → get inode number

  5. Read file inode → access actual data blocks


๐Ÿ—‘️ Deletion Behavior

  • When a file is deleted:

    • directory entry is removed

    • space may remain (reusable)

  • Directory may have “holes” due to deletions


Summary

ComponentPurpose
Superblock        Global info about file system
Inode        Metadata + data block pointers
Directory        Maps file names → inode numbers
Data blocks        Actual file content

Comments

Popular posts from this blog

Operating Systems OS PCCST403 Semester 4 BTech KTU CS 2024 Scheme

Introduction to Operating System -Virtualization, Concurrency, and Persistence

Operating Systems PCCST403 Scheme and Syllabus