0% found this document useful (0 votes)
3 views

unit 5 - file and input management

The document covers I/O and file management in operating systems, detailing I/O devices, buffering techniques, and disk scheduling algorithms. It explains the modes of data transfer, advantages and disadvantages of I/O interfaces, and various disk scheduling strategies like FCFS, SSTF, SCAN, and C-SCAN. Additionally, it discusses the importance of buffering in optimizing I/O operations and enhancing system performance.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

unit 5 - file and input management

The document covers I/O and file management in operating systems, detailing I/O devices, buffering techniques, and disk scheduling algorithms. It explains the modes of data transfer, advantages and disadvantages of I/O interfaces, and various disk scheduling strategies like FCFS, SSTF, SCAN, and C-SCAN. Additionally, it discusses the importance of buffering in optimizing I/O operations and enhancing system performance.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

OPERATING SYSTEM

Unit 5: File and I/O Management


I/O Management: I/O Devices, Organization of I/O function, I/O Buffering,
Disk Scheduling Disk Scheduling policies like FIFO, LIFO, STTF, SCAN, C-
SCAN. File Management: Concept, Access methods, Directory Structure,
Protection, File System implementation, Directory Implementation, Allocation
methods, Free Space management. Case Study: I/O and File Management in
multi-cores OS.

Input and Output Devices


An input/output device, often known as an IO device, is any hardware that allows a human
operator or other systems to interface with a computer. Input/output devices, as the name
implies, are capable of delivering data (output) to and receiving data from a computer (input).
An input/output (I/O) device is a piece of hardware that can take, output, or process data. It
receives data as input and provides it to a computer, as well as sends computer data to storage
media as a storage output.
Input Devices
Input devices are the devices that are used to send signals to the computer for performing
tasks. The receiver at the end is the CPU (Central Processing Unit), which works to send
signals to the output devices. Some of the classifications of Input devices are:
• Keyboard Devices
• Pointing Devices
• Composite Devices
• Game Controller
• Visual Devices
• Audio Input Devices
I/O Interface
The method that is used to transfer information between internal storage and external I/O
devices is known as I/O interface. The CPU is interfaced using special communication links
by the peripherals connected to any computer system. These communication links are used
to resolve the differences between CPU and peripheral. There exists special hardware
components between CPU and peripherals to supervise and synchronize all the input and
output transfers that are called interface units.
Mode of Transfer:

Course Name--Operating Systems


Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
The binary information that is received from an external device is usually stored in the
memory unit. The information that is transferred from the CPU to the external device is
originated from the memory unit. CPU merely processes the information but the source and
target are always the memory unit. Data transfer between CPU and the I/O devices may be
done in different modes. Data transfer to and from the peripherals may be done in any of
the three possible ways
1. Programmed I/O.
2. Interrupt- initiated I/O.
3. Direct memory access( DMA).
Now let’s discuss each mode one by one.
1. Programmed I/O: It is due to the result of the I/O instructions that are written in the
computer program. Each data item transfer is initiated by an instruction in the program.
Usually the transfer is from a CPU register and memory. In this case it requires constant
monitoring by the CPU of the peripheral devices.
Example of Programmed I/O: In this case, the I/O device does not have direct access
to the memory unit. A transfer from I/O device to memory requires the execution of
several instructions by the CPU, including an input instruction to transfer the data from
device to the CPU and store instruction to transfer the data from CPU to memory. In
programmed I/O, the CPU stays in the program loop until the I/O unit indicates that it is
ready for data transfer. This is a time consuming process since it needlessly keeps the
CPU busy. This situation can be avoided by using an interrupt facility. This is discussed
below.
2. Interrupt- initiated I/O: Since in the above case we saw the CPU is kept busy
unnecessarily. This situation can very well be avoided by using an interrupt driven
method for data transfer. By using interrupt facility and special commands to inform the
interface to issue an interrupt request signal whenever data is available from any device.
In the meantime the CPU can proceed for any other program execution. The interface
meanwhile keeps monitoring the device. Whenever it is determined that the device is
ready for data transfer it initiates an interrupt request signal to the computer. Upon
detection of an external interrupt signal the CPU stops momentarily the task that it was
already performing, branches to the service program to process the I/O transfer, and
then return to the task it was originally performing.
• The I/O transfer rate is limited by the speed with which the processor can test and
service a device.
• The processor is tied up in managing an I/O transfer; a number of instructions must
be executed for each I/O transfer.
• Terms:
• Hardware Interrupts: Interrupts present in the hardware pins.
• Software Interrupts: These are the instructions used in the program
whenever the required functionality is needed.
• Vectored interrupts: These interrupts are associated with the static vector
address.
• Non-vectored interrupts: These interrupts are associated with the
dynamic vector address.
• Maskable Interrupts: These interrupts can be enabled or disabled
explicitly.
• Non-maskable interrupts: These are always in the enabled state. we
cannot disable them.
• External interrupts: Generated by external devices such as I/O.
Course Name--Operating Systems
Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
• Internal interrupts: These devices are generated by the internal
components of the processor such as power failure, error instruction,
temperature sensor, etc.
• Synchronous interrupts: These interrupts are controlled by the fixed time
interval. All the interval interrupts are called as synchronous interrupts.
• Asynchronous interrupts: These are initiated based on the feedback of
previous instructions. All the external interrupts are called as
asynchronous interrupts.
3. Direct Memory Access: The data transfer between a fast storage media such as
magnetic disk and memory unit is limited by the speed of the CPU. Thus, we can allow
the peripherals directly communicate with each other using the memory buses,
removing the intervention of the CPU. This type of data transfer technique is known as
DMA or direct memory access. During DMA the CPU is idle and it has no control over
the memory buses. The DMA controller takes over the buses to manage the transfer
directly between the I/O devices and the memory unit.
1. Bus grant request time.
2. Transfer the entire block of data at transfer rate of device because the device is
usually slow than the speed at which the data can be transferred to CPU.
3. Release the control of the bus back to CPU So, total time taken to transfer the N
bytes = Bus grant request time + (N) * (memory transfer rate) + Bus release control
time.
4. Buffer the byte into the buffer
5. Inform the CPU that the device has 1 byte to transfer (i.e. bus grant request)
6. Transfer the byte (at system bus speed)
7. Release the control of the bus back to CPU.

