0% found this document useful (0 votes)
8 views48 pages

Understanding I/O Devices and DMA

Uploaded by

anyone1921
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views48 pages

Understanding I/O Devices and DMA

Uploaded by

anyone1921
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Unit-6

I/O devices (Input/Output devices) are hardware components used to interact


with a computer system—either by inputting data into the system or
outputting results from it.

🔹 Input Devices

These allow users to send data or control signals to a computer.

 Keyboard – for typing text


 Mouse – for pointing, clicking, dragging
 Scanner – for digitizing documents
 Microphone – for audio input
 Webcam – for capturing video

🔹 Output Devices

These receive data from a computer and present it to the user.

 Monitor/Display – shows visual output


 Printer – produces hard copies of documents
 Speakers – output sound
 Projector – displays output on a large screen

🔹 Input/Output (Both I/O) Devices

These perform both input and output functions.

 Touchscreen – accepts input via touch and displays output


 External hard drives – data can be read from and written to them
 Modem – sends and receives data over networks.

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.

Synchronous vs asynchronous I/O

 Synchronous I/O − In this scheme CPU execution waits while I/O


proceeds
 Asynchronous I/O − I/O proceeds concurrently with CPU execution

Communication to I/O Devices

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.

 Special Instruction I/O


 Memory-mapped I/O
 Direct memory access (DMA)

Special Instruction I/O

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.

Direct Memory Access


Direct Memory Access (DMA) is a technique used in computers and other
electronic devices to allow peripherals (like hard drives, network cards, and
sound cards) to communicate directly with the main memory (RAM) without
involving the CPU. This process speeds up data transfer and frees up the CPU
to perform other tasks, improving overall system performance.
 The peripheral device sends a request to the DMA controller to
initiate a data transfer.
 The DMA controller takes control of the system’s memory bus and
accesses memory directly, either reading data from it or writing data
to it.
 After the transfer is complete, the DMA controller signals the CPU
that the task is finished, and the CPU can continue with other tasks.
Working of DMA Transfer
Below diagram represents a Direct Memory Access (DMA) controller and its
components in a typical DMA system.
Working of DMA System
DMA Controller Components
1. Control Logic: The Control Logic is the central component that
manages the overall DMA operation. It processes control signals and
directs data transfers between the peripherals and memory. It
receives commands from other components and determines how and
when data should be moved.
2. DMA Select and DMA Request: DMA Select is used by the DMA
controller to select the appropriate data transfer request. DMA
Request is initiated by a peripheral device when it needs to perform a
data transfer. The request tells the DMA controller that the device is
ready to either read or write data.
3. DMA Acknowledge: The DMA Acknowledge signal is sent back
from the control logic to the peripheral device to confirm that the
DMA operation has been initiated and the device can proceed with
the data transfer.
4. Bus Request and Bus Grant: Bus Request is generated by the DMA
controller when it needs access to the system's bus for data transfer.
The Bus Grant signal is sent from the CPU or the system’s bus
controller to give the DMA controller permission to use the bus for
transferring data.
5. Address Bus and Data Bus: The Address Bus and Data Bus are
used to transfer data and memory addresses between the DMA
controller, memory, and peripherals. The Data Bus Buffer
temporarily holds data being transferred, while the Address Bus
Buffer holds memory addresses.
6. Registers:
 Address Register: This stores the memory address where
data will be written or read from.
 Word Count Register: This keeps track of the number of
words or units of data that need to be transferred.
 Control Register: This contains control information,
including the direction of data transfer (read or write), and
any other control signals necessary to manage the DMA
operation.
7. Internal Bus: The Internal Bus connects all the components inside
the DMA controller, allowing them to communicate and pass data
efficiently.
8. Interrupt: The Interrupt signal is used to inform the CPU once the
DMA operation is completed. After the data has been transferred, the
DMA controller sends an interrupt to notify the CPU, so the CPU can
resume processing or handle other tasks.
Working:
 The DMA controller facilitates the transfer of data between memory
and peripherals without involving the CPU for each individual data
operation, as mentioned in the article.
 The DMA Select and DMA Request initiate the process when a
