File Allocation Program Implementation
File Allocation Program Implementation
Problems
1 Sequential Allocation
Problem Statement: Given a disk with 10 blocks (0-9), an initial file occupies
blocks 2-4. The file grows by 2 blocks. If contiguous space exists, append to
the file; otherwise, relocate it entirely. Print the success message with new
allocation or a failure message.
Initial State:
0 1 2 3 4 5 6 7 8 9
Output Cases:
• If blocks 5,6 are free: Allocation Success - File now occupies (2-6)
• If no contiguous space: Relocate file to another continuous block
and print new range
• If no space available: Allocation Failed
2 Indexed Allocation
Problem Statement: Given a file that uses indexed allocation, the index block
at 1 points to allocated blocks {3,5,7}. The file grows by 2 more blocks. If space
is available, update the index block and print success, else return failure.
Initial State:
0 1 2 3 4 5 6 7 8 9
Output Cases:
• If 2 free blocks exist: Allocation Success - Updated index block
points to new blocks
• If not enough space: Allocation Failed
1
3 Linked Allocation
Problem Statement: A file is stored as linked allocation: 2 → 5 → 7. The
file grows by 2 blocks. If free blocks exist, update pointers and print success,
else return failure.
Initial State:
0 1 2 3 4 5 6 7 8 9
Output Cases:
• If free blocks exist: Allocation Success - File now links to new
blocks
• If no space available: Allocation Failed