Advantages:

Standardization: I/O interfaces provide a standard way of communicating with external


devices. This means that different devices can be connected to a computer using the same
interface, which makes it easier to swap out devices and reduces the need for specialized
hardware.
Modularity: With I/O interfaces, different devices can be added or removed from a
computer without affecting the other components. This makes it easier to upgrade or
replace a faulty device without affecting the rest of the system.
Efficiency: I/O interfaces can transfer data between the computer and the external devices
at high speeds, which allows for faster data transfer and processing times.
Compatibility: I/O interfaces are designed to be compatible with a wide range of devices,
which means that users can choose from a variety of devices that are compatible with their
computer’s I/O interface.

Disadvantages:

Cost: I/O interfaces can be expensive, especially if specialized hardware is required to


connect a particular device to a computer system.
Complexity: Some I/O interfaces can be complex to configure and require specialized
knowledge to set up and maintain. This can be a disadvantage for users who are not

Course Name--Operating Systems


Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
familiar with the technical aspects of computer hardware.
Compatibility issues: While I/O interfaces are designed to be compatible with a wide
range of devices, there can still be compatibility issues with certain devices. In some cases,
device drivers may need to be installed to ensure proper functionality.
Security risks: I/O interfaces can be a security risk if they are not properly configured or
secured. Hackers can exploit vulnerabilities in I/O interfaces to gain unauthorized access to
a computer system or steal data.
Buffering in OS
In Operating Systems I/O operations are one of the most fundamental tasks that is needed to
be carried out correctly and with the utmost efficiency. One of the techniques that we can use
to ensure the utmost efficiency of the I/O Operations is Buffering. So, Buffering is a process
in which the data is stored in a buffer or cache, which makes this stored data more accessible
than the original source. Buffer is an area in memory that is used to hold the data that is being
transmitted from one place to another and store the data temporarily.
There are a number of data storage devices that are used in a system, like Hard Disks, network
devices, pen drives, etc. So, there might be some waiting time faced by the processes or
applications that are attempting to access that data from the storage devices. This problem is
mainly caused when the devices from where device is slow or have low latency.
This problem is significantly solved using Buffering, as in this process the buffer acts as an
intermediate between the storage device and the processes/applications. In this process, the
data is already transferred to the Buffer so the data retrieval can be done from it which
significantly reduces the waiting time and hence improves the performance of the system.
Types of Buffering in OS
There are mainly three types of Buffering that are used in OS:
1. Single Buffering
2. Double Buffering
3. Circular Buffering
I/O buffering and its Various Techniques
A buffer is a memory area that stores data being transferred between two devices or
between a device and an application.
Uses of I/O Buffering :
• Buffering is done to deal effectively with a speed mismatch between the producer and
consumer of the data stream.
• A buffer is produced in main memory to heap up the bytes received from modem.
• After receiving the data in the buffer, the data get transferred to disk from buffer in a
single operation.
• This process of data transfer is not instantaneous, therefore the modem needs another
buffer in order to store additional incoming data.
• When the first buffer got filled, then it is requested to transfer the data to disk.
• The modem then starts filling the additional incoming data in the second buffer while
the data in the first buffer getting transferred to disk.
• When both the buffers completed their tasks, then the modem switches back to the first
buffer while the data from the second buffer get transferred to the disk.
• The use of two buffers disintegrates the producer and the consumer of the data, thus
minimizes the time requirements between them.
• Buffering also provides variations for devices that have different data transfer sizes.

