Operating System 4
Operating System 4
UNIT - 4
File System Implementation in Operating
System
● File System Structure: The file system structure refers to how the
files and directories are organized and stored on the physical storage
device. This includes the layout of file systems data structures such
as the directory structure, file allocation table, and inodes.
● File Allocation: The file allocation mechanism determines how files
are allocated on the storage device. This can include allocation
techniques such as contiguous allocation, linked allocation, indexed
allocation, or a combination of these techniques.
● Data Retrieval: The file system implementation determines how the
data is read from and written to the physical storage device. This
includes strategies such as buffering and caching to optimize file I/O
performance.
● Security and Permissions: The file system implementation includes
features for managing file security and permissions. This includes
access control lists (ACLs), file permissions, and ownership
management.
● Recovery and Fault Tolerance: The file system implementation
includes features for recovering from system failures and
maintaining data integrity. This includes techniques such as
journaling and file system snapshots.
3
There are several types of file systems, each designed for specific purposes
and compatible with different operating systems. Some common file system
types include:
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
All the three methods have their own advantages and disadvantages as
discussed below:
6
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. This
means that given the starting block address and the length of the file (in terms
of blocks required), we can determine the blocks occupied by the file.
The directory entry for a file with contiguous allocation contains
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:
7
● 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:
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
8
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
9
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. Each file has its own index block.
The ith entry in the index block contains the disk address of the ith file block.
The directory entry contains the address of the index block as shown in the
image:
Advantages:
● This supports direct access to the blocks occupied by the file and
therefore provides fast access to the file blocks.
● It overcomes the problem of external fragmentation.
10
Disadvantages:
For files that are very large, single index block may not be able to hold all the
pointers.
Following mechanisms can be used to resolve this:
The Operating system works to allocate free space to the files when a file is created. It
also creates a free void space when a file is deleted from the system. For doing all
these tasks and managing spaces in our system, the operating system works with the
help of a free space management system and allocates and de-allocates memory
spaces simultaneously. In this article, we are going to learn about these concepts.
12
When a file is created, the operating system searches the free space list for the required
space allocated to save a file. While deletion a file, the file system frees the given space
and adds this to the free space list.
"Free block number" can be defined as that block which does not contain any value,
i.e., they are free blocks. The formula to find a free block number is :
[Block number = (number of bits per words)*(number of 0-value word) + Offset of first 1
bit ]
=8∗0+3=3
=8∗0+3=3
● The operating system goes through all the blocks until it finds a free block.
(block whose bit is '0').
14
Linked List
A linked list is another approach for free space management in an operating system. In
it, all the free blocks inside a disk are linked together in a linked list. These free blocks
on the disk are linked together by a pointer. These pointers of the free block contain the
address of the next free block and the last pointer of the list points to null which
indicates the end of the linked list. This technique is not enough to traverse the list
because we have to read each disk block one by one which requires I/O time.
In the above example, we have three blocks of free memory, each represented by a node
in the linked list. The first block has 20 bytes of free memory, the second block has 20
bytes of free memory, and the third block has 60 bytes of free memory. The operating
system can use this linked list to allocate memory blocks to processes as needed.
Disadvantages
Grouping
The grouping technique is also called the "modification of a linked list technique". In this
method, first, the free block of memory contains the addresses of the n-free blocks. And
the last free block of these n free blocks contains the addresses of the next n free block
of memory and this keeps going on. This technique separates the empty and occupied
blocks of space of memory.
Example
Suppose we have a disk with some free blocks and some occupied blocks. The free
block numbers are
15
3,4,5,6,9,10,11,12,13,
3,4,5,6,9,10,11,12,13,, and
14
1,2,7,8,15,
1,2,7,8,15, and
16
16
When the "grouping technique" is applied, block 3 will store the addresses of blocks 4, 5,
and 6 because block 3 is the first free block. In the same way, block 6 will store the
addresses of blocks 9, one 0, and one 1 because block 6 is the first occupied block.
1. By using this method, we can easily find addresses of a large number of free
blocks easily and quickly.
Disadvantage
Counting
In memory space, several files are created and deleted at the same time. For which
memory blocks are allocated and de-allocated for the files. Creation of files occupy free
blocks and deletion of file frees blocks. When there is an entry in the free space, it
16
consists of two parameters- "address of first free disk block (a pointer)" and "a number
'n'".
Example
Let us take an example where a disk has 16 blocks in which some blocks are empty and
some blocks are occupied as given below :
When the "counting technique" is applied, the block number 3 will represent block
number 4 because block 3 is the first free block. Then, the block stores the number of
free blocks
i.e. - there are 4 free blocks together. In the same way, the first occupied block number
9 will represent block number 10 and keeps the number of rest occupied blocks i.e.-
there are 6 occupied blocks as shown in the above figure.
Advantages
Disadvantage
● In the counting method, the first free block stores the rest free blocks, so it
requires more space.
Advantages
Disadvantages
● Arm Assembly is there which keeps a pointy r/w head on each disk to read of write on a
particular disk.
● A world cylinder may also be used at times to refer disk stack.
● Transfer rate: This is the rate at which the data moves from disk to the computer.
● Random access time: It is the sum of the seek time and rotational latency.
Seek time is the time taken by the arm to move to the required track. Rotational latency is defined as
the time taken by the arm to reach the required sector in the track.
Transfer time is the time to transfer the data. It depends on the rotating speed of the disk and
number of bytes to be transferred.
In this article, we will explore the different types of disk scheduling algorithms
and their functions. By understanding and implementing these algorithms, we
can optimize system performance and ensure faster data retrieval.
19
Disk scheduling algorithms are crucial in managing how data is read from and
written to a computer’s hard disk. These algorithms help determine the order
in which disk read and write requests are processed, significantly impacting
the speed and efficiency of data access. Common disk scheduling methods
include First-Come, First-Served (FCFS), Shortest Seek Time First (SSTF),
SCAN, C-SCAN, LOOK, and C-LOOK. By understanding and implementing these
algorithms, we can optimize system performance and ensure faster data
retrieval.
● Multiple I/O requests may arrive by different processes and only one
I/O request can be served at a time by the disk controller. Thus other
I/O requests need to wait in the waiting queue and need to be
scheduled.
● Two or more requests may be far from each other so this can result
in greater disk arm movement.
● Hard drives are one of the slowest parts of the computer system and
thus need to be accessed in an efficient manner.
● Seek Time: Seek time is the time taken to locate the disk arm to a
specified track where the data is to be read or written. So the disk
scheduling algorithm that gives a minimum average seek time is
better.
20
There are several Disk Several Algorithms. We will discuss in detail each one
of them.
FCFS is the simplest of all Disk Scheduling Algorithms. In FCFS, the requests
are addressed in the order they arrive in the disk queue. Let us understand this
with the help of an example.
Example:
(82-50)+(170-82)+(170-43)+(140-43)+(140-24)+(24-16)+(190-16)
=642
23
Advantages of FCFS
Disadvantages of FCFS
In SSTF (Shortest Seek Time First), requests having the shortest seek time are
executed first. So, the seek time of every request is calculated in advance in
the queue and then they are scheduled according to their calculated seek
time. As a result, the request near the disk arm will get executed first. SSTF is
certainly an improvement over FCFS as it decreases the average response
time and increases the throughput of the system. Let us understand this with
the help of an example.
24
Example:
So,
(50-43)+(43-24)+(24-16)+(82-16)+(140-82)+(170-140)+(190-170)
=208
3. SCAN
In the SCAN algorithm the disk arm moves in a particular direction and
services the requests coming in its path and after reaching the end of the disk,
it reverses its direction and again services the request arriving in its path. So,
this algorithm works as an elevator and is hence also known as an elevator
algorithm. As a result, the requests at the midrange are serviced more and
those arriving behind the disk arm will have to wait.
Example:
SCAN Algorithm
26
Therefore, the total overhead movement (total distance covered by the disk
arm) is calculated as
● High throughput
● Low variance of response time
● Average response time
● Long waiting time for requests for locations just visited by disk arm
4. C-SCAN
In the SCAN algorithm, the disk arm again scans the path that has been
scanned, after reversing its direction. So, it may be possible that too many
requests are waiting at the other end or there may be zero or few requests
pending at the scanned area.
27
These situations are avoided in the CSCAN algorithm in which the disk arm
instead of reversing its direction goes to the other end of the disk and starts
servicing the requests from there. So, the disk arm moves in a circular fashion
and this algorithm is also similar to the SCAN algorithm hence it is known as
C-SCAN (Circular SCAN).
Example:
Circular SCAN
So, the total overhead movement (total distance covered by the disk arm) is
calculated as:
5. LOOK
LOOK Algorithm is similar to the SCAN disk scheduling algorithm except for
the difference that the disk arm in spite of going to the end of the disk goes
only to the last request to be serviced in front of the head and then reverses
its direction from there only. Thus it prevents the extra delay which occurred
due to unnecessary traversal to the end of the disk.
Example:
LOOK Algorithm
29
So, the total overhead movement (total distance covered by the disk arm) is
calculated as:
6. C-LOOK
Example:
C-LOOK
So, the total overhead movement (total distance covered by the disk arm) is
calculated as