File Organization and Processing
Lecture 7
File System Implementation
Mohamed Mead
Indexed Allocation
Linked allocation solves the external-fragmentation and
size-declaration problems of contiguous allocation.
However, in the absence of a FAT, linked allocation cannot
support efficient direct access.
Indexed allocation solves this problem by bringing all the
pointers together into one location: the index block.
Indexed Allocation
Each file has its own index block, which is an array
of disk-block addresses. The ith entry in the index
block points to the ith block of the file.
Indexed Allocation
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.
Indexed Allocation
When the file is created, all pointers in the index block are
set to null.
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.
Indexed allocation supports direct access
Indexed Allocation
Indexed allocation does suffer from wasted space,
however. The pointer overhead of the index block is
generally greater than the pointer overhead of linked
allocation.
Indexed Allocation
Consider a common case in which we have a file of only one
or two blocks.
With linked allocation, we lose the space of only one
pointer per block.
With indexed allocation, an entire index block must be
allocated, even if only one or two pointers will be non-
null.
Indexed File Allocation Example
8 A. Frank - P. Weisberg
Performance
Before selecting an allocation method, we need to
determine how the systems will be used.
A system with mostly sequential access should not
use the same method as a system with mostly
random access.
Free-Space Management
Since disk space is limited, we need to reuse the
space from deleted files for new files, if possible.
(Write-once optical disks allow only one write to any
given sector, and thus reuse is not physically
possible.)
To keep track of free disk space, the system
maintains a free-space list.
Free-Space Management
The free-space list records all free disk blocks—those not
allocated to some file or directory.
To create a file, we search the free-space list for the
required amount of space and allocate that space to the
new file. This space is then removed from the free-space
list.
Free-Space Management
When a file is deleted, its disk space is added to the free-
space list. The free-space list, despite its name, may not be
implemented as a list.
Free-Space Management - Bit
Vector
Frequently, the free-space list is implemented as a bit map or
bit vector.
Each block is represented by 1 bit. If the block is free, the bit
is 1; if the block is allocated, the bit is 0.
For example, consider a disk where blocks 2, 3, 4, 5, 8, 9, 10, 11,
12, 13, 17, 18, 25, 26, and 27 are free and the rest of the blocks
are allocated. The free-space
bit map would be 001111001111110001100000011100000 ...
Free-Space Management
The main advantage of this approach is its relative
simplicity and its efficiency in finding the first free block
or n consecutive free blocks on the disk.
One technique for finding the first free block on a system
that uses a bit-vector to allocate disk space is to
sequentially check each word in the bit map to see
whether that value is not 0
Free-Space Management - Linked
List
Another approach to free-space management is to link
together all the free disk blocks, keeping a pointer to the
first free block in a special location on the disk and caching
it in memory.
This first block contains a pointer to the next free disk
block, and so on.
Free-Space Management
blocks 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 17, 18, 25, 26, and 27
were free and the rest of the blocks were allocated. In
this situation, we would keep a pointer to block 2 as the
first free block.