Course Name--Operating Systems


Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
Disk Scheduling Algorithms
Disk scheduling is done by operating systems to schedule I/O requests arriving for the disk.
Disk scheduling is also known as I/O Scheduling.
Importance of Disk Scheduling in Operating System
• 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.
Here, we will cover the following Topics in Disk Scheduling.
• Important Terms Associated with Disk Scheduling
• Disk Scheduling Algorithms
• FCFS (First Come First Serve)
• SSTF (Shortest Seek Time First)
• SCAN (Elevator Algorithm)
• C-SCAN (Circular SCAN)
• LOOK
• C-LOOK

Key Terms Associated with Disk Scheduling


• 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.
Disk Scheduling Algorithms
There are several Disk Several Algorithms. We will discuss each one of them.

Course Name--Operating Systems


Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
FCFS (First Come First Serve)
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:
Suppose the order of request is- (82,170,43,140,24,16,190)
And current position of Read/Write head is: 50

So, total overhead movement (total distance covered by the disk arm) =
(82-50)+(170-82)+(170-43)+(140-43)+(140-24)+(24-16)+(190-16) =642
Advantages of FCFS
Here are some of the advantages of First Come First Serve.
• Every request gets a fair chance
• No indefinite postponement
Disadvantages of FCFS
Here are some of the disadvantages of First Come First Serve.
• Does not try to optimize seek time
• May not provide the best possible service

Course Name--Operating Systems


Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
SSTF (Shortest Seek Time First)
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.

Example:
Suppose the order of request is- (82,170,43,140,24,16,190)
And current position of Read/Write head is: 50

So,
Total overhead movement (total distance covered by the disk arm) =
(50-43)+(43-24)+(24-16)+(82-16)+(140-82)+(170-140)+(190-170) =208
Advantages of Shortest Seek Time First
Here are some of the advantages of Shortest Seek Time First.
• The average Response Time decreases
• Throughput increases
Disadvantages of Shortest Seek Time First
Here are some of the disadvantages of Shortest Seek Time First.
• Overhead to calculate seek time in advance
• Can cause Starvation for a request if it has a higher seek time as compared to incoming
requests
• The high variance of response time as SSTF favors only some requests

Course Name--Operating Systems


Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
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:
Suppose the requests to be addressed are-82,170,43,140,24,16,190. And the Read/Write arm
is at 50, and it is also given that the disk arm should move “towards the larger value”.
Therefore, the total overhead movement (total distance covered by the disk arm) is
calculated as

Therefore, the total overhead movement (total distance covered by the disk arm) is
calculated as

= (199-50) + (199-16) = 332

Advantages of SCAN Algorithm


Here are some of the advantages of the SCAN Algorithm.
• High throughput
• Low variance of response time
• Average response time
Disadvantages of SCAN Algorithm
Here are some of the disadvantages of the SCAN Algorithm.
• Long waiting time for requests for locations just visited by disk arm

Course Name--Operating Systems


Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
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.
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:
Suppose the requests to be addressed are-82,170,43,140,24,16,190. And the Read/Write arm
is at 50, and it is also given that the disk arm should move “towards the larger value”.

So, the total overhead movement (total distance covered by the disk arm) is calculated as:
=(199-50) + (199-0) + (43-0) = 391
Advantages of C-SCAN Algorithm
Here are some of the advantages of C-SCAN.
• Provides more uniform wait time compared to SCAN.

Course Name--Operating Systems


Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
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:

Suppose the requests to be addressed are-82,170,43,140,24,16,190. And the Read/Write