peripheral wants to transfer data, similar to how DMA allows
peripherals to operate independently of the CPU.
 Address Bus and Data Bus handle the flow of data and memory
addresses during the transfer, improving system efficiency by
bypassing the CPU.
 The Registers (Address Register, Word Count Register, Control
Register) store the necessary information to control the transfer, as
described in the article, where DMA controls the movement of data
between the device and memory.
 The Interrupt is triggered once the transfer is completed, similar to
how the CPU is notified in the article that DMA operations have
been finished.
Types of DMA
There are several types of DMA, each with its own way of transferring data:
1. Burst Mode DMA:
 In this mode, the DMA controller takes control of the
memory bus and transfers a block of data in one go.
 The CPU is temporarily locked out of memory access while
the DMA controller completes the data transfer.
2. Cycle Stealing DMA:
 In this mode, the DMA controller transfers one data item at
a time but allows the CPU to access memory between each
transfer.
 This allows the CPU and DMA controller to share the
memory bus and work more collaboratively.
3. Block Mode DMA:
 The DMA controller transfers a block of data without
interruption, but it uses a more organized approach than
burst mode, allowing for more efficient transfers.
 The CPU is locked out of memory access during the
transfer.
4. Demand Mode DMA:
 In this mode, the DMA controller transfers data only when
the CPU is not using the memory bus, essentially waiting
for an idle time to perform the transfer.
What is an Interrupt?
The interrupt is a signal emitted by hardware or software when a process or an
event needs immediate attention. It alerts the processor to a high-priority
process requiring interruption of the current working process. In I/O devices
one of the bus control lines is dedicated for this purpose and is called
the Interrupt Service Routine (ISR).
When a device raises an interrupt at let’s say process i,e., the processor first
completes the execution of instruction i. Then it loads the Program Counter
(PC) with the address of the first instruction of the ISR. Before loading the
Program Counter with the address, the address of the interrupted instruction is
moved to a temporary location. Therefore, after handling the interrupt the
processor can continue with process i+1.
While the processor is handling the interrupts, it must inform the device that
its request has been recognized so that it stops sending the interrupt request
signal. Also, saving the registers so that the interrupted process can be restored
in the future, increases the delay between the time an interrupt is received and
the start of the execution of the ISR. This is called Interrupt Latency.
Types of Interrupt
Event-related software or hardware can trigger the issuance of interrupt
signals. These fall into one of two categories: software interrupts or hardware
interrupts.
1. Software Interrupts
A sort of interrupt called a software interrupt is one that is produced by
software or a system as opposed to hardware. Traps and exceptions are other
names for software interruptions. They serve as a signal for the operating
system or a system service to carry out a certain function or respond to an
error condition. Generally, software interrupts occur as a result of specific
instructions being used or exceptions in the operation. In our system, software
interrupts often occur when system calls are made. In contrast to the fork()
system call, which also generates a software interrupt, division by zero throws
an exception that results in the software interrupt.
A particular instruction known as an “interrupt instruction” is used to create
software interrupts. When the interrupt instruction is used, the processor stops
what it is doing and switches over to a particular interrupt handler code. The
interrupt handler routine completes the required work or handles any errors
before handing back control to the interrupted application.

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 Driver in computing refers to a special kind of software program or a


specific type of software application that controls a specific hardware device
that enables different hardware devices to communicate with the computer’s
Operating System. A device driver communicates with the computer hardware
by computer subsystem or computer bus connected to the hardware.

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:

Types of Device Driver:


For almost every device associated with the computer system there exist a
Device Driver for the particular hardware. But it can be broadly classified into
two types

Kernel-mode Device Driver –

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.

o BIOS: BIOS (basic input/output system) is the most basic computer


driver in existence. It is designed to be the first program that boots when
a PC turns on. The BIOS is stored on memory built into the motherboard
and is designed to boot the hardware connected to the PC, including the
hard drives, video display output, keyboard and mouse.
o Motherboard Drivers: Motherboard drivers are small programs that are
read by either Windows or Linux and allow for basic computer functions
while inside the operating system. These drivers normally include
programs that allow broadband ports, USB ports and I/O ports for the
mouse and keyboard. Depending on the making of the motherboard, the
drivers may also have basic drivers for video and audio support.
o User-mode Device Driver – Other than the devices which are brought by
the kernel for working the system the user also brings some devices for
use during the using of a system that devices need device drivers to
function those drivers fall under User mode device driver. For example,
the user needs any plug-and-play action that comes under this.

