IMPLEMENTING FILE
SYSTEMS
ALLOCATION METHODS
Presented By
Under the guidance of
Sameeksha R Shet- 1JB22CS132
Trisha Gowda H A- 1JB22CS176 Mrs. Chethana K N Ma’am
Varsha M N- 1JB22CS178
Allocation Methods
As many files are stored on the same disk, The main problem is
how to allocate space to these files so that disk space is utilized
effectively and files can be accessed quickly. Allocation methods
address the problem of allocating space to files so that disk space
is utilized effectively and files can be accessed quickly.
Three methods exist for allocating disk space:
Contiguous allocation
Linked allocation
Indexed allocation
Contiguous Allocation
• Requires that each file occupy a set of contiguous blocks on
the disk.
• Accessing a file is easy - only need the starting location (block
#) and length (number of blocks).
• Contiguous allocation of a file is defined by the disk address
and length (in block units) of the first block. If the file is n
blocks long and starts at location b, then it occupies blocks b
b+1.b+2… b + n – 1.
Advantages of contiguous allocation:
• Accessing a file that has been allocated contiguously is
easy .
• For sequential access, the file system remembers the disk
address of the last block referenced and when necessary,
reads the next block.
• For direct access to block i of a file that starts at block b,
we can immediately access block b + i.
Disadvantages of contiguous
allocation:
1.Finding space for a new file is difficult. The system chosen to
manage free space determines how this task is accomplished.
2. The above algorithms suffer from the problem of external
fragmentation.
As files are allocated and deleted, the free disk space is
broken into pieces leading to external fragmentation.
Depending on the total amount of disk storage and the
average file size, external fragmentation may be a minor or a
major problem.
Linked Allocation
1. It solves the problems of contiguous allocation. By considering each
file is a linked list of disk blocks.
2. These blocks may be scattered anywhere on the disk .
3. The directory contains a pointer to the first and last blocks of a file.
4. This new block is written to and is linked to the end of the file.
5. A file can continue to grow as long as free blocks are available .
Consequently, it is never necessary to compact disk storage.
6. The operations create , read and write can be done using linked
allocation.
Linked Allocation
1. To create a new file, we simply create a new entry file the directory.
With linked allocation, each directory entry has a pointer to the first disk
block of the file. This pointer is initialized to nil (the end-of-list pointer
value) to signify an empty file. The size field is also set to 0.
2. A write to the file causes the free-space management system to filed a
free block, and this new block is written to and is linked to the end of
the file.
3. To read a file, we simply read blocks by following the pointers from
block to block. There is no external fragmentation with linked allocation,
and any free block on the free- space list can be used to satisfy a
Advantages and Disadvantages of Linked Allocation:
Advantages Disadvantages
• There is no external fragmentation. • The major problem is that it can be
used effectively only for
sequential-access files.
• Any free blocks on the free list can
be used to satisfy a request for disk
space.
• Space required for the pointers.
• The size of a file need not be
declared when the file is created. • The solution is clusters. Collect
blocks into multiples and allocate
clusters rather than blocks.
• A file can continue to grow as long as
free blocks are available.
• Reliability- the files are linked
together by pointers scattered all
• It is never necessary to compact disk over the disk and if a pointer were
space for the sake of linked lost or damaged then all the links
allocation. are lost.
File Allocation Table (FAT)
1. A section of disk at the beginning of each volume is set aside to contain
the table. The table has one entry for each disk block and is indexed by
block number.
2. The FAT is used in much the same way as a linked list. The directory
entry contains the block number of the first block of the file.
3. The table entry indexed by that block number contains the block number
of the next block in the file.
4. The chain continues until it reaches the last block, which has a special
end-of-file value as the table entry. An unused block is indicated by a
Indexed Allocation
1. It brings all the pointers together into one location called index
block.
2. Each file has its own index block, which is an array of disk-block
addresses.
3. The ith entry in the index block points to the ith block of the file.
The directory contains the address of the index block. To find and
read the ith block, we use the pointer in the ith index block entry.
4. When the file is created, all pointers in the index block are set to
nil. When the ith block is first written, a block is obtained from the
free-space manager and its address is put in the ith index block
entry.
5. Indexed allocation supports direct access, without suffering from
external fragmentation, because any free block on the disk can
Indexed Allocation
Advantages Of Indexed Allocation:
• It reduces the chances of External Fragmentation.
• Direct accessibility is provided pointers to all the memory
blocks stored.
• A bad data block causes the lost of only that block.
• File size can be increased easily since the system does
not have to look for a contiguous chunk of memory.
Disadvantages of Indexed
Allocation
• Suffersfrom some of the same performance problems as
linked allocation.
• Indexblocks can be cached in memory, however, data
blocks may be spread all over the disk volume.
• Indexed allocation does suffer from wasted space.
• Thepointer overhead of the index block is generally
greater than the pointer overhead of linked allocation.
• If the indexed block is too small, it will not be able to hold
To tackle the disadvantage of small indexed block we consider some
mechanisms for this purpose:
Linked scheme: An index block is normally one disk block. Thus, it can be read and written
directly by itself. To allow for large files, we can link together several index blocks.
Multilevel Index: A variant of linked representation uses a first-level index block to point to a set
of second-level index blocks, which in turn point to the file blocks. To access a block, the
operating system uses the first-level index to find a second-level index block and then uses that
block to find the desired data block.
Combined Scheme: This scheme allows the use of pointers which point to direct blocks and
indirect blocks. Direct blocks which addresses of blocks that contain the data of the file. And
indirect blocks which contain address of addresses of block which in turn contain pointers to
actual data.
Combined Scheme Of Indexed
Allocation
Performance
Contiguous
Linked Indexed
Contiguous allocation Indexed allocation is
In linked allocation, we
requires only one access to more complex. If the
keep the address of the
get a disk block. Since we index block is already
can easily keep the initial
next block in memory
in memory, then the
address of the file in and read it directly. This
access can be made
memory, we can calculate method is fine for
immediately the disk directly. If the memory
sequential access.
address of the ith block and space is not available,
Linked allocation should
read it directly. then we may have to
not be used for an
read first the index
application requiring
block and then the
THANK YOU