arm is at 50, and it is also given that the disk arm should move “towards the larger
value”.

So, the total overhead movement (total distance covered by the disk arm) is calculated as:
= (190-50) + (190-16) = 314

C-LOOK
As LOOK is similar to the SCAN algorithm, in a similar way, C-LOOK is similar to the
CSCAN disk scheduling algorithm. In CLOOK, the disk arm in spite of going to the end goes
only to the last request to be serviced in front of the head and then from there goes to the
other end’s last request. Thus, it also prevents the extra delay which occurred due to
unnecessary traversal to the end of the disk.
Example:
1. Suppose the requests to be addressed are-82,170,43,140,24,16,190. And the Read/Write
arm is at 50, and it is also given that the disk arm should move “towards the
larger value”

Course Name--Operating Systems


Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
So, the total overhead movement (total distance covered by the disk arm) is calculated as
= (190-50) + (190-16) + (43-16) = 341

Course Name--Operating Systems


Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
File Access Methods in Operating System
When a file is used, information is read and accessed into computer memory and there are
several ways to access this information of the file. Some systems provide only one access
method for files. Other systems, such as those of IBM, support many access methods, and
choosing the right one for a particular application is a major design problem.
There are three ways to access a file into a computer system: Sequential-Access, Direct
Access, Index sequential Method.
1. Sequential Access –
It is the simplest access method. Information in the file is processed in order, one record
after the other. This mode of access is by far the most common; for example, editor and
compiler usually access the file in this fashion.
Read and write make up the bulk of the operation on a file. A read operation -read
next- read the next position of the file and automatically advance a file pointer, which
keeps track I/O location. Similarly, for the -write next- append to the end of the file and
advance to the newly written material.
Key points:
• Data is accessed one record right after another record in an order.
• When we use read command, it move ahead pointer by one
• When we use write command, it will allocate memory and move the pointer to the
end of the file
• Such a method is reasonable for tape.

Advantages of Sequential Access Method :


• It is simple to implement this file access mechanism.
• It uses lexicographic order to quickly access the next entry.
• It is suitable for applications that require access to all records in a file, in a specific
order.
• It is less prone to data corruption as the data is written sequentially and not randomly.
• It is a more efficient method for reading large files, as it only reads the required data
and does not waste time reading unnecessary data.
• It is a reliable method for backup and restore operations, as the data is stored
sequentially and can be easily restored if required.
Disadvantages of Sequential Access Method :
• If the file record that needs to be accessed next is not present next to the current record,
this type of file access method is slow.
• Moving a sizable chunk of the file may be necessary to insert a new record.
• It does not allow for quick access to specific records in the file. The entire file must be
searched sequentially to find a specific record, which can be time-consuming.
• It is not well-suited for applications that require frequent updates or modifications to the
file. Updating or inserting a record in the middle of a large file can be a slow and
cumbersome process.
• Sequential access can also result in wasted storage space if records are of varying
lengths. The space between records cannot be used by other records, which can result in
inefficient use of storage.
2.Direct Access –
Another method is direct access method also known as relative access method. A fixed-
length logical record that allows the program to read and write record rapidly. in no
particular order. The direct access is based on the disk model of a file since disk allows
Course Name--Operating Systems
Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
random access to any file block. For direct access, the file is viewed as a numbered
sequence of block or record. Thus, we may read block 14 then block 59, and then we can
write block 17. There is no restriction on the order of reading and writing for a direct access
file.
A block number provided by the user to the operating system is normally a relative block
number, the first relative block of the file is 0 and then 1 and so on.

Advantages of Direct Access Method :


• The files can be immediately accessed decreasing the average access time.
• In the direct access method, in order to access a block, there is no need of traversing all
the blocks present before it.
3.Index sequential method –
It is the other method of accessing a file that is built on the top of the sequential access
method. These methods construct an index for the file. The index, like an index in the back
of a book, contains the pointer to the various blocks. To find a record in the file, we first
search the index, and then by the help of pointer we access the file directly.
Key points:
• It is built on top of Sequential access.
• It control the pointer by using index.

4.Relative Record Access –