Applications of Device Drivers

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


Device-independent I/O software, also known as the I/O subsystem or I/O


management, is an integral part of an operating system that provides a layer of
abstraction between hardware devices and user-level applications This
abstraction though performs input and output operations for applications It can,
without having to worry about the specifics of hardware devices.
Key Concepts
Here are some of the key elements and ideas related to device-independent
information and control (I/O) software within an operating system:

Features of Device I/O Software


1. Abstraction Layer
The main goal of this I/O is to provide a bigger layer of abstraction to protect
applications from the complexities of communicating with hardware devices.
This gives abstraction from hardware application’s data to interface a
consistent. Moreover, it is very easy to use.
2. Device Driver
Non-device I/O software controls device drivers, which are software
components that manage communication between the operating system and
physical hardware devices These drivers interpret generic I/O requests from an
application types into device-specific commands.
3. Standard I/O Operations
It gives a general set of I/O operations that programs can use to read from and
write to devices. They are highly used for various operations such as starting a
device, opening the last tab, reading and writing a particular document, and
controlling the gadget.
4. Device Independence
Device-impartial I/O software ensures that applications can use identical I/O
operations irrespective of the specific hardware tool they're interacting with.
This approach that packages do not need to be rewritten or modified when the
underlying hardware changes.
5. Buffering and Caching
Buffering and caching are primarily used for I/O operations to optimize them.
Data may be buffered in memory to lessen the quantity of interactions with the
hardware, enhancing performance.
6. Error Handling
Error handling in tool-unbiased I/O (Input/Output) software programs is critical
thing of making the reliability and robustness of I/O operations across diverse
devices and systems. Device-impartial I/O software program is designed to
abstract the underlying hardware, allowing software program packages to carry
out I/O operations without having to address the specific info of different
devices.
7. Concurrency Control
Concurrency manage in tool-unbiased I/O (Input/Output) software program is
crucial to control and synchronize access to I/O resources, making sure that
multiple techniques or threads can interact with I/O gadgets in a coordinated
and consistent manner. Concurrency control mechanisms are especially
important in environments in which more than one packages or thread may be
acting I/O operations on distinct devices concurrently.
8. Virtual File System (VFS)
A virtual document is created for some OS to provide a similar virtual
environment for various operations such as record structure diversification,
network protocols, and storage of the device. This lets in packages to paintings
with files and data regardless of their place or layout.
9. Device Management
Device Management conducts the key aspects necessary for the device such as
its configuration, its allocation of resources, the coordination required in
between the gadgets, and its management with the initial process of the device.
10. Security and Access Control
The I/O subsystem enforces protection regulations and gets right of entry to
control, ensuring that the handiest authorized users or packages can get
admission to positive devices or carry out specific operations.
11. Portability
By presenting a device-impartial interface, the I/O subsystem complements the
portability of packages. Applications evolved on one platform may be without
problems adapted to run on exceptional platforms with minimal code changes
Goals of I/O software
Last Updated : 17 Jun, 2022


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.

Hard Disk Structure In OS

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.

Below is a descriptive diagram of a single platter.


Tracks

Circular areas of the disk are known as tracks.

 There may be more than 1000 tracks on a 3.5-inch hard disk.


 Track Numbering starts with zero from the outermost track.

Sectors

We further divide tracks into several small units, and these units are known as
sectors.

 Sectors are the most minor physical storage units on disk.


 The size of each sector is almost always 512 Bytes.
 Sector Numbering starts from number 1, in the outermost tracks.

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.

 The magnetic field writes data onto the platter surface.


 When the R/W head contacts the platter surface, it may create bad
sectors.
 Had disk may damage due to these bad sectors.

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.

Cylinder Numbering starts with zero from the outermost cylinder.

Cluster

Cluster is also known as blocks. A group of sectors makes a cluster. There


