Module 5
Module 5
•Single-Level Directory
•Two-Level Directory
•Tree Structure/ Hierarchical Structure
•Acyclic Graph Structure
•General-Graph Directory Structure
• Single-level Directory
• The simplest directory structure is the single-level directory. All files
are contained in the same directory, which is easy to support and
understand
• The directory contains one entry per each file present on the file
system.
• A single level directory has a significant limitation, however, when the
number of files increases or when the system has more than one user
• Since all the files are in the same directory, they must have a unique
name. If two users call their dataset test, then the unique name rule
violated.
Advantages
Disadvantages
• The allocation methods define how the files are stored in the
disk blocks. There are three main disk space or file allocation
methods.
• Contiguous Allocation
• Linked Allocation
• Indexed Allocation
• The main idea behind these methods is to provide:
• Efficient disk space utilization.
• Fast access to the file blocks.
1. Contiguous Allocation
• In this scheme, each file occupies a contiguous set of blocks on the
disk.
• 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.
• The directory entry for a file with contiguous allocation contains
• Address of starting block
• Length of the allocated portion.
• The file ‘mail’ in the following figure starts from the block 19 with
length = 6 blocks. Therefore, it occupies 19, 20, 21, 22, 23, 24 blocks.
• Advantages:
•Both the Sequential and Direct Accesses are supported by this. For direct
access, the address of the kth block of the file which starts at block b can
easily be obtained as (b+k).
•This is extremely fast since the number of seeks are minimal because of
contiguous allocation of file blocks.
•Disadvantages:
•Increasing file size is difficult because it depends on the availability of contiguous
memory at a particular instance.
•This method suffers from both internal and external fragmentation. This makes it
inefficient in terms of memory utilization.
2. Linked List Allocation
• In this scheme, each file is a linked list of disk blocks which need not
be contiguous. The disk blocks can be scattered anywhere on the
disk.
• The directory entry contains a pointer to the starting and the ending
file block. Each block contains a pointer to the next block occupied by
the file.
• The file ‘jeep’ in following image shows how the blocks are randomly
distributed. The last block (25) contains -1 indicating a null pointer
and does not point to any other block.
• Advantages:
• This is very flexible in terms of file size. File size can be increased easily
since the system does not have to look for a contiguous chunk of memory.
• This method does not suffer from external fragmentation. This makes it
relatively better in terms of memory utilization.
• Disadvantages:
• Because the file blocks are distributed randomly on the disk, a large
number of seeks are needed to access every block individually. This makes
linked allocation slower.
• It does not support random or direct access. We can not directly access the
blocks of a file. A block k of a file can be accessed by traversing k blocks
sequentially (sequential access ) from the starting block of the file via block
pointers.
• Pointers required in the linked allocation incur some extra overhead.
• 3. Indexed Allocation
• In this scheme, a special
block known as the Index
block contains the pointers
to all the blocks occupied by
a file
• Disadvantages
• The disadvantages of the bit vector method are-
• For finding a free block, the operating system may need to search the
entire bit vector.
• To detect the first 1 in a word that is not 0 using this method, special
hardware support is needed.
• Keeping the bit vector in the main memory is possible for smaller disks but
not for larger ones.
Linked List
• In this method, all the free blocks existing in
the disk are linked together in a linked list. The
address of the first free block is stored
somewhere in the memory. Each free block
contains a pointer that contains the address to
the next free block. The last free block points to
null, indicating the end of the linked list.
• For example, consider a disk having 16 blocks
where block numbers 3, 4, 5, 6, 9, 10, 11, 12,
13, and 14 are free, and the rest of the blocks,
i.e., block numbers 1, 2, 7, 8, 15 and 16 are
allocated to some files. If we maintain a linked
list, then Block 3 will contain a pointer to Block
4, and Block 4 will contain a pointer to Block 5.
• Advantages
• The advantages of the linked list method are-
• External fragmentation is prevented by linked list allocation.
• Directory only needs to hold the starting and ending pointers of the
file, linked list allocation places less strain on it.
• Disadvantages
• This method is inefficient since we need to read each block to
traverse the list, which takes more I/O time.
• There is an overhead in maintaining the pointer.
• There is no provision for random or direct memory access in linked
list allocation. We must search through the full linked list to locate the
correct block
Grouping
• The third method of free space management in operating systems is
grouping. This method is the modification of the linked list method.
• In this method, the first free block stores the addresses of the n free
blocks. The first n-1 of these blocks is free. The last block in
these n free blocks contains the addresses of the next n free blocks,
and so on.
For example, consider a disk having 16 blocks where block numbers 3, 4, 5, 6, 9,
10, 11, 12, 13, and 14 are free, and the rest of the blocks, i.e., block numbers 1, 2,
7, 8, 15 and 16 are allocated to some files.
• Thus each free block in the disk will contain two things-
A pointer to the next free block.
The number of free contiguous blocks following