Relative record access is a file access method used in operating systems where records are
accessed relative to the current position of the file pointer. In this method, records are
located based on their position relative to the current record, rather than by a specific
address or key value.
Key Points of Relative Record Access:
Relative record access is a random access method that allows records to be accessed based
on their position relative to the current record.
This method is efficient for accessing individual records but may not be suitable for files
that require frequent updates or random access to specific records.
Relative record access requires fixed-length records and may not be flexible enough for
some applications.
This method is useful for processing records in a specific order or for files that are accessed
sequentially.
Advantages of Relative Record Access:
Random Access: Relative record access allows random access to records in a file. The
system can access any record at a specific offset from the current position of the file
pointer.
Efficient Retrieval: Since the system only needs to read the current record and any records
that need to be skipped, relative record access is more efficient than sequential access for
accessing individual records.
Useful for Sequential Processing: Relative record access is useful for processing records in
a specific order. For example, if the records are sorted in a specific order, the system can
access the next or previous record relative to the current position of the file pointer.

Course Name--Operating Systems


Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
Disadvantages of Relative Record Access:
Fixed Record Length: Relative record access requires fixed-length records. If the records
are of varying length, it may be necessary to use padding to ensure that each record is the
same length.
Limited Flexibility: Relative record access is not very flexible. It is difficult to insert or
delete records in the middle of a file without disrupting the relative positions of other
records.
Limited Application: Relative record access is best suited for files that are accessed
sequentially or with some regularity, but it may not be appropriate for files that are
frequently updated or require random access to specific records.
5.Content Addressable Access-
Content-addressable access (CAA) is a file access method used in operating systems that
allows records or blocks to be accessed based on their content rather than their address. In
this method, a hash function is used to calculate a unique key for each record or block, and
the system can access any record or block by specifying its key.
Keys in Content-Addressable Access:
Unique: Each record or block has a unique key that is generated using a hash function.
Calculated based on content: The key is calculated based on the content of the record or
block, rather than its location or address.
Advantages of Content-Addressable Access:
Efficient Search: CAA is ideal for searching large databases or file systems because it
allows for efficient searching based on the content of the records or blocks.
Flexibility: CAA is more flexible than other access methods because it allows for easy
insertion and deletion of records or blocks.
Data Integrity: CAA ensures data integrity because each record or block has a unique key
that is generated based on its content.
Disadvantages of Content-Addressable Access:
Overhead: CAA requires additional overhead because the hash function must be calculated
for each record or block.
Collision: There is a possibility of collision where two records or blocks can have the same
key. This can be minimized by using a good hash function, but it cannot be completely
eliminated.
Limited Key Space: The key space is limited by the size of the hash function used, which
can lead to collisions and other issues.
Key Points of Content-Addressable Access:
Content-addressable access is a file access method that allows records or blocks to be
accessed based on their content rather than their address.
CAA uses a hash function to generate a unique key for each record or block.
CAA is efficient for searching large databases or file systems and is more flexible than
other access methods.
CAA requires additional overhead for calculating the hash function and may have collisions
or limited key space.
Course Name--Operating Systems
Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
Structures of Directory in Operating System
A directory is a container that is used to contain folders and files. It organizes files and
folders in a hierarchical
manner.

Following are the logical structures of a directory, each providing a solution to the problem
faced in previous type of directory structure.
1) Single-level directory:

The single-level directory is the simplest directory structure. In it, all files are contained
in the same directory which makes it easy to support and understand.
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:
• Since it is a single directory, so its implementation is very easy.
• If the files are smaller in size, searching will become faster.
• The operations like file creation, searching, deletion, updating are very easy in such a
directory structure.
• Logical Organization: Directory structures help to logically organize files and
directories in a hierarchical structure. This provides an easy way to navigate and
manage files, making it easier for users to access the data they need.

Course Name--Operating Systems


Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
• Increased Efficiency: Directory structures can increase the efficiency of the file system
by reducing the time required to search for files. This is because directory structures are
optimized for fast file access, allowing users to quickly locate the file they need.
• Improved Security: Directory structures can provide better security for files by
allowing access to be restricted at the directory level. This helps to prevent
unauthorized access to sensitive data and ensures that important files are protected.
• Facilitates Backup and Recovery: Directory structures make it easier to backup and
recover files in the event of a system failure or data loss. By storing related files in the
same directory, it is easier to locate and backup all the files that need to be protected.
• Scalability: Directory structures are scalable, making it easy to add new directories and
files as needed. This helps to accommodate growth in the system and makes it easier to
manage large amounts of data.
Disadvantages:
• There may chance of name collision because two files can have the same name.
• Searching will become time taking if the directory is large.
• This can not group the same type of files together.

