Sequential Implementation for file
allocation strategies
Prepared by: Sinan D.
What is File Allocation?
• File allocation is how an operating system
stores files on a disk.
• The disk is divided into small blocks, and
files are stored using these blocks.
File Allocation
• File allocation is how the OS decides
which disk blocks are given to a file.
• There are three main strategies:
[Link]: Blocks are next to each other.
[Link]: Blocks are scattered but linked like a chain.
[Link]: Blocks are scattered, but pointers are in one
index block.
What is Sequential Allocation?
• Sequential allocation stores a file in
continuous (adjacent) disk blocks.
• All parts of the file are placed one after
another on the disk.
• Think of it like sitting people in a cinema.
• If one group comes together, they sit in adjacent
seats.
• That’s how sequential allocation works .
How Sequential Allocation Works
1)When a new file is created, the operating
system:
- Finds free continuous blocks on the disk.
2)The file is stored in those blocks one by
one, in order.
3)The system only needs to store:
• The starting block number
• The length of the file (number of blocks)
Example
• If a file needs 5 blocks and starts at block
20:
• 20 | 21 | 22 | 23 | 24
• start block = 20
• length = 5 blocks
• The blocks are stored sequentially.
Advantages
1) Fast file access
• Reading files is very fast.
• The disk head moves in one direction only.
• Best for large files like videos and audio.
2)Simple to Implement
• Only starting block and size are needed.
• Easy to manage.
3) Good for Sequential Access
• Works very well when data is read from
beginning to end.
Disadvantages
• 1. External Fragmentation
• Free space becomes broken into small
pieces.
• Even if total free space exists, it may not
be continuous.
• 2. File Size Must Be Known
• The system needs to know file size in
advance.
• Hard to increase file size later.
Disadvantages
• 3. Difficult to Grow Files
• If a file becomes bigger, it may need to be:
• Moved to another location
• Or copied to a new continuous space
Where It Is Used
• CD-ROM and DVD systems
• Media files (audio and video)
• Read-only storage systems
• Old operating systems
Code Implementation
• #include <stdio.h> • for (i = start; i < start + len; i++)
• #define SIZE 20 {
• if (i >= SIZE || disk[i] == 1) {
• int disk[SIZE];
• printf("Allocation failed\n");
• int main() { • return 0;
• int i, start, len; • } }
• for (i = 0; i < SIZE; i++) • for (i = start; i < start + len; i++)
• disk[i] = 0; • disk[i] = 1;
• printf("Enter starting block: • printf("File allocated at blocks:
"); ");
• scanf("%d", &start); • for (i = start; i < start + len; i++)
• • printf("%d ", i);
printf("Enter file length: ");
• return 0; }
• scanf("%d", &len);
Summary
• Sequential allocation is simple and fast.
• It uses continuous disk space.
• Even if total free space exists, it may not
be continuous.
u !
Yo
n k
h a
T