The allocation methods define how the files are stored in the disk blocks. There are three main disk space or file allocation methods.

The main idea behind these methods is to provide:

All the three methods have their own advantages and disadvantages as discussed below:

Contiguous Allocation :

Example of contiguous allocation:
We can see in the given diagram, that there is a file. The name of the file is ‘mail.’ The file starts from the 19th block and the length of the file is 6. So, the file occupies 6 blocks in a contiguous manner. Thus, it will hold blocks 19, 20, 21, 22, 23, 24.

Advantages of Contiguous Allocation:

  1. The contiguous allocation method gives excellent read performance.
  2. Contiguous allocation is easy to implement.
  3. The contiguous allocation method supports both types of file access methods that are sequential access and direct access.
  4. The Contiguous allocation method is fast because, in this method number of seeks is less due to the contiguous allocation of file blocks.

Disadvantages of Contiguous Allocation:

  1. In the contiguous allocation method, sometimes disk can be fragmented.
  2. In this method, it is difficult to increase the size of the file due to the availability of the contiguous memory block.

Linked Allocation:

Example of linked allocation:
We can see in the below figure that we have a file named ‘jeep.’ The value of the start is 9. So, we have to start the allocation from the 9th block, and blocks are allocated in a random manner. The value of the end is 25. It means the allocation is finished on the 25th block. We can see in the below figure that the block (25) comprised of -1, which means a null pointer, and it will not point to another block.

Advantages of Linked Allocation:

  1. In linked list allocation, there is no external fragmentation. Due to this, we can utilize the memory better.
  2. In linked list allocation, a directory entry only comprises of the starting block address.
  3. The linked allocation method is flexible because we can quickly increase the size of the file because, in this to allocate a file, we do not require a chunk of memory in a contiguous form.

Disadvantages of Linked Allocation:

  1. Linked list allocation does not support direct access or random access.
  2. In linked list allocation, we need to traverse each block.
  3. If the pointer in the linked list break in linked list allocation, then the file gets corrupted.
  4. In the disk block for the pointer, it needs some extra space.

Indexed Allocation:

Example of indexed allocation:
Here, the index block is 19.

Advantages of Indexed Allocation:

  1. The indexed allocation method solves the problem of external fragmentation.
  2. Indexed allocation provides direct access.

Disadvantages of Indexed Allocation:

  1. In indexed allocation, pointer overhead is more.
  2. We can lose the entire file if an index block is not correct.
  3. It is totally a wastage to create an index for a small file.