2) Two-level directory:
As we have seen, a single level directory often leads to confusion of files names among
different users. The solution to this problem is to create a separate directory for each
user.
In the two-level directory structure, each user has their own user files directory
(UFD). The UFDs have similar structures, but each lists only the files of a single user.
System’s master file directory (MFD) is searched whenever a new user id is created.

Advantages:
• The main advantage is there can be more than two files with same name, and would be
very helpful if there are multiple users.
• A security would be there which would prevent user to access other user’s files.
• Searching of the files becomes very easy in this directory structure.

Course Name--Operating Systems


Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
Disadvantages:
• As there is advantage of security, there is also disadvantage that the user cannot share
the file with the other users.
• Unlike the advantage users can create their own files, users don’t have the ability to
create subdirectories.
• Scalability is not possible because one use can’t group the same types of files together.
3) Tree Structure/ Hierarchical Structure:
Tree directory structure of operating system is most commonly used in our personal
computers. User can create files and subdirectories too, which was a disadvantage in the
previous directory structures.
This directory structure resembles a real tree upside down, where the root directory is at
the peak. This root contains all the directories for each user. The users can create
subdirectories and even store files in their directory.
A user do not have access to the root directory data and cannot modify it. And, even in this
directory the user do not have access to other user’s directories. The structure of tree
directory is given below which shows how there are files and subdirectories in each user’s
directory.

Advantages:
• This directory structure allows subdirectories inside a directory.
• The searching is easier.
• File sorting of important and unimportant becomes easier.
• This directory is more scalable than the other two directory structures explained.
Disadvantages:
• As the user isn’t allowed to access other user’s directory, this prevents the file sharing
among users.
• As the user has the capability to make subdirectories, if the number of subdirectories
increase the searching may become complicated.
• Users cannot modify the root directory data.
• If files do not fit in one, they might have to be fit into other directories.

Course Name--Operating Systems


Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
4) Acyclic Graph Structure:
As we have seen the above three directory structures, where none of them have the
capability to access one file from multiple directories. The file or the subdirectory could be
accessed through the directory it was present in, but not from the other directory.
This problem is solved in acyclic graph directory structure, where a file in one directory can
be accessed from multiple directories. In this way, the files could be shared in between the
users. It is designed in a way that multiple directories point to a particular directory or file
with the help of links.
In the below figure, this explanation can be nicely observed, where a file is shared between
multiple users. If any user makes a change, it would be reflected to both the users.

Acyclic Graph Structure

Advantages:
• Sharing of files and directories is allowed between multiple users.
• Searching becomes too easy.
• Flexibility is increased as file sharing and editing access is there for multiple users.
Disadvantages:
• Because of the complex structure it has, it is difficult to implement this directory
structure.
• The user must be very cautious to edit or even deletion of file as the file is accessed by
multiple users.
• If we need to delete the file, then we need to delete all the references of the file inorder
to delete it permanently.

