0
0
Operating Systemsknowledge~6 mins

File allocation methods (contiguous, linked, indexed) in Operating Systems - Full Explanation

Choose your learning style9 modes available
Introduction
Imagine you have a big box where you want to store many books. The problem is how to arrange these books so you can find and use them easily later. File allocation methods solve this problem by deciding how files are stored on a computer's disk.
Explanation
Contiguous Allocation
In contiguous allocation, each file is stored in one continuous block of disk space. This means all parts of the file are next to each other, making reading fast and simple. However, it can cause wasted space if files grow or shrink, and finding a big enough free block can be hard.
Contiguous allocation stores files in one continuous block, making access fast but space management tricky.
Linked Allocation
Linked allocation stores a file as a chain of disk blocks scattered anywhere on the disk. Each block contains a pointer to the next block. This method uses space efficiently and allows files to grow easily, but accessing a file can be slower because the system must follow pointers from block to block.
Linked allocation stores files as scattered blocks linked by pointers, allowing flexible size but slower access.
Indexed Allocation
Indexed allocation keeps a special index block that holds pointers to all the blocks of a file. This index acts like a table of contents, letting the system find any part of the file quickly. It combines the benefits of contiguous and linked methods but requires extra space for the index block.
Indexed allocation uses an index block to point to file blocks, enabling fast access with some extra overhead.
Real World Analogy

Think of storing books in a library. Contiguous allocation is like placing all pages of a book on one shelf in order. Linked allocation is like having pages scattered in different shelves but with a note on each page telling where the next page is. Indexed allocation is like having a special card listing all the shelf locations of each page.

Contiguous Allocation → All pages of a book placed together on one shelf in order
Linked Allocation → Pages scattered on different shelves with notes pointing to the next page
Indexed Allocation → A special card listing all shelf locations of the book's pages
Diagram
Diagram
┌─────────────────────────────┐
│ Contiguous Allocation        │
│ ┌───────────────┐           │
│ │ File Blocks   │           │
│ │ [1][2][3][4] │           │
│ └───────────────┘           │
├─────────────────────────────┤
│ Linked Allocation            │
│ ┌─────┐   ┌─────┐   ┌─────┐ │
│ │[1]─┐│→ │[3]─┐│→ │[2]  │ │
│ └─┬──┘│  └─┬──┘│  └─────┘ │
│   ↓    ↓    ↓              │
├─────────────────────────────┤
│ Indexed Allocation           │
│ ┌───────────────┐           │
│ │ Index Block   │           │
│ │ [1][3][2][4] │           │
│ └───────────────┘           │
│ Blocks scattered anywhere   │
└─────────────────────────────┘
This diagram shows how files are stored in contiguous, linked, and indexed allocation methods.
Key Facts
Contiguous AllocationStores a file in one continuous block of disk space.
Linked AllocationStores a file as linked blocks scattered anywhere on the disk.
Indexed AllocationUses an index block to point to all blocks of a file.
PointerA reference in one block that tells where the next block is located.
Index BlockA special block that holds pointers to all parts of a file.
Common Confusions
Believing contiguous allocation always wastes space.
Believing contiguous allocation always wastes space. Contiguous allocation can waste space if files grow or shrink, but it is very efficient for fixed-size files.
Thinking linked allocation allows fast random access.
Thinking linked allocation allows fast random access. Linked allocation requires following pointers sequentially, so random access is slower compared to indexed allocation.
Assuming indexed allocation does not need extra space.
Assuming indexed allocation does not need extra space. Indexed allocation requires extra disk space for the index block that stores pointers to file blocks.
Summary
File allocation methods decide how files are stored on disk to balance speed and space use.
Contiguous allocation stores files in one block for fast access but can waste space.
Linked allocation uses pointers to link scattered blocks, allowing flexible file sizes but slower access.
Indexed allocation uses an index block to quickly find file parts, combining benefits of both methods.