may be 64 or more sectors in a cluster. OS uses these clusters to Read/Write the
data.

Hard Disk Capacity

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.

File Systems in Operating System



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.

File Allocation Methods


There are several types of file allocation methods. These are mentioned below.
 Continuous Allocation
 Linked Allocation(Non-contiguous allocation)
 Indexed Allocation
Continuous Allocation
A single continuous set of blocks is allocated to a file at the time of file
creation. Thus, this is a pre-allocation strategy, using variable size portions. The
file allocation table needs just a single entry for each file, showing the starting
block and the length of the file. This method is best from the point of view of
the individual sequential file. Multiple blocks can be read in at a time to
improve I/O performance for sequential processing. It is also easy to retrieve a
single block. For example, if a file starts at block b, and the ith block of the file
is wanted, its location on secondary storage is simply b+i-1.

Disadvantages of Continuous Allocation


 External fragmentation will occur, making it difficult to find
contiguous blocks of space of sufficient length. A compaction
algorithm will be necessary to free up additional space on the disk.
 Also, with pre-allocation, it is necessary to declare the size of the file
at the time of creation.
Linked Allocation(Non-Contiguous Allocation)
Allocation is on an individual block basis. Each block contains a pointer to the
next block in the chain. Again the file table needs just a single entry for each
file, showing the starting block and the length of the file. Although pre-
allocation is possible, it is more common simply to allocate blocks as needed.
Any free block can be added to the chain. The blocks need not be continuous.
An increase in file size is always possible if a free disk block is available. There
is no external fragmentation because only one block at a time is needed but
there can be internal fragmentation but it exists only in the last disk.
Disadvantage Linked Allocation(Non-contiguous allocation)
 Internal fragmentation exists in the last disk block of the file.
 There is an overhead of maintaining the pointer in every disk block.
 If the pointer of any disk block is lost, the file will be truncated.
 It supports only the sequential access of files.
Indexed Allocation
It addresses many of the problems of contiguous and chained allocation. In this
case, the file allocation table contains a separate one-level index for each file:
The index has one entry for each block allocated to the file. The allocation may
be on the basis of fixed-size blocks or variable-sized blocks. Allocation by
blocks eliminates external fragmentation, whereas allocation by variable-size
blocks improves locality. This allocation technique supports both sequential and
direct access to the file and thus is the most popular form of file allocation.
Disk Free Space Management
Just as the space that is allocated to files must be managed, so the space that is
not currently allocated to any file must be managed. To perform any of the file
allocation techniques, it is necessary to know what blocks on the disk are
available. Thus we need a disk allocation table in addition to a file allocation
table. The following are the approaches used for free space management.
 Bit Tables: This method uses a vector containing one bit for each
block on the disk. Each entry for a 0 corresponds to a free block and
each 1 corresponds to a block in use.
For example 00011010111100110001
In this vector every bit corresponds to a particular block and 0 implies
that that particular block is free and 1 implies that the block is already
occupied. A bit table has the advantage that it is relatively easy to find
one or a contiguous group of free blocks. Thus, a bit table works well
with any of the file allocation methods. Another advantage is that it is
as small as possible.
 Free Block List: In this method, each block is assigned a number
sequentially and the list of the numbers of all free blocks is maintained
in a reserved block of the disk.
Advantages of File System
 Organization: A file system allows files to be organized into
directories and subdirectories, making it easier to manage and locate
files.
 Data Protection: File systems often include features such as file and
folder permissions, backup and restore, and error detection and
correction, to protect data from loss or corruption.
 Improved Performance: A well-designed file system can improve
the performance of reading and writing data by organizing it
efficiently on disk.
Disadvantages of File System
 Compatibility Issues: Different file systems may not be compatible
with each other, making it difficult to transfer data between different
operating systems.
 Disk Space Overhead: File systems may use some disk space to store
metadata and other overhead information, reducing the amount of
space available for user data.
 Vulnerability: File systems can be vulnerable to data
corruption, malware, and other security threats, which can
compromise the stability and security of the system.

File Access Methods in Operating System


