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):
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:
๐ฆ Data Block Pointers in Inode
To store file data, inodes use a multi-level index structure:
๐น Types of pointers:
-
Direct pointers
-
Directly point to data blocks
-
Fast access for small files
-
-
Single Indirect pointer
-
Points to a block containing more pointers
-
-
Double Indirect pointer
-
Points to block → points to indirect blocks → data blocks
-
-
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:
๐ 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:
Example:
๐️ 2. Deletion (unlink)
When a file is deleted:
-
Its directory entry is removed
-
But space may remain unused in the directory
๐ Example:
♻️ 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
-
-
reclenenables 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:
-
Start at root
/ -
Look up
foo→ get inode number -
Read inode → locate its data blocks
-
Find
bar.txtentry → get inode number -
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
| Component | Purpose |
|---|---|
| Superblock | Global info about file system |
| Inode | Metadata + data block pointers |
| Directory | Maps file names → inode numbers |
| Data blocks | Actual file content |


Comments
Post a Comment