Course Name--Operating Systems


Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
File System Implementation
A file is a collection of related information. The file system resides on secondary storage and
provides efficient and convenient access to the disk by allowing data to be stored, located,
and retrieved.
File system implementation in an operating system refers to how the file system manages the
storage and retrieval of data on a physical storage device such as a hard drive, solid-state
drive, or flash drive. The file system implementation includes several components, including:
1. 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.
2. 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.
3. 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.
4. 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.
5. 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.
1.
I/O Control level – Device drivers act as an interface between devices and OS, they help
to transfer data between disk and main memory. It takes block number as input and as
output, it gives low-level hardware-specific instruction.
2. Basic file system – It Issues general commands to the device driver to read and write
physical blocks on disk. It manages the memory buffers and caches. A block in the buffer
can hold the contents of the disk block and the cache stores frequently used file system
metadata.
3. File organization Module – It has information about files, the location of files and
their logical and physical blocks. Physical blocks do not match with logical numbers of
logical blocks numbered from 0 to N. It also has a free space that tracks unallocated
blocks.
4. Logical file system – It manages metadata information about a file i.e includes all
details about a file except the actual contents of the file. It also maintains via file control
blocks. File control block (FCB) has information about a file – owner, size, permissions,
and location of file contents.
Advantages
1. Duplication of code is minimized.
2. Each file system can have its own logical file system.
3. File system implementation in an operating system provides several advantages,
including:
4. Efficient Data Storage: File system implementation ensures efficient data storage on a
physical storage device. It provides a structured way of organizing files and directories,
which makes it easy to find and access files.
5. Data Security: File system implementation includes features for managing file security
and permissions. This ensures that sensitive data is protected from unauthorized access.
Course Name--Operating Systems
Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
6. Data Recovery: The file system implementation includes features for recovering from
system failures and maintaining data integrity. This helps to prevent data loss and ensures
that data can be recovered in the event of a system failure.
7. Improved Performance: File system implementation includes techniques such as
buffering and caching to optimize file I/O performance. This results in faster access to
data and improved overall system performance.
8. Scalability: File system implementation can be designed to be scalable, making it
possible to store and retrieve large amounts of data efficiently.
9. Flexibility: Different file system implementations can be designed to meet specific
needs and use cases. This allows developers to choose the best file system implementation
for their specific requirements.
10. Cross-Platform Compatibility: Many file system implementations are cross-platform
compatible, which means they can be used on different operating systems. This makes it
easy to transfer files between different systems.
In summary, file system implementation in an operating system provides several advantages,
including efficient data storage, data security, data recovery, improved performance,
scalability, flexibility, and cross-platform compatibility. These advantages make file system
implementation a critical aspect of any operating system.
Disadvantages
If we access many files at the same time then it results in low performance. We
can implement a file system by using two types of data structures :
1. Boot Control Block – It is usually the first block of volume and it contains information
needed to boot an operating system. In UNIX it is called the boot block and in NTFS it is
called the partition boot sector.
2. Volume Control Block – It has information about a particular partition ex:- free block
count, block size and block pointers, etc. In UNIX it is called superblock and in NTFS it
is stored in the master file table.
3. Directory Structure – They store file names and associated inode numbers. In UNIX,
includes file names and associated file names and in NTFS, it is stored in the master file
table.
4. Per-File FCB – It contains details about files and it has a unique identifier number to
allow association with the directory entry. In NTFS it is stored in the master file table.
5. Mount Table – It contains information about each mounted volume.
6. Directory-Structure cache – This cache holds the directory information of recently
accessed directories.
7. System-wide open-file table – It contains the copy of the FCB of each open file.
8. Per-process open-file table – It contains information opened by that particular process
and it maps with the appropriate system-wide open-file.
9. Linear List – It maintains a linear list of filenames with pointers to the data blocks. It is
time-consuming also. To create a new file, we must first search the directory to be sure
that no existing file has the same name then we add a file at the end of the directory. To
delete a file, we search the directory for the named file and release the space. To reuse
the directory entry either we can mark the entry as unused or we can attach it to a list of
free directories.
10. Hash Table – The hash table takes a value computed from the file name and returns a
pointer to the file. It decreases the directory search time. The insertion and deletion
process of files is easy. The major difficulty is hash tables are its generally fixed size and
hash tables are dependent on the hash function of that size.

Course Name--Operating Systems


Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
Key Steps Involved In File System Implementation

File system implementation is a crucial component of an operating system, as it provides an


interface between the user and the physical storage device. Here are the key steps involved
in file system implementation:
1. Partitioning the storage device: The first step in file system implementation is to
partition the physical storage device into one or more logical partitions. Each partition is
formatted with a specific file system that defines the way files and directories are
organized and stored.
2. File system structures: File system structures are the data structures used by the
operating system to manage files and directories. Some of the key file system structures
include the superblock, inode table, directory structure, and file allocation table.
3. Allocation of storage space: The file system must allocate storage space for each file
and directory on the storage device. There are several methods for allocating storage
space, including contiguous, linked, and indexed allocation.
4. File operations: The file system provides a set of operations that can be performed on
files and directories, including create, delete, read, write, open, close, and seek. These
operations are implemented using the file system structures and the storage allocation
methods.
5. File system security: The file system must provide security mechanisms to protect files
and directories from unauthorized access or modification. This can be done by setting file
permissions, access control lists, or encryption.
6. File system maintenance: The file system must be maintained to ensure efficient and
reliable operation. This includes tasks such as disk defragmentation, disk checking, and
backup and recovery.
Overall, file system implementation is a complex and critical component of an operating
system. The efficiency and reliability of the file system have a significant impact on the
performance and stability of the entire system.

File Allocation Methods


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.
All the three methods have their own advantages and disadvantages as discussed below:
Course Name--Operating Systems
Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
1. Contiguous Allocation
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
• 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:
• This method suffers from both internal and external fragmentation. This makes it
inefficient in terms of memory utilization.
• Increasing file size is difficult because it depends on the availability of contiguous
memory at a particular instance.

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.