File access methods in an operating system are the techniques and processes
used to read from and write to files stored on a computer’s storage devices.
There are several ways to access this information in 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.
These methods determine how data is organized, retrieved, and modified within
a file system. Understanding file access methods is crucial for efficient data
management and system performance. In this article, we are going to discuss
different types of methods to access the file.
There are three ways to access a file in a computer system:
 Sequential-Access
 Direct Access
 Index sequential Method
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, the 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- reads the next position of the file and automatically advances a file
pointer, which keeps track of the I/O location. Similarly, for the -
write next- append to the end of the file and advance to the newly written
material.

Sequential Access Method


Key Points related to Sequential Access
 Data is accessed from one record right after another record in an order.
 When we use the read command, it moves ahead pointer by one.
 When we use the 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.
Direct Access Method
The Direct Access Method (also known as the Relative Access Method)
allows rapid reading and writing of fixed-length records in any order. Based on
the disk model, which supports random access, the file is viewed as a sequence
of numbered blocks or records. This means data can be read or written to any
block in no specific order. The block numbers provided by the user are relative,
starting from 0, 1, and so on. There are no restrictions on the order of accessing
records in direct access files.

Direct Access Method


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.
Disadvantages of Direct Access Method
 Complex Implementation : Implementing direct access can be
complex, requiring sophisticated algorithms and data structures to
manage and locate records efficiently.
 Higher Storage Overhead : Direct access methods often require
additional storage for maintaining data location information (such as
pointers or address tables), which can increase the overall storage
requirements.
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.
Index Access Method

Key Points Related to Index Sequential Method


 It is built on top of Sequential access.
 It control the pointer by using index.
Advantages of Index Sequential Method
 Efficient Searching : Index sequential method allows for quick
searches through the index.
 Balanced Performance : It combines the simplicity of sequential
access with the speed of direct access, offering a balanced approach
that can handle various types of data access needs efficiently.
 Flexibility : This method allows both sequential and random access to
data, making it versatile for different types of applications, such as
batch processing and real-time querying.
 Improved Data Management : Indexing helps in better organization
and management of data. It makes data retrieval faster and more
efficient, especially in large databases.
 Reduced Access Time : By using an index to directly locate data
blocks, the time spent searching for data within large datasets is
significantly reduced.
Disadvantages of Index Sequential Method
 Complex Implementation : The index sequential method is more
complex to implement and maintain compared to simple sequential
access methods.
 Additional Storage : Indexes require additional storage space, which
can be significant for large datasets. This extra space can sometimes
offset the benefits of faster access.
 Update Overhead : Updating the data can be more time-consuming
because both the data and the indexes need to be updated. This can
lead to increased processing time for insertions, deletions, and
modifications.
 Index Maintenance : Keeping the index up to date requires regular
maintenance, especially in dynamic environments where data changes
frequently. This can add to the system’s overhead.
File Operations in OS

The Operating system is responsible for performing the following file


operations using various system calls:
1. Read
2. Write
3. Create
4. Delete
5. Truncate files
6. Reposition

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.

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:
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.

Free Space Management in Operating System


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:
Free Space Management Techniques
 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 waste of space.
 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.
 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.
 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.
 Volume Shadow Copy: This is a technology used in Microsoft
Windows operating systems to create backup copies of files or entire
volumes. When a file is modified, the operating system creates a
shadow copy of the file and stores it in a separate location. This
method is useful for data recovery and protection against accidental
file deletion.
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 free and 1 indicates an allocated block. The given instance of disk blocks on
the disk in Figure 1 (where green blocks are allocated) can be represented by a

bitmap of 16 bits as: 1111000111111001.

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.

This kind of implementation requires a filename to be searched before creating


a file with that name. Similarly, a delete operation also requires a linear search
for the directory and then deallocating the space occupied by the directory.

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.

A solution to the above problem could be to use a chained-overflow hash table.


A chained-overflow hash table consists of a linked list that stores all hashed
entries. Now, if more than one filename hashes to the same entry it can be
added as another node to the linked list.

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.

Directory Implementation using Singly Linked List

The implementation of directories using a singly linked list is easy to program


but is time-consuming to execute. Here we implement a directory by using a
linear list of filenames with pointers to the data blocks.
Directory Implementation Using Singly Linked List
 To create a new file the entire list has to be checked such that the
