Understanding I/O Devices and DMA
Understanding I/O Devices and DMA
🔹 Input Devices
🔹 Output Devices
Device Controllers
Device drivers are software modules that can be plugged into an OS to handle a
particular device. Operating System takes help from device drivers to handle all
I/O devices.
The Device Controller works like an interface between a device and a device
driver. I/O units (Keyboard, mouse, printer, etc.) typically consist of a
mechanical component and an electronic component where electronic
component is called the device controller.
There is always a device controller and a device driver for each device to
communicate with the Operating Systems. A device controller may be able to
handle multiple devices. As an interface its main task is to convert serial bit
stream to block of bytes, perform error correction as necessary.
Any device connected to the computer is connected by a plug and socket, and
the socket is connected to a device controller. Following is a model for
connecting the CPU, memory, controllers, and I/O devices where CPU and
device controllers all use a common bus for communication.
The CPU must have a way to pass information to and from an I/O device. There
are three approaches available to communicate with the CPU and Device.
This uses CPU instructions that are specifically made for controlling I/O
devices. These instructions typically allow data to be sent to an I/O device or
read from an I/O device.
Memory-mapped I/O
When using memory-mapped I/O, the same address space is shared by memory
and I/O devices. The device is connected directly to certain main memory
locations so that I/O device can transfer block of data to/from memory without
going through CPU.
While using memory mapped IO, OS allocates buffer in memory and informs
I/O device to use that buffer to send data to the CPU. I/O device operates
asynchronously with CPU, interrupts CPU when finished.
The advantage to this method is that every instruction which can access memory
can be used to manipulate an I/O device. Memory mapped IO is used for most
high-speed I/O devices like disks, communication interfaces.
Types of Interrupt
2. Hardware Interrupts
In a hardware interrupt, all the devices are connected to the Interrupt Request
Line. A single request line is used for all the n devices. To request an interrupt,
a device closes its associated switch. When a device requests an interrupt, the
value of INTR is the logical OR of the requests from individual devices.
Hardware interrupts are further divided into two types of interrupt
Maskable Interrupt: Hardware interrupts can be selectively enabled
and disabled thanks to an inbuilt interrupt mask register that is
commonly found in processors. A bit in the mask register
corresponds to each interrupt signal; on some systems, the interrupt
is enabled when the bit is set and disabled when the bit is clear, but
on other systems, the interrupt is deactivated when the bit is set.
Spurious Interrupt: A hardware interrupt for which there is no
source is known as a spurious interrupt. This phenomenon might also
be referred to as phantom or ghost interrupts. When a wired-OR
interrupt circuit is connected to a level-sensitive processor input,
spurious interruptions are typically an issue. When a system performs
badly, it could be challenging to locate these interruptions.
Sequences of Events Involved in Handling an IRQ(Interrupt Request)
Devices raise an IRQ.
The processor interrupts the program currently being executed.
The device is informed that its request has been recognized and the
device deactivates the request signal.
The requested action is performed.
An interrupt is enabled and the interrupted program is resumed.
Benefits of Interrupt
Real-time Responsiveness: Interrupts permit a system to reply
promptly to outside events or signals, permitting real-time
processing.
Efficient Resource usage: Interrupt-driven structures are more
efficient than system that depend on busy-waiting or polling
strategies. Instead of continuously checking for the incidence of
event, interrupts permit the processor to remain idle until an event
occurs, conserving processing energy and lowering energy intake.
Multitasking and Concurrency: Interrupts allow multitasking with
the aid of allowing a processor to address multiple tasks
concurrently.
Improved system Throughput: By coping with occasions
asynchronously, interrupts allow a device to overlap computation
with I/O operations or other responsibilities, maximizing system
throughput and universal overall performance.
# Device Driver
Device Drivers are essential for a computer system to work properly because
without a device driver the particular hardware fails to work accordingly, which
means it fails in doing the function/action it was created to do. Most use the
term Driver, but some may say Hardware Driver, which also refers to
the Device Driver.
Device Drivers depend upon the Operating System’s instruction to access the
device and perform any particular action. After the action, they also show their
reactions by delivering output or status/message from the hardware device to
the Operating system. For example, a printer driver tells the printer in which
format to print after getting instruction from OS, similarly, A sound card driver
is there due to which 1’s and 0’s data of the MP3 file is converted to audio
signals and you enjoy the music. Card reader, controller, modem, network card,
sound card, printer, video card, USB devices, RAM, Speakers, etc need Device
Drivers to operate.
The following figure illustrates the interaction between the user, OS, Device
driver, and the devices:
This Kernel-mode device driver includes some generic hardware that loads with
the operating system as part of the OS these are BIOS, motherboard, processor,
and some other hardware that are part of kernel software. These include the
minimum system requirement device drivers for each operating system.
These essential building blocks of personal and enterprise computing are used
in the following ways:
1. Device drivers for accessing storage systems
Computer storage systems allow users to store data and make it available on
demand. They include external and internal devices such as USB flash drives,
hard drives, and network-attached storage. Drivers in storage systems enable
them to interact with the computer. This ensures that the computer can access its
internal or external storage systems, query their information, and allow data
transfer.
Connecting storage devices to the computer without drivers becomes difficult as
the OS does not detect them. Usually, hard disks and CD-ROMs are recognized
by the OS and do not require drivers to be manually installed. Users must install
drivers from the manufacturer’s website if they are not automatically detected.
2. Device drivers for input and output devices
The computer’s OS interacts with device drivers to ensure its hardware
functions as expected. Input devices include mice and keyboards, while output
devices include display devices such as monitors. Keyboards, mice, and
monitors are categorized as plug-and-play devices.
Usually, the drivers for plug-and-play devices are generic and do not require
manual installation, as the computer’s OS recognizes them and installs them
automatically. However, if an external device is not a plug-and-play device,
users may need to manually install the drivers from the installation disc or
download them. This will enable the OS to recognize these devices.
3. Device drivers for digital cameras
A digital camera driver is a program that allows communication between it and
other devices, such as computers. Without the drivers, the OS will not detect
this device. Most digital cameras are only compatible with the Windows OS,
as Linux systems lag.
Digital camera drivers allow for the transfer of photos from the camera to the
computer. They enable digital cameras to print photos using the PictBridge
standard directly to a PictBridge-capable computer printer without needing a
computer. Drivers in the video output port allow users to display pictures on
television by selecting one video or photo at a time.
4. Drivers for mobile operating systems like Android
Mobile phones have drivers to enable them to communicate with computers.
Drivers come bundled with the firmware on most phones, which allows
computers to load them up to support hardware as the OS is not specified.
However, sometimes users may need to install OEM PC software first for
drivers to be installed and allow data transfer.
Drivers allow for the integration of peripheral devices such as game controllers
or keyboards based on operating systems such as Android Things and Android.
The drivers enable access and control of the hardware. Additionally, they allow
smart devices to work with custom applications.
5. Device drivers for superior video performance
Graphic cards are core components of a computer system and are responsible
for superior video performance in computers, games, or other graphic-intensive
tasks. Graphic drivers allow graphic cards to interact with the computer’s
operating system and are thus essential to getting top performance from the
graphic cards.
Updating graphic drivers and other Windows 11 (or older) drivers can give
users a speed boost, fix problems, and sometimes even provide users with new
features. For instance, updating game drivers can increase frames per second,
reducing lag.
Device-Independent I/O Software in Operating System
In this article, we will try to understand as well as cover all the Goals of
Input/output (I/O) software.
I/O Software is used for interaction with I/O devices like mouse, keyboards,
USB devices, printers, etc. Several commands are made via external available
devices which makes the OS function upon each of them one by one.
I/O software is organized in the following ways:
User Level Libraries– Provides a simple interface to program for input-output
functions.
Kernel Level Modules– Provides device driver to interact with the device-
independent I/O modules and device controller.
Hardware-A layer including hardware controller and actual hardware which
interact with device drivers.
Let us now see all the goals of I/O software in the below illustrated section one
after the another:
Goals Of I/O Software
In this section, we will talk about all the goals of I/O software one after the
another which are illustrated below:
1. Uniform naming: For example naming of file systems in Operating Systems
is done in a way that the user does not have to be aware of the underlying
hardware name.
2. Synchronous versus Asynchronous: When the CPU is working on some
process it goes into the block state when the interrupt occurs. Therefore most of
the devices are asynchronous. And if the I/O operation is in a blocking state it is
much easier to write the I/O operation. It is always the operating system’s
responsibility to create such an interrupt-driven user program.
3. Device Independence: The most important part of I/O software is device
independence. It is always preferable to write a program that can open all other
I/O devices. For example, it is not necessary to write the input-taking program
again and again for taking input from various files and devices. As this creates
much work to do and also much space to store the different programs.
4. Buffering: Data that we enter into a system cannot be stored directly in
memory. For example, the data is converted into smaller groups and then
transferred to the outer buffer for examination. Buffer has a major impact on I/O
software as it is the one that ultimately helps store the data and copy data. Many
devices have constraints and just to avoid it some data is always put into the
buffer in advance so the buffer rate of getting filled with data and getting empty
remains balanced.
5. Error handling: Errors and mostly generated by the controller and also they
are mostly handled by the controller itself. When the lower level solves the
problem it does not reach the upper level.
6. Shareable and Non-Shareable Devices: Devices like Hard Disk can be
shared among multiple processes while devices like Printers cannot be shared.
The goal of I/O software is to handle both types of devices.
7. Caching: Caching is the process in which all the most accessible and most
used data is kept in a separate memory (known as Cache memory) for access by
creating a copy of the originally available data. The reason for implementing
this Caching process is just to increase the speed of accessing the data since
accessing the Cached copy of data is more efficient as compared to accessing
the original data.
A hard disk is a secondary storage that stores a large amount of data. The hard
disk drive contains dozens of disks. These disks are also known as platters.
These platters are mounted over the spindle, which rotates in any direction, i.e.,
clockwise or anti-clockwise. Let’s look at the hard disk structure in OS.
Platter in Disk
The manufacturer constructs the Platter from aluminum or iron oxide. The
platter diameter range is 1.8 inches to 5.25 inches.
One surface of the Platter requires one Read/Write head, and a second
R/W head is used for the other surface to store information.
Every Platter holds the same no of tracks.
Multiple platters increase the storage capacity.
Sectors
We further divide tracks into several small units, and these units are known as
sectors.
R/W Head
R/W Heads move forth and back over the Platter surfaces to Read or Write the
data on sectors. Read/Write heads do not touch the platter surface.
Cylinder
All Corresponding tracks with the same radius of all platters in the Hard disk
are known as cylinders. In simple words, we say
“Each track of all platters with the same radius is called a cylinder”.
So, the number of tracks on the Platter always equals the number of cylinders.
For example, in a hard disk, where each Platter contains 600 tracks, the number
of cylinders will also be 600 in the hard disk.
Cluster
As we know, there are several platters in the hard disk. Each Platter contains
two R/W heads. There are several cylinders/tracks in the hard disk. Each track
is divided into multiple sectors. Each sector has some size, but most sectors are
512 Bytes.
Hard disk Capacity = Number of Platters × Tracks per Platter × Sectors per
Track × Bytes per Sector
Some of the common storage capacities for Hard Disk Drives (HDDs) include
500GB, 1TB, 2TB, and 4TB.
A computer file is defined as a medium used for saving and managing data in
the computer system. The data stored in the computer system is completely in
digital format, although there can be various types of files that help us to store
the data.
File systems are a crucial part of any operating system, providing a structured
way to store, organize, and manage data on storage devices such as hard drives,
SSDs, and USB drives. Essentially, a file system acts as a bridge between the
operating system and the physical storage hardware, allowing users and
applications to create, read, update, and delete files in an organized and efficient
manner.
What is a File System?
A file system is a method an operating system uses to store, organize, and
manage files and directories on a storage device. Some common types of file
systems include:
FAT (File Allocation Table): An older file system used by older
versions of Windows and other operating systems.
NTFS (New Technology File System): A modern file system used by
Windows. It supports features such as file and folder permissions,
compression, and encryption.
ext (Extended File System): A file system commonly used
on Linux and Unix-based operating systems.
HFS (Hierarchical File System): A file system used by macOS.
APFS (Apple File System): A new file system introduced by Apple
for their Macs and iOS devices.
A file is a collection of related information that is recorded on secondary
storage. Or file is a collection of logically related entities. From the user’s
perspective, a file is the smallest allotment of logical secondary storage.
The name of the file is divided into two parts as shown below:
Name
Extension, separated by a period.
Issues Handled By File System
We’ve seen a variety of data structures where the file could be kept. The file
system’s job is to keep the files organized in the best way possible.
A free space is created on the hard drive whenever a file is deleted from it. To
reallocate them to other files, many of these spaces may need to be recovered.
Choosing where to store the files on the hard disc is the main issue with files
one block may or may not be used to store a file. It may be kept in the disk’s
non-contiguous blocks. We must keep track of all the blocks where the files are
partially located.
Files Attributes And Their Operations
File Types and Their Content
File Directories
The collection of files is a file directory. The directory contains information
about the files, including attributes, location, and ownership. Much of this
information, especially that is concerned with storage, is managed by the
operating system. The directory is itself a file, accessible by various file
management routines.
Below are information contained in a device directory.
Name
Type
Address
Current length
Maximum length
Date last accessed
Date last updated
Owner id
Protection information
The operation performed on the directory are:
Search for a file
Create a file
Delete a file
List a directory
Rename a file
Traverse the file system
Advantages of Maintaining Directories
Efficiency: A file can be located more quickly.
Naming: It becomes convenient for users as two users can have same
name for different files or may have different name for same file.
Grouping: Logical grouping of files can be done by properties e.g. all
java programs, all games etc.
Single-Level Directory
In this, a single directory is maintained for all the users.
Naming Problem: Users cannot have the same name for two files.
Grouping Problem: Users cannot group files according to their
needs.
Two-Level Directory
In this separate directories for each user is maintained.
Path Name: Due to two levels there is a path name for every file to
locate that file.
Now, we can have the same file name for different users.
Searching is efficient in this method.
Tree-Structured Directory
The directory is maintained in the form of a tree. Searching is efficient and also
there is grouping capability. We have absolute or relative path name for a file.
Read files: The OS needs a read pointer to read a file from a specific
location in the file.
To read files through command line, we use the type command. For huge
files, we use the more command to read files one page at a time.
Write files: The system call uses the same pointers to write a file, it helps
to save space and reduce complexity.
Create files: The user should have enough space to create a file. When a
file is created, a directory entry is made.
To create files through command line, the syntax is type nul > (filename).
(filetype)
Delete files: The user can look up the file name and delete it. It will
release the space occupied by the file and remove the directory entries for
the file.
The del command is used when we want to delete a file through command
line.
Truncate files: The user can delete information from the file, instead of
deleting it as a whole. This changes the file length, though the other
attributes remain the same.
Repositioning files: The current file-position pointer can be repositioned
to a new given value.
There are also other file operations like appending a file, creating a
duplicate of the file, and renaming a file.
OS File System Architecture
An operating system (OS) is software that manages computer hardware and
software resources and provides related services to computers. It acts as an
intermediary between applications and computer hardware.
What is a Document System?
A file system is a method that helps in organizing and managing data on
different storage devices, such as a hard drive or pen drive. File systems also
provide efficient access to users where they can enable disks for easy data
storage, location, and recovery. Most operating systems use a layer for each
task, including file systems. Each layer of the archive system is responsible for
specific functions.
File-System Structure
File Structure
- Logical storage unit
- Collection of related Information
File System in the storage unit
The file system is organized into layers
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
system data structure such as Directory structure, file allocation table,
and inodes. To Provide efficient and convenient access to the files on the disk,
OS imposes one or more file Systems to allow the data to be stored, located,
and retrieved easily.
Layered File System
The image describes how the file system is divided into different layers and
also the functionality of each layer. When an application requests information,
the first request is sent to the information source, which contains metadata for
the data and structure. The hard drive is divided into many parts and sectors,
and the installation file module determines which physical block the
application needs. The overall data is divided into several logical blocks. Data
is stored on and retrieved from the hard drive. The hard drive is divided into
many parts and sectors and is also responsible for managing free space.
When the installation file module determines which physical block the
application needs, it passes this information to the underlying file. The main
file is responsible for issuing commands to the I/O controller to retrieve these
blocks. The I/O control has access rights to the hard disk. These numbers are
called drivers. I/O management is also responsible for interrupts. Unix uses the
Unix File System (UFS). Windows series supports FAT, FAT32 and N-TFS.
FAT ( File Allocation Table )
File Allocation Table is a file created by Microsoft to support small disks and
simple formats. The file system, called a partition table, uses a table to keep
track of the volume's heaps. FAT is used to overcome the shortcomings of
mounting partition names and has slightly faster access.
FAT The system creates an index table for data stored on the device or system.
The index table contains the entry data (data stored in the local area)
for each data.
The operating system searches for the group number of each
extension of the file until it reaches the end.
It supports a maximum volume of 4 GB.
Inode
Inode is a file structure in the UNIX operating system that contains important
information about the files in the file. When a file system is created in UNIX,
a certain number of indos are also created. Usually about 1% of the file
system's disk space is allocated to the inode table.
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:
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
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.
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.
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:
1. Linked scheme: This scheme links two or more index blocks
together for holding the pointers. Every index block would then
contain a pointer or the address to the next index block.
2. Multilevel index: In this policy, a first level index block is used to
point to the second level index blocks which inturn points to the disk
blocks occupied by the file. This can be extended to 3 or more levels
depending on the maximum file size.
3. Combined Scheme: In this scheme, a special block called the Inode
(information Node) contains all the information about the file such
as the name, size, authority, etc and the remaining space of Inode is
used to store the Disk Block addresses which contain the actual
file as shown in the image below. The first few of these pointers in
Inode point to the direct blocks i.e the pointers contain the addresses
of the disk blocks that contain data of the file. The next few pointers
point to indirect blocks. Indirect blocks may be single indirect,
double indirect or triple indirect. Single Indirect block is the disk
block that does not contain the file data but the disk address of the
blocks that contain the file data. Similarly, double indirect
blocks do not contain the file data but the disk address of the blocks
that contain the address of the blocks containing the file data.
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.
Disadvantages:
For finding a free block, Operating System needs to iterate all the
blocks which is time consuming.
The efficiency of this method reduces as the disk size increases.
2. 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.
In Figure-2, the free space list head points to Block 5 which points to Block 6,
the next free block and so on. The last free block would contain a null pointer
indicating the end of free list. A drawback of this method is the I/O required for
free space list traversal.
Advantages:
The total available space is used efficiently using this method.
Dynamic allocation in Linked List is easy, thus can add the space as
per the requirement dynamically.
Disadvantages:
When the size of Linked List increases, the headache of miniating
pointers is also increases.
This method is not efficient during iteration of each block of 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.
Advantage:
Finding free blocks in massive amount can be done easily using this
method.
Disadvantage:
The only disadvantage is, we need to alter the entire list, if any of the
block of the list is occupied.
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:
Address of first free disk block.
A number n.
Advantages:
Using this method, a group of entire free blocks can take place easily
and Fastly.
The list formed in this method is especially smaller in size.
Disadvantage:
The first free block in this method, keeps account of other free blocks.
Thus, due to that one block the space requirement is more.
Advantages of Free Space Management Techniques
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.
Easy to Implement: Some techniques, such as linked allocation, are
simple to implement and require less overhead in terms of processing
and memory resources.
Faster Access to Files: Techniques such as contiguous allocation can
help to reduce disk fragmentation and improve access time to files.
Disadvantages of Free Space Management Techniques
Fragmentation: Techniques such as linked allocation can lead to
fragmentation of disk space, which can decrease the efficiency of
storage devices.
Overhead: Some techniques, such as indexed allocation, require
additional overhead in terms of memory and processing resources to
maintain index blocks.
Limited scalability: Some techniques, such as FAT, have limited
scalability in terms of the number of files that can be stored on the
disk.
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.
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.
Directory Implementation in Operating System – Using Linear List & Hash
Table
There are many ways to implement a directory in the operating system.
Implementation of a directory structure involves a selection of efficient and
reliable directory allocation and management algorithm from the available
algorithms that enhances the performance of the system. There are mainly two
algorithms for implementing directory, by using Linear List and Hash table.
Linear List :
This is the simplest of all directory implementation methods. It is easy to
implement, but it takes a lot of time to execute. It simply maintains a sequential
list of file names pointing to their corresponding data blocks.
Hash Table :
In this technique, a hash table is used with the linear list for storing directory
entries. The hash table makes use of a hash function that takes an input value
based on the filename and produces an output as a reference to the
corresponding directory entry in the linear list.
Therefore, all file operations consume very less time to execute. However
necessary arrangements should be made to handle collisions. A collision is a
situation where more than one filename is hashed to the same location.
Disadvantages of this technique are that a hash table is usually of fixed size and
the performance of the hash functions is also dependent on the size of the hash
table. Therefore, whenever a new file is to be added after all the available free
entries have been used. The hash table should be expanded to accommodate the
addition of new files and the existing directory entries should be organized in
such a way that the new hash function also maps input values to their
corresponding directory entries.
OR
Directory Implementation in Operating System
Directory implementation in the operating system can be done using Singly
Linked List and Hash table. The efficiency, reliability, and performance of a
file system are greatly affected by the selection of directory-allocation and
directory-management algorithms. There are numerous ways in which the
directories can be implemented. But we need to choose an appropriate
directory implementation algorithm that enhances the performance of the
system.
Linked file allocation offers flexibility by allowing non-contiguous storage blocks, reducing external fragmentation and facilitating file size expansion as needed by adding free blocks to an existing chain. However, this method introduces overhead due to pointers in each block and supports only sequential access. In contrast, indexed allocation provides a single-level index for each file, supporting both sequential and direct access, improving performance but at the cost of potentially higher space for maintaining index tables, which can impact overall disk space efficiency .
Device drivers are crucial for the interaction between hardware components and operating systems as they translate OS instructions into device-specific actions. Without these drivers, hardware would be unable to communicate effectively with the system, leading to malfunction or inability to perform desired tasks, such as printing documents or playing audio. This dependency ensures that hardware functionalities are properly utilized and controlled within the system's environment .
Memory-mapped I/O impacts system design by simplifying the integration of I/O devices, as they share the same address space as the main memory. This allows more flexible and efficient communication, as devices write and read data to/from specified memory locations without CPU intervention. Consequently, performance is enhanced due to reduced CPU workload and improved data transfer speeds, but challenges such as address space allocation and potential conflicts can arise, requiring careful system coordination .
Communication between the CPU and I/O devices can be achieved using special instruction I/O, memory-mapped I/O, or direct memory access (DMA). Memory-mapped I/O involves assigning certain memory addresses to control I/O devices, allowing the CPU to read or write to these addresses as if they were ordinary RAM locations. This method utilizes the same address space for I/O devices and system memory, facilitating efficient data transfer without requiring CPU intervention, and allowing the I/O device to transfer data directly to/from memory asynchronously .
Synchronous I/O causes CPU execution to wait while I/O operations are completed, which can lead to inefficient CPU usage especially when I/O operations take a significant amount of time. On the other hand, asynchronous I/O allows I/O operations to proceed concurrently with CPU execution, enabling the CPU to perform other tasks while waiting for I/O operations to complete. This can significantly improve the overall performance and efficiency of the system by reducing idle CPU time .
Kernel-mode device drivers are crucial as they provide direct communication between hardware and the kernel, allowing essential components like BIOS and motherboard drivers to function seamlessly during system boot and operation. This direct control improves performance and reliability for core functionalities. However, challenges include the complexity of developing these drivers and the potential for system instability or crashes if they contain bugs, as they operate with high privileges and can impact the entire system .
Device controllers serve as the interface between I/O devices and device drivers, converting data and control signals to a format the device drivers and OS can understand. This interaction starts with the device controller converting serial bit streams into blocks of bytes while managing error corrections. Device drivers take these blocks and allow the operating system to communicate effectively with the hardware, ensuring that data is correctly passed through the plug and socket connections to the device controller for execution .
The primary advantages of contiguous file allocation include supporting both sequential and direct access, with the latter benefiting from the simplicity of calculating the address of the kth block directly, leading to minimal seek times and fast access. However, the disadvantages include potential internal and external fragmentation, complicating efficient disk space utilization, and difficulty in increasing file sizes due to the need for contiguous free space .
Interrupts facilitate multitasking by allowing the processor to handle multiple tasks concurrently, switching between them as events occur without the need for constant polling. This enhances efficiency and system responsiveness. However, issues such as interrupt handling priority and managing spurious interrupts could cause problems, including decreased performance if interrupts lead to excessive context switching, or undetected errors if spurious interrupts are mismanaged .
Interrupts enhance system performance by providing real-time responsiveness, allowing for efficient resource usage by letting the system react to events without constant polling, and enabling multitasking by allowing processors to switch between tasks. They improve throughput by overlapping computation with I/O operations. However, challenges include managing spurious interrupts, which can complicate system behavior, and ensuring that all interrupts are correctly prioritized and handled without causing unintended disruptions .