Course Name--Operating Systems


Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
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. 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.
Disadvantages:
• The pointer overhead for indexed allocation is greater than linked allocation.
• For very small files, say files that expand only 2-3 blocks, the indexed allocation would
keep one entire block (index block) for the pointers which is inefficient in terms of
memory utilization. However, in linked allocation we lose the space of only 1 pointer
per block.

Course Name--Operating Systems


Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
Free space management
Free space management is a critical aspect of operating systems as it involves
managing the available storage space on the hard disk or other secondary storage devices.
The operating system uses various techniques to manage free space and optimize the use of
storage devices. Here are some of the commonly used free space management techniques:
1. Linked Allocation: In this technique, each file is represented by a linked list of disk
blocks. When a file is created, the operating system finds enough free space on the disk
and links the blocks of the file to form a chain. This method is simple to implement but
can lead to fragmentation and wastage of space.
2. Contiguous Allocation: In this technique, each file is stored as a contiguous block of
disk space. When a file is created, the operating system finds a contiguous block of free
space and assigns it to the file. This method is efficient as it minimizes fragmentation
but suffers from the problem of external fragmentation.
3. Indexed Allocation: In this technique, a separate index block is used to store the
addresses of all the disk blocks that make up a file. When a file is created, the operating
system creates an index block and stores the addresses of all the blocks in the file. This
method is efficient in terms of storage space and minimizes fragmentation.
4. File Allocation Table (FAT): In this technique, the operating system uses a file
allocation table to keep track of the location of each file on the disk. When a file is
created, the operating system updates the file allocation table with the address of the
disk blocks that make up the file. This method is widely used in Microsoft Windows
operating systems.
Overall, free space management is a crucial function of operating systems, as it ensures that
storage devices are utilized efficiently and effectively.
The system keeps tracks of the free disk blocks for allocating space to files when they are
created. Also, to reuse the space released from deleting the files, free space management
becomes crucial. The system maintains a free space list which keeps track of the disk
blocks that are not allocated to some file or directory. The free space list can be
implemented mainly as:
1. Bitmap or Bit vector – A Bitmap or Bit Vector is series or collection of bits where
each bit corresponds to a disk block. The bit can take two values: 0 and 1: 0 indicates
that the block is allocated and 1 indicates a free block.
Advantages –
• Simple to understand.
• Finding the first free block is efficient. It requires scanning the words (a group of 8 bits)
in a bitmap for a non-zero word. (A 0-valued word has all bits 0). The first free block is
then found by scanning for the first 1 bit in the non-zero word.
1. Linked List – In this approach, the free disk blocks are linked together i.e. a free block
contains a pointer to the next free block. The block number of the very first disk block
is stored at a separate location on disk and is also cached in memory. Grouping – This
approach stores the address of the free blocks in the first free block. The first free block
stores the address of some, say n free blocks. Out of these n blocks, the first n-1 blocks
are actually free and the last block contains the address of next free n blocks.
An advantage of this approach is that the addresses of a group of free disk blocks can
be found easily.
1. Counting – This approach stores the address of the first free disk block and a number n
of free contiguous disk blocks that follow the first block. Every entry in the list would
contain:
Course Name--Operating Systems
Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--
1. Address of first free disk block
2. A number n

Here are some advantages and disadvantages of free space management techniques in
operating systems:

Advantages:

1. Efficient use of storage space: Free space management techniques help to optimize the
use of storage space on the hard disk or other secondary storage devices.
2. Easy to implement: Some techniques, such as linked allocation, are simple to implement
and require less overhead in terms of processing and memory resources.
3. Faster access to files: Techniques such as contiguous allocation can help to reduce disk
fragmentation and improve access time to files.

Disadvantages:

1. Fragmentation: Techniques such as linked allocation can lead to fragmentation of disk


space, which can decrease the efficiency of storage devices.
2. Overhead: Some techniques, such as indexed allocation, require additional overhead in
terms of memory and processing resources to maintain index blocks.
3. Limited scalability: Some techniques, such as FAT, have limited scalability in terms of
the number of files that can be stored on the disk.
4. Risk of data loss: In some cases, such as with contiguous allocation, if a file becomes
corrupted or damaged, it may be difficult to recover the data.
5. Overall, the choice of free space management technique depends on the specific
requirements of the operating system and the storage devices being used. While some
techniques may offer advantages in terms of efficiency and speed, they may also have
limitations and drawbacks that need to be considered.

Course Name--Operating Systems


Unit 5: FILE AND I/O Management Semester III
Course Code COMPUTER--

You might also like