File Allocation Methods in OS
Tags: computerscience, operatingsystem, os
Published: 2020-10-24 11:53:50

Contiguous allocation
In this scheme, a file is made from the contiguous set of blocks Linear ordering on the disk is defined by the disk addresses. In this scheme only one job is accessing the disk block b after that it accesses the block b+1 and there are no head movements. When the movement of the head is needed the head moves only from one track to another track. So the disk number that is required for accessing the contiguous allocation is minimal. Contiguous allocation method provides a good performance that’s why it is used by the IBM VM/CMS operating system. For example, if a file requires n blocks and is given a block b as the starting location, then the blocks assigned to the file will be: b, b+1, b+2,..., b+n-1. This means that given the starting block address and the length of the file (in terms of blocks required), we can determine the blocks occupied by the file. For a contiguous allocation the directory entry the address of the starting block and Length of the allocated portion.

Advantages:

In the contiguous allocation, sequential and direct access both are supported.
For the direct access, the starting address of the kth block is given and further blocks are obtained by b+K,
This is very fast and the number of seeks is minimal in the contiguous allocation method.

Linked allocation
The problems of contiguous allocation are solved in the linked allocation method. In this scheme, disk blocks are arranged in the linked list form which is not contiguous. The disk block is scattered in the disk. In this scheme, the directory entry contains the pointer of the first block and pointer of the ending block. These pointers are not for the users. For example, a file of six blocks starts at block 10 and end at the block. Each pointer contains the address of the next block. When we create a new file we simply create a new entry with the linked allocation. Each directory contains the pointer to the first disk block of the file. when the pointer is nil then it defines the empty file.

Advantages:

In terms of the file size, this scheme is very flexible.
We can easily increase or decrease the file size and system does not worry about the contiguous chunks of memory.
This method free from external fragmentation this makes it better in terms of memory utilization.

Indexed Allocation
In this scheme, a special block known as the index block contains the pointer to all the blocks occupied by a file. each file contains its index which is in the form of an array of disk block addresses. The ith entry of index block point to the ith block of the file. The address of the index block is maintained by the directory. When we create a file all pointer is set to nil. A block is obtained from the free space manager when the first ith block is written. When the index block is very small it is difficult to hold all the pointers for the large file. to deal with this issue a mechanism is available.

Advantages:

This scheme supports random access of the file.
This scheme provides fast access to the file blocks.
This scheme is free from the problem of external fragmentation.

Read more on File Allocation in OS: https://exploringbits.com/file-allocation-methods-in-os/