0% found this document useful (0 votes)
2K views5 pages

Os File Allocation Methods

File allocation is the method of assigning disk blocks to files in a file system, aiming for efficient disk space usage and fast access. The three main methods are Contiguous Allocation, Linked Allocation, and Indexed Allocation, each with its own advantages and limitations regarding fragmentation, access speed, and space efficiency. Contiguous Allocation is efficient for sequential access but suffers from fragmentation, Linked Allocation allows for easy growth but is limited in access speed, and Indexed Allocation supports both access types but can waste space for small files.

Uploaded by

23b159
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views5 pages

Os File Allocation Methods

File allocation is the method of assigning disk blocks to files in a file system, aiming for efficient disk space usage and fast access. The three main methods are Contiguous Allocation, Linked Allocation, and Indexed Allocation, each with its own advantages and limitations regarding fragmentation, access speed, and space efficiency. Contiguous Allocation is efficient for sequential access but suffers from fragmentation, Linked Allocation allows for easy growth but is limited in access speed, and Indexed Allocation supports both access types but can waste space for small files.

Uploaded by

23b159
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

FILE ALLOCATION:

File allocation refers to the way disk blocks are assigned to files stored in the file
system. The goal is to efficiently utilize disk space and allow fast access to file data.

There are three main methods:

1.​ Contiguous Allocation​

2.​ Linked Allocation​

3.​ Indexed Allocation

CONTIGUOUS ALLOCATION

●​ Contiguous allocation is a file allocation method where a file is stored in a single


continuous block of disk space.
●​ The file is defined using two values: the starting block number and the length of the
file (number of blocks).
●​ If a file starts at block 100 and needs 4 blocks, it occupies:​
100, 101, 102, 103.

●​ Sequential and direct access are very efficient, since all blocks are placed together
and access can be calculated as start + i.
●​ During file creation, the system must search for a large enough contiguous block of
free space.
●​ Allocation uses strategies like First Fit (first large-enough space) or Best Fit (smallest
suitable space).​

●​ A major issue is external fragmentation, where free space is broken into small
non-contiguous parts.
●​ To solve fragmentation, compaction (reorganizing files to create larger free areas) may
be used, but it is time-consuming.​

●​ If the exact size of a file is unknown at creation, the file might either waste space or run
out of space.
●​ Some systems use a modified version called extent-based allocation, where
additional contiguous chunks (extents) are linked if the file grows.
Linked Allocation,
●​ Each file is stored in blocks scattered across the disk, and each block contains
a pointer to the next block.
●​ Only the first and last block addresses of the file are stored in the directory.
●​ Example: A file stored in blocks 9 → 16 → 1 → 10 → 25, where each block
links to the next.​

●​ This method supports easy file growth, as any free block on the disk can be
used for allocation.
●​ There is no external fragmentation, since any block can be used regardless of
its position.
●​ The major limitation is that it only supports sequential access efficiently — to
read block 5, you must follow 4 pointers.​

●​ Each block stores a pointer, reducing usable data space (e.g., with 512B blocks
and 4B pointers, only 508B is data).
●​ If a pointer is lost or corrupted, the entire file chain can be broken, affecting
reliability.​
●​ To improve performance, clustering is used, where multiple blocks are grouped
and linked together, reducing the number of pointers.
●​ An improvement over this method is the FAT (File Allocation Table) approach
(used in MS-DOS), where all pointers are kept in a central table instead of
storing them in blocks.
●​ FAT supports faster random access because the pointer chain is held in
memory.
INDEXED ALLOCATION

●​ Indexed Allocation maintains a separate index block for each file, which
stores the addresses of all its data blocks.
●​ The directory entry for a file stores the address of its index block.
●​ Example: If the index block contains [217, 618, 339], the file consists of
these three blocks.​

●​ Supports direct access efficiently, as block i can be located using index[i].


●​ There is no external fragmentation, since blocks can be allocated anywhere on
the disk.​

●​ A drawback is that an entire index block must be allocated even if only a few
entries are used (space overhead).
●​ For small files, most of the index block is wasted; for large files, the index block
may be too small.

●​ To support large files, several techniques are used:


○​ Linked Index Blocks: When an index block is full, link to another index
block.
○​ Multilevel Index: Use one index block that points to other index blocks.
○​ Combined Scheme (UNIX inode):​

○​ First 12 pointers → direct blocks


○​ 13th → single indirect block
○​ 14th → double indirect block
○​ 15th → triple indirect block​

●​ Indexed allocation works well for both sequential and random access and is
used in most modern file systems.

You might also like