new directory does not exist previously.
 The new directory then can be added to the end of the list or at the
beginning of the list.
 In order to delete a file, we first search the directory with the name of
the file to be deleted. After searching we can delete that file by
releasing the space allocated to it.
 To reuse the directory entry we can mark that entry as unused or we
can append it to the list of free directories.
 To delete a file linked list is the best choice as it takes less time.
Disadvantage
The main disadvantage of using a linked list is that when the user needs to find
a file the user has to do a linear search. In today’s world directory information
is used quite frequently and linked list implementation results in slow access
to a file. So the operating system maintains a cache to store the most recently
used directory information.

Directory Implementation using Hash Table

An alternative data structure that can be used for directory implementation is


a hash table. It overcomes the major drawbacks of directory implementation
using a linked list. In this method, we use a hash table along with the linked
list. Here the linked list stores the directory entries, but a hash data structure is
used in combination with the linked list.
In the hash table for each pair in the directory key-value pair is generated. The
hash function on the file name determines the key and this key points to the
corresponding file stored in the directory. This method efficiently decreases
the directory search time as the entire list will not be searched on every
operation. Using the keys the hash table entries are checked and when the file
is found it is fetched.

Directory Implementation Using Hash Table


Disadvantage:
The major drawback of using the hash table is that generally, it has a fixed size
and its dependency on size. But this method is usually faster than linear search
through an entire directory using a linked list.
Disk Management in Operating System
Disk management is one of the critical operations carried out by the operating
system. It deals with organizing the data stored on the secondary
storage devices which includes the hard disk drives and the solid-state drives. It
also carries out the function of optimizing the data and making sure that the data
is safe by implementing various disk management techniques. We will learn
more about disk management and its related techniques found in operating
system.
The range of services and add-ons provided by modern operating systems is
constantly expanding, and four basic operating system management functions
are implemented by all operating systems. These management functions are
briefly described below and given the following overall context. The four main
operating system management functions (each of which are dealt with in more
detail in different places) are:
 Process Management
 Memory Management
 File and Disk Management
 I/O System Management
Most computer systems employ secondary storage devices (magnetic disks). It
provides low-cost, non-volatile storage for programs and data (tape, optical
media, flash drives, etc.). Programs and the user data they use are kept on
separate storage devices called files. The operating system is responsible for
allocating space for files on secondary storage media as needed.
There is no guarantee that files will be stored in contiguous locations on
physical disk drives, especially large files. It depends greatly on the amount of
space available. When the disc is full, new files are more likely to be recorded
in multiple locations. However, as far as the user is concerned, the example file
provided by the operating system hides the fact that the file is fragmented into
multiple parts.
The operating system needs to track the location of the disk for every part of
every file on the disk. In some cases, this means tracking hundreds of thousands
of files and file fragments on a single physical disk. Additionally, the operating
system must be able to locate each file and perform read and write operations on
it whenever it needs to. Therefore, the operating system is responsible for
configuring the file system, ensuring the safety and reliability of reading and
write operations to secondary storage, and maintains access times (the time
required to write data to or read data from secondary storage).
Disk Management of the Operating System Includes:
 Disk Format
 Booting from disk
 Bad block recovery
The low-level format or physical format:
Divides the disk into sectors before storing data so that the disk controller can
read and write Each sector can be:
The header retains information, data, and error correction code (ECC) sectors of
data, typically 512 bytes of data, but optional disks use the operating system’s
own data structures to preserve files using disks.
It is conducted in two stages:
1. Divide the disc into multiple cylinder groups. Each is treated as a logical
disk.
2. Logical format or “Create File System”. The OS stores the data structure of
the first file system on the disk. Contains free space and allocated space.
For efficiency, most file systems group blocks into clusters. Disk I / O runs in
blocks. File I / O runs in a cluster.
For example, the sizes can be 256,512, and 1,024 bytes. If disk is formatted
with larger sector size, fewer sectors can fit on each track.
As a result fewer headers and trailers are written on each track and more space
is obtainable for user data. – Some operating systems can handle a sector size of
512 bytes.
Operating system keeps its own data structures on disk before it use disk to
store the files. It performs this with following two steps:
1. It partitions the disk into one or more groups of cylinders. Each partition is
treated by OS as a separate disk.
2. Logical formatting: That means creation of file system.
In order to increase the efficiency, file system groups blocks in chunks called as
clusters.
Some operating systems give special programs the ability to use a disk partition
as a large sequential array of logical blocks, without any file-system data
structures. This array is sometimes called the raw disk, and I/O to this array is
called as raw I/O.
Boot block:
 When the computer is turned on or restarted, the program stored in the
initial bootstrap ROM finds the location of the OS kernel from the
disk, loads the kernel into memory, and runs the OS. start.
 To change the bootstrap code, you need to change the ROM and
hardware chip. Only a small bootstrap loader program is stored in
ROM instead.
 The full bootstrap code is stored in the “boot block” of the disk.
 A disk with a boot partition is called a boot disk or system disk.
 The bootstrap program is required for a computer to initiate the
booting after it is powered up or rebooted.
 It initializes all components of the system, from CPU registers to
device controllers and the contents of main memory, and then starts
the operating system.
 The bootstrap program then locates the OS kernel on disk, loads that
kernel into memory, and jumps to an initial address to start the
operating-system execution.
 The Read Only Memory (ROM) does not require initialization and is
at a fixed location that the processor can begin executing when
powered up or reset. Therefore bootstrap is stored in ROM.
 Because of read only feature of ROM; it cannot be infected by a
computer virus. The difficulty is that modification of this bootstrap
code requires changing the ROM hardware chips.
 Therefore, most systems store a small bootstrap loader program in the
boot ROM which invokes and bring full bootstrap program from disk
into main memory.
 The modified version of full bootstrap program can be simply written
onto the disk.
 The fixed storage location of full bootstrap program is in the “boot
blocks”.
 A disk that has a boot partition is called a boot disk or system disk.
Bad Blocks:
 Disks are error-prone because moving parts have small tolerances.
 Most disks are even stuffed from the factory with bad blocks and are
handled in a variety of ways.
 The controller maintains a list of bad blocks.
 The controller can instruct each bad sector to be logically replaced
with one of the spare sectors. This scheme is known as sector sparing
or transfer.
 A soft error triggers the data recovery process.
 However, unrecoverable hard errors may result in data loss and
require manual intervention.
 Failure of the disk can be:
1. Complete, means there is no way other than replacing the disk. Back up of
content must be taken on new disk.
2. One or more sectors become faulty.
3. After manufacturing, the bad blocks exist. Depending on the disk and
controller in use, these blocks are handled in a different ways.
Disk management in operating systems involves organizing and maintaining the
data on a storage device, such as a hard disk drive or solid-state drive. The main
goal of disk management is to efficiently utilize the available storage space and
ensure data integrity and security.
Some common disk management techniques used in operating systems
include:
1. Partitioning: This involves dividing a single physical disk into
multiple logical partitions. Each partition can be treated as a separate
storage device, allowing for better organization and management of
data.
2. Formatting: This involves preparing a disk for use by creating a file
system on it. This process typically erases all existing data on the disk.
3. File system management: This involves managing the file systems
used by the operating system to store and access data on the disk.
Different file systems have different features and performance
characteristics.
4. Disk space allocation: This involves allocating space on the disk for
storing files and directories. Some common methods of allocation
include contiguous allocation, linked allocation, and indexed
allocation.
5. Disk defragmentation: Over time, as files are created and deleted, the
data on a disk can become fragmented, meaning that it is scattered
across the disk. Disk defragmentation involves rearranging the data on
the disk to improve performance.
Advantages of disk management include:
1. Improved organization and management of data.
2. Efficient use of available storage space.
3. Improved data integrity and security.
4. Improved performance through techniques such as defragmentation.
Disadvantages of disk management include:
1. Increased system overhead due to disk management tasks.
2. Increased complexity in managing multiple partitions and file systems.
3. Increased risk of data loss due to errors during disk management tasks.
4. Overall, disk management is an essential aspect of operating system
management and can greatly improve system performance and data
integrity when implemented properly.

Common questions

Powered by AI

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 .

You might also like