Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views60 pages

4 Operating System

Uploaded by

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

4 Operating System

Uploaded by

chetan prajapati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

Operating Systems

UNIT - 4 FILE SYSTEMS

STRUCTURE

4.0 Learning Objectives

4.1 Introduction

4.2 A Simple File System

4.3 Device Strategy Module

4.4 I/O Initiators

4.5 Device Handlers

4.5.1 Disk Scheduling

4.5.2 Design of IO Systems

4.6 File Management

4.7 Directory Management

4.8 Let Us Sum Up

4.9 Keywords

4.10 Some Useful Books

4.11 Answer to Check Your Progress

4.12 Terminal Question

4.0 LEARNING OBJECTIVES

After studying this unit, you will be able to:

● Explain the structure of a file system and its components.

● Understand the strategy behind file space allocation and various


techniques for it.

● Explain the setup of the file access controls and grant


permissions.

● Describe file and directory management.


Operating Systems

4.1 INTRODUCTION

A File System is a mechanism that provides on-line storage and access to


both data and programs of an operating system and all the users of the
computer system. A file system consists of two unique parts: a collection
of files, that stores required data, and a directory structure, organizing and
provides information about all the files in the system that are in storage
devices.

A user has many expectations when working with files, such as:

● Convenient and fast access to files.

● Reliable storage of files.

● Sharing of files with collaborators.

The resources used for storing and accessing files are I/O devices. The OS
ensures both efficient performance of file processing activities in
processes and efficient use of I/O devices.

Operating systems organize file management into two components called


the file system and the input-output control system (IOCS) to separate
the file-level concerns from concerns related to efficient storage and
access of data. A file has following functions:

● To create and manipulate files.

● To rely on files during power outages and I/O device malfunctions.

● Directions to share files among users.

While an IOCS provides access to data stored on I/O devices and good
performance of I/O devices.

File Processing

File processing refers to the sequence of operating a file that includes


opening, reading, and writing of data and closing of a file. Figure 4.1
illustrates the arrangement of OS implementing the process of file
processing activities. Each directory specifies entries of some files
describing details about the file, the name of the owner, location on a disk,
the way of organization and instruction to users to access a file.
Operating Systems

As shown in the figure, Pi is a code for the process to open a file for File
processing, that locates a file through directory structure (a group of
directories). There are two files as shown in the figure, beta and phi. The
code of process Pi is responsible for opening of a data, what to name it,
user details, directory structure all of which will determine which two files
to be accessed. A file system generates various file types. Each file type
has its distinct view of data. file type provides its own abstract view of data
(logical view of data). For example, in figure 4.1, the file beta opened
through Pi has a record-oriented logical view, while the file phi has byte
stream–oriented logical view with no distinct records.

Figure 4.1: File system and the IOCS

IOCS arranges its file data in an I/O device based on its file type. IOCS
facilitates the physical view of the file’s data. An IOCS has the following
functions:

● IOCS regulates the movement between the logical view and the
physical view of a file’s data.

● By providing a structure, an IOCS accelerates the speed of a file


processor in searching a data stored as a memory in form of a
buffer, file cache or disk cache.
Operating Systems
● IOCS take its data from a buffer or a cache when the read operation
is performed that grants access to a data in a file.

When the read operation is performed, the IOCS commences its work in
the background of taking the data from the buffer or cache eliminating the
need to wait until the data is read off from the I/O device holding a file.
The actual I/O operations to read data from an I/O device into a buffer or
a cache, or to write it from there onto an I/O device, are performed by the
IOCS in the background.

4.2 A SIMPLE FILE SYSTEM

File Concept

A computer stores its data in various storage media like HDDS, magnetic
tapes and optical disks all which are non-volatile, hence its content stored
in these devices are persistent even between the system reboots. A file is a
group of information that is named and recorded in a storage. A user looks
at a file as the smallest allotment of logical secondary storage, i.e a data
must first exist in a file for it to be viewed in a secondary storage. A file in
general, is a representation of programs (both source and object forms) and
data. It can be in numbers, alphabets, alphanumeric or binary. As an
overview a file is a sequence of bits, bytes, lines, or records that is devoid
of a text file. But the real meaning of a file can only be defined by its user
or creator.

Many different types of information may be stored in a file—source or


executable programs, numeric or text data, photos, music, video, and so
on. A file has a certain defined structure, which depends on its type.

File System

A file system is a collection of data in a file owned by a user. It can be


shared only by authorized users and it is reliably stored over an extended
period of time. A file system provides privacy to its users to avoid
interference by other users and liberty to users to name their files to ensure
the files don't overlap the other users.
Operating Systems

The IOCS views a file as a storehouse of data that needs to be accessed


speedily and is stored on an I/O device that needs to be used efficiently.
Facilities provided by the file system and the IOCS are:

● Directory structures for convenient grouping of files.

● Protection of files against illegal accesses.

● File sharing semantics for concurrent accesses to a file.

● Reliable storage of files.

Input-Output Control System (IOCS)

● Efficient operation of I/O devices.

● Efficient access to data in a file.

Benefits of a File system:

● Protection to directory structures involved in organizing data into


logical files.

● Prevention of illegal file access.

● Reduces risks of losing a data during system crash.

The file system and the IOCS maintain their hierarchy by establishing their
policies and each of them hold different notions and thus are classified into
types based on their varied functions:

● A file system provides a space for performing open, read/write and


close operations. This mechanism is performed by accessing
directories for opening and closing of operations. Their policy is to
ensure safety while performing open or read/write operations. A file
system also enables IOCS to open a file data by requesting read/write
operation.

● The policy of IOCS ensures efficient functioning of I/O devices and


file processing. This can be achieved through the IOCS mechanism
module which is to initiate I/O operations by evoking the Kernel.

A file system houses two kinds of data:

1. Data: A data within a file can simply be called a Date.


Operating Systems
2. Meta data or control data: A data used to access the data of a
different file.

Meta data is usually seen inside a directory structure as shown in the


logical view of figure 4.1.

Files and File Operations

A file system houses and organizes different types of files, e.g., data files,
executable programs, object modules, textual information, documents,
spreadsheets, photos, and video clips. Each of these file types has their
unique way for recording data. These file types can be grouped into two
classes:

● Structured files

● Byte stream files

A structured file consists of collection of records, where the record is a


meaningful unit for processing of data. A record is a collection of fields
where a field contains a single data item. Each record in a file is stimulated.
The value in the key field of a record is unique in a file; i.e., no two records
contain an identical key.

Many file types mentioned earlier are structured files. Standard system
software’s use file types that are structured and determined by OS
designers. Eg: Compilers and Linkers. General users use file types based
on the application or programs they create.

A byte stream file is “flat.” There are no records and fields in it; it is
looked upon as a sequence of bytes by the processes that use it.

A file attribute is a characteristic of a file that is important either to its


users or to the file system, or both. Type, organization, size, location on
disk, access control information, (which indicates the manner in which
different users can access the file), owner name, time of creation, time of
last use are commonly used attributes of a file.

A typical attributes of a file besides varying OS are:

● Name. The symbolic file name is the only information kept in human
readable form.
Operating Systems

● Identifie: A unique tag found in a form of numbers used for


identifying a file within a file system. Unlike Name the information
is kept in non-human readable form.

● Type. This information is needed for systems that support different


types of files.

● Location: It helps trace files in a device and act as a pointer to a


device.

● Size: The current size of the file (in bytes, words, or blocks) and
possibly the maximum allowed size are included in this attribute.

● Protection. Access-control information determines who can perform


read/write, execution, and so on.

● Timestamps and user identification. This information may be kept


for creation, last modification, and last use. These data can be useful
for protection, security, and usage monitoring.

Some newer file systems also support extended file attributes, including
character encoding of the file and security features such as a file checksum.

A directory structure houses information of all files existing alongside the


files in a same device. When an identifier turns on Location to trace the
file attributes the size it consumes is more than a kilobyte to record such
information of a searched file. In a system the size of a directory structure
is in megabytes or gigabytes since they try to match the volatility and they
co-exist in the same device of a file and are brought into memory
piecemeal when required.

Operations on Files

A file system module performs operations on a file such as open, close,


rename and delete. But the actual access to a file is carried by the IOCS
module. The table 4.1 is a description of such performances.

Operation Description

Opening a file The file system finds the file in directory entry and
checks whether the user whose process is trying to
Operating Systems
open the file has the necessary access privileges for the
file. It then performs some housekeeping actions to
initiate the processing of a file.

Reading or writing a The file system considers the organization of the file
record and implements the read/write operation in an
appropriate manner.

Closing a file The directory entry is updated with information of the


file size

Making a copy of a file A copy of the file is made, a new directory entry is
created for the copy and its name, size, location, and
protection information is recorded in the entry.

File deletion The directory entry of the file is deleted and the disk
area occupied by it is freed.

File renaming The new name is recorded in the directory entry of the
file.

Specifying access The protection information in the file’s directory entry


privileges is updated.

Table 4-1: Operations on files

Hierarchical Model of a File System

The file system similar to other software systems can break down
towards various parts. As in hierarchical organization, each level stands
as a representation of an abstract machine. In a hierarchy a module
readily seeks service of the other module at the same or at a lower level.
However, all file systems don’s adhere to rigid hierarchy. The conceptual
view of the hierarchical module expands the possibilities to its user and
I/O system to understand the complex functioning of this system. The
left-hand side of figure 4.2 displays the file system’s position as a layer
between the user and the I/O system. It creates the removal of logical
files that can be changed to other files and directory commands for the
user.
Operating Systems

It manages these basic disks and secondary memory devices via services
of the I/O system and swapping data by logical block numbers. The role
of an I/O system is to translate the logical block numbers into verified
disk. Figure 4.2 displays the file system into three units in a hierarchy.

Figure 4.2: A hierarchical view of the file system.

General Model of a File System

Almost all operating systems use a layering approach for every task
along file systems. Each layer of the file system is liable for some
ventures.

The Figure 4.3 shown below, indicates how the file system is sorted in
different layers, including the functions of each layer.

When an application program asks a file, the chief request is to handle


the logical file system. The logical file system contains the Metadata of
the file with directory structure. An error rise when the application
program does not have the permissions of the file Logical file systems
cross checks the path to a file.

● Overall, files are sorted into varied logical blocks. Fails need to be
preserved in the hard disk and be redeemed from the hard disk which
is further divided into several tracks and sectors.

● so, in this process of files, the logical blocks need to be plotted to


physical blocks. This plotting is done by a file organization module
further behind Free Space Management.
Operating Systems
● FOM decides which physical block the application program needs; it
derives this data from the basic file system. This basic file system is
behind to supply the commands to I/O control in order to get those
blocks.

● I/O holds the codes by using which it can access hard disk. These
codes are known as device drivers. I/O controls are again held for
handling errors.

Figure 4.3 File system and the IOCS

Symbolic File System (SFS)

SFS houses files of different sources called collections which is inclusive


of directories and removable media, metadata of files that eliminates the
need to plug in the source media. All such sources appear in symbolic
links. An SFS is a managed directory which is initialized with the
command:sfs init. All commands associated with each SFS can be
implemented only if it's rendered inside a SFS directory tree. Files are
included with the command sfs add-col my collection /path/to/source (add
collection). However, they neglect if the link and files are new.
Operating Systems

4.2.3 Access Control Verification

A very popular method adopted to encounter issues concerning security is


by creating an identity profile to users. Each user will have a unique profile
therefore it becomes simple to create an Access-Control List (ACL)
holding details like name and permitted ways of access for each user.
Through ACL the OS finds it convenient to track user details on requesting
access. Trespassing of data occurs when the user profile is not listed in
ACL and thus turning down authorization. This approach is flawed with
complex access methods.

Defects of Access Control List:

● A major setback of this technique is, it demands labour, if the numbers


of the users are large in number. Further the user details must be known
beforehand.

● The size of the directory entry must be flexible but also making it
complex further.

Preparing a condensed version of the list would acknowledge these errors.


This can be achieved by differentiating the users into three groups as
below:

● Owner: The user who created the file is the owner.

● Group: A set of users who are sharing the file and need similar
access is a group, or work group.

● Other: All other users in the system.

The most common recent approach is to combine access-control lists with


the more general (and easier to implement) owner, group, and universe
access control scheme just described. For example, Solaris uses the three
categories of access by default but allows access-control lists to be added
to specific files and directories when more fine-grained access control is
desired.

An Illustration:

Sanam is an author composing a new book for which she employs three
graduate students (Sara, Sam and Raj) to assist her in the project. The text
of the book is saved in a file as book.tex.
Operating Systems
Actions permitted with the text as follows:

● Sara will be the only permitted user to perform actions on the file.

● Her fellow assistance is permitted to perform read/write on a file and


restricted from deleting the file.

● Users can read but not write on the file as (the author desires to
welcome readers for her text and deliver feedback).

In order to retain these restrictions a new group must be generated as


mentioned above (refer ACL). For instance, a group named Text is
constructed and the users linked to the full text file are Sam, Sara and raj.
If there is a context where Sara wishes to permit a user to access chapter 1
alone it's undesirable to include the user in the Text group because that
will let the user access all chapters. A file can only have a single group.
This error can be resolved by improving the functions of ACL. In
programs like UNIX system control over the creation and modification
over a group are disposed manually to establish control over the access
list.

As ACL has conditions to its approach, refinement is required only to three


particular fields. A field is composed of bits and each bit is responsible for
the denial or access to a file.

In a UNIX system a field of three bits is represented as “rwx” where r


denotes read, write and execution respectively. A distinct field is given to
the owner, group, and users of a file. This approach requires bytes per file
to secure information. For the above-mentioned example of text file
book.tex.

● Owner Sanam: all bites

● Group text: Bites ‘r’ and ‘w’

● All users: Bite ‘r’

Other Protection Approaches

A different method to address drawbacks is to secure the file with a


password. In general computer systems are accessed only through
password likewise it can be done for files too.
Operating Systems

Limitations of a password controlled file:

● Frequent change of password can endanger access to file.

● It is impossible for users to remember multiple passwords.

● Fixating a password to one file makes it available to access all file.

● Associating password to sub directory rather than a primary file


can lessen the possibilities of access to a file without permission.

In a construction directory structure, we want to shield not only individual


files but conjointly collections of files in subdirectories; that is, we need
to produce a mechanism for directory protection. The directory operations
that must be protected are somewhat completely different from the file
operations. we wish to regulate the creation and deletion of files in a very
directory. In addition, we tend to need most likely to regulate whether or
not a user will verify the existence of an enter directory. Sometimes, data
of the existence and name of a file is critical. Thus, listing the contents of
a directory should be a protected operation. Similarly, if a pathname refers
to a file in a directory, the user must be allowed access to each directory
and the file. In systems wherever files might have various pathnames (such
as acyclic and general graphs), a given user may have different access
rights to a selected file, looking at the trail name used.

File Organizations and Access Method

Record access pattern is a process of accessing records in a file.

They are of two basic patterns:

• Sequential access: Access of file in one particular order or


conversely.

• Random access: A quick browsing with no particular order.

Only with appropriate discharge of process record pattern will ensure the
success of a file processing actions of a process in a system.

The characteristics of an I/O device make it suitable for a specific record


access pattern. For example, a tape drive can access only the record that is
placed immediately before or after the current position of its read/write
head.
Operating Systems
A disk drive by a direct route can access any record provided its address
making it conclusive for discharging both the types of Record access
pattern.

A file is a coalition of approaching a record in a file to the mechanism of


accessing it. A file organization serves as a map to an I/O device to
discharge a proper record access for a specific record access pattern. A file
system is an aid for various file organizations making it possible for a
process to use which best fits its file processing requirement and the I/O
device in actions.

The forthcoming section details three fundamental file organization

1. Sequential file organization,

2. Direct file organization

3. Index sequential file organization

Other file organizations used in practice are either variants of these


fundamental ones or are special-purpose organizations that exploit less
commonly used I/O devices.

Access method is the use of the IOCS module to access a file run by a
specific file organization. This method also serves as a policy module for
the IOCS. A program commences on a command inferred from the file
declaration if not by default rules and proceeds further by analyzing the
correct access method to kickstart an operation in a file.

Sequential File Organization

In accordance with the key field, a record is stored in two ways, ascending
or descending in a sequential file organization. A record access pattern on
its application must adhere to the uprooted guidelines. Therefore, it
approves the following dual actions:

read the next (or previous) record and skip the next (or previous) record.
A sequential-access file is used in an application if its data can be
conveniently presorted into an ascending or descending order. The
sequential file organization is also used for byte stream files.
Operating Systems

Direct File Organization

Direct file organization is of huge advantage and coherence while


accessing a record in a random order during the file process. Mention of
the value in a key field while read/write command issued is a prerequisite
to access a record and such files are known as a direct file a direct-access
file. A direct-access file has the following characteristics:

● Key value is essential to access her account.

● The module of the direct file organization requires generating of the


address for a record in the storage medium on exercising
transformation to a key role.

● The transformation generates (track_no, record_no) address for files


in a disk.

● The disk head is at the track (track_no) and record (record_no) before
applying the read/write command.

● Direct file organization is effective in processing a record randomly.


However, it has the following setbacks compared to sequence-file
organization.

● Record address calculation consumes CPU time.

● Inner track of a disk stores less data compared to the outer track, but
direct file organization can store data equally in both tracks thus
wasting the capacity of a record.

● Every key in a record must hold a value for its effective calculation
of the formula but this condition applies for dummy records leading
to in effective use of the I/O device.

● Direct- Access file is not great as sequential- access file in processing


a record.

● The characteristics of an I/O Device becomes evident in assumption


for calculating formulas making the file organization device
dependent.

● A device is directly proportional in calculating the address therefore


every device requires a modified address to calculate the formula for
Operating Systems
example different track capacity, will imply modifying the address
calculation formulas. This requirement affects the portability of
programs.

Index Sequential File Organization

Determination of a records location with its key value is achieved with an


index. An index file will have key value and the disk address has its format
in the index entry for every key value inside a file. For instance, to search
a record with key K, the index entry must contain K in its index, but one
can also use the disk address mentioned in the entry to access the record.
Index search is of more use when the size of the file is large and the index
small. It makes the task easy by searching in index rather than the file
itself. The index sequential organization is a fusion of index and sequential
file organization. The access module of the method searches its record in
an index to identify the location of the disk. The file can be located only if
it is presented inside a file.

For locating records of this type, a smaller index is preferred than a pure
index because this index holds entries only for certain key values and are
more effective in tracing a record thus resulting in the proper functioning
of the I/O device. However, large file index still has large number of
entries increasing the time of searching eventually. A higher level of index
is one that directs the search straight to the section of a disk containing the
intended record. This sequential search helps to save time in location of
the file in a record.

The index sequential file organization is a hybrid organization that


combines elements of the indexed and the sequential file organizations. To
locate a desired record, the access method module for this organization
searches an index to identify a section of the disk that may contain the
record and searches the records in this section of the disk sequentially to
find the record.

The search succeeds if the record is present in the file; otherwise, it results
in a failure. This arrangement requires a much smaller index than does a
pure indexed file because the index contains entries for only some of the
key values. It also provides better access efficiency than the sequential file
organization while ensuring comparably efficient use of I/O media.
Operating Systems

For a large file, the index would still contain a large number of entries, and
so the time required to search through the index would be large. A higher-
level index can be used to reduce the search time. An entry in the higher-
level index points to a section of the index. This section of the index is
searched to find the section of the disk that may contain a desired record,
and this section of the disk is searched sequentially for the desired record.

Access Methods

An access method accesses a set of files by employing a distinct file


organization. This method uses an IOCS module. A file organization
decides the methods to access a record whether by a sequential search or
address calculation. It also uses higher techniques like Buffering and
blocking of records in I/O programming to make it more potential.

Buffering of Records

Transitory memory spaces in a system are called Buffers that read a record
of a file in advance even before the process is required. Buffering acts
earlier to eliminate the need for an I/O device to complete its operation.
This process is delayed when the intended record is absent in a buffer.
When the write command is delivered the data copies the file into a buffer
allowing it to proceed with its operation. The date is written on the I/O
device eventually and the buffer is released for the process again. The
process is delayed only if the buffer is absent during write operation.

Blocking of Records

The access method is involved in reading/writing a huge number of data


containing multiple file records from or to the I/O medium. This action
facilitates the I/O operations to function potentially, lessening the time
needed for the I/O to process its file. Blocking enables the I/O medium to
function at a large scale across a device.

Directories

A directory contains information about a group of files. Each entry in a


directory contains the attributes of one file, such as its type, organization,
size, location, and the manner in which it may be accessed by various users
in the system.
Operating Systems

Figure 4.4: Fields in a typical directory entry

Figure 4.4 shows the fields of a typical directory entry. Open count and
Lock fields are employed when multiple processes open a file
simultaneously.

1. Open count: It denotes the number of processes. In an open count


a metadata is stored in a file system for the purpose of increasing
the search speed on a condition of non-zero in a count.

2. Lock fields: Employed for a selected access to a file.

3. Flags: It distinguishes one directory entry from the other. Value


‘D’ in the field denotes directory, ‘L’ denotes link and ‘M’ denotes
a file system that is mounted.

4. The Misc: Information concerning file’s owner, time of creation,


and last modified are stored here.

A file system hosts files authorized by various users. Hence, it is crucial


that it grants its users two exemptions:
Operating Systems

● File naming freedom: A user must be given liberty to name their file
without conditioning.

● File sharing: Freedom to access and share files of various users.

A file system takes aid of directory structure to create and manage


various directories. As shown in figure 4.5 the directory is depicted as a
rectangle and file as a circle.

Figure 4.5: A directory structure composed of master and user


directories.

Figure 4.5 is a basic directory structure of two types.

1. User directory (UD): Entries detailing the files owned by a single


user.

2. Master directory: Information of all UDs registered in a system.

In the above file system, users A and B have named their respective file as
beta. These users are registered in their respective UDs associated with.
Figure 4.5 is a two-level directory structure. Use of separate UDs is what
provides naming freedom. When a process is created by user A, it executes
the statement open (beta, ...), the file system explores the master directory
to locate A’s UD along with beta in it.

If the statement open (beta, ...) is being executed by some process created
by B, the file system would search B’s UD for beta. This construction
ensures that the correct file is accessed besides various files with identical
names existing in the system. However, UDs obstruct Users from sharing
their file with others, for users to share their file a distinct system is to be
created to enable file protection does its job.
Operating Systems
A file system will decide if the User C is allowed to access A’s file beta.
This action is permitted by examining the protection info field of beta’s
directory.

Directory Trees

The 1960’s MULTICS file system enabled users to create their own file
and directory of any desired level also to name their file of their choice.
Figure 4.6 demonstrated is a directory structure represented in the form of
a tree.

Figure4.6: Directory trees of the file system and of user A.

A user creates a file to store data or these files act as a directory such files
are known as data files and directory files or simply directories. Every file
system supports a directory called root that holds a home directory for each
user and these files are directory files named after the concerned user. A
user constructs information in a home directory by building directory files
and data files in the flag field, the file entry is represented as D in the file
system if a file is a directory file.

As shown in the above figure 4.6 the root tree is a directory root leading
to the home directory for a user that holds a username. For example, user
A has built a file called alpha and the directors are named as admin and
projects. The project directory is followed by a real-time directory
constituting a file Main_pgm, therefore user A has a built the directory of
their own.
Operating Systems

The user’s specific directory “in” can be changed at any time and is called
current directory. When the user desires to access a file, the process is
carried out in a directory. The user is directed to the home directory by
the OS on logging inside the system. The home directory becomes the
user’s current directory and can be modified with the “change directory”
command.

It is impossible for a file to have a unique name in a file system hence a


user or process uses the path name to search explicitly. A path name is an
arrangement of one or more path components separated by slash (/)
directory of their own where each path component is a reference through
a directory and the last path component is the name of the file.

Relative path names help locate a file from a current direct as they are
short and comfortable in usage. But at the same time it can create chaos
when files are accessed from various current directories. For instance in
figure 4.6 the file alpha has a single relative path named Alpha, on
searching from the current directory while it has path name ../alpha and
../../alpha on searching from directories projects and real_time
respectively.

A file’s name may not be unique in the file system, so a user or a process
uses a path name to identify it in an unambiguous manner. A path name is
a sequence of one or more path components separated by a slash (/), Path
names for locating a file from the current directory are called relative path
names. Relative path names are often short and convenient to use;
however, they can be confusing because a file may have different relative
path names when accessed from different current directories. For example,
in Figure 4.6, the file alpha has the simple relative path name alpha when
accessed from current directory A, whereas it has relative path names of
the form ../alpha and ../../alpha when accessed from the directories projects
and real_time, respectively.

For relative path names to function effectively each directory stores


information of its own parent directory in the directory structure. The
absolute path name of a file begins on the root directory of the file system’s
directory tree. Files with same names built in different directories differ in
their absolute path names. We will use the convention that the first path
Operating Systems
component in an absolute path is a null symbol, and the home directory of
a user A is specified as˜A. Thus, in Figure 13.8, the absolute path name of
file alpha is /A/alpha. An alternative path name for it is ˜A/alpha.

Operations on Directories

A search being the most chronic operation on directories. Several other


operations on directories are maintenance operations like creating or
deleting files, renovating file entries when a process performs a close
operation, record a directory, or cut out a directory. The deletion operation
specifies a path name for the file to be erased. It turns to be complex when
the directory structure is a graph because a file may have numerous
parents. A file is deleted if it has a single parent; or it's just made remote
from its parent directory in the path name specified in the delete command.
To clarify the delete operation, the file system sustains a link count with
each file. The count is set to 1 when the file is generated, gained by 1
whenever a link is set to point to it, and drained by 1 at a delete command.
The file can be removed when its link count is set off to 0.

This easy plan of action is not enough if the directory structure contains
cycles. A cycle starts when a link is set from a directory to one of its former
directories, e.g., if a link is set up from the directory real_time in Figure
4.6 to the directory plan. Now the link count of projects is 2, so its removal
by using the path name ˜A/projects would only guide the cut of the entry
of projects in A. Yet, there is no cause to keep directory projects and files
accessible from it, since projects would not be reachable from the home
directory of any user! This problem can be resolved either by using a
technique to discover cycles that are unreachable from any home
directories, which can be valuable or by stopping cycles from appearing in
the directory structure, which is fairly extortionate.

Organization of Directories

A directory may be a flat file that is looked directly to note the needed file
entry. Yet this organization is unfit if the directory consists of a massive
number of entries. Hash tables and B+ trees are too old to allow a vast
search power.
Operating Systems

Mounting of File Systems

A File system composed on a logical disk of an operating system i.e, it is


found in the divisions of a disk. A mounted file system is the only way to
enter a file constituted in a file system. The mount operation “connects''
the file system to the system’s directory structure. Operations can’t be
performed for an unmounted file system and this is supervised by the
system administrator. Mounting and mounting partially contribute to
secure files in a file system. Mounting creates an equal effect
corresponding to that of a link. A mount is transitory in altering the
directory structure as the impact of it survives only for a mounted file
system or till the system restarts. Mounting file systems is convenient to
access multiple file systems in the OS or if the user desires to access files
stored in a remote machine over a distributed system. The point of
mounting a file system in a directory is called a mount point. It's achieved
by delivering the command mount (<FS_name>, <mount_point_name>)
both are names of a path which determine the root of the file system to be
mounted along with the mount point. On initiating operation mount the
root of the mounted file system assumes the name <mount_point_name>.
Hence, any file with the relative path name api in the directory <FS_name>
will be permitted by the path name <mount_point_name>/api. File
directories with already existing files become invisible if they are mounted
and can be viewed again on unmounting the file system.

File Protection

Controlled sharing of files is restricting the sharing of a file other than


collaborators by a user. This system works by specifying the users list and
the ways of access by the owner. The file system stores this information in
the protection info field of the file’s directory entry and using it to limit
access to the file.

An access control list (ACL) serves this purpose. Every element of the
access control list is an access control pair of the form (<user_name>,
<list_of_access_privileges>). On initiating the operation by a random user
X tries to perform an operation <opn> on file alpha, the file system looks
for the pair with <user_name>= X, in the access control list of alpha and
locates whether <opn> is stable with the <list_of_access_privileges>. If
Operating Systems
not, the attempt to access alpha is a debacle. For example, a write attempt
by X will fail if the entry for user X in the access control list is (X, read),
or if the list does not contain an entry for X.

The number of users and the access privilege determines the size of the
Access- control list. The size can be constrained on grouping the users in
a specific way and assigning access control pair for user class rather than
an individual user, thus access control list will have its users in pairs.

A user in a file system is granted access of three kinds:

1. Read: it permits users to fetch a list of a directory.

2. Write: It lets users create and alter data in a file. In a directory


write operation permits a user to generate a file of their own.

3. Execute: It allows users to implement a process in a file and


permits access in a directory.

An Append is a novel access privilege which increases the size of a


protection information.

4.2.4 Logical File System

Logical files are a delineation of a record found in one or more physical


files constituting more than a single format known as Multi-format logical
files. It is a view or representation of one or more physical files and doesn't
carry data as such. The file system presents the abstraction of a logical file
to the user and defines a set of operations to use and manipulate these. It
also provides a way to organize individual files into groups and to keep
track of those using directories. Typically, a file can be identified using
two forms of names, depending on the operation to be performed on that
file. A symbolic name, chosen by the user at file creation, is used to find a
file in a directory.

It also is used when manipulating the file as a whole, e.g., to rename or


delete it. Symbolic names, however, are not convenient to use within
programs, especially when used repeatedly. Thus, operations that access
the file data (notably read and write operations) use a numeric identifier
for the file. This is generated by lower levels of the file system. When a
desired file is first opened by setting up data structures necessary to
facilitate its access, an identifier, the open file ID is returned and used for
Operating Systems

subsequent read, write, and other data manipulation operations. Note that
the symbolic name remains valid even when the file is not in use, whereas
the open file ID is only temporary. It is valid only when the process that
opened the file remains active or until the file is explicitly closed.

The logical file system deals with all of the meta data associated with a
file (UID, GID, mode, dates, etc.), i.e. everything about the file except the
data itself. This level manages the directory structure and the mapping of
file names to file control blocks, FCBs, which contain all of the meta data
as well as block number information for finding the data on the disk.

4.2.5 Physical File System

Physical files are repositories of data in a system. They also have details
concerning manners of data to be presented to or received from a program.
Physical files have only a single format with multiple users. Records in a
database file can be described using either a field level description or
record level description.

Physical versus Logical Files:

Physical File: A collection of bytes stored on a disk or tape.

Logical File: A “Channel” (like a telephone line) is anonymous of a file’s


location and physical format of a program.

An OS looks for a physical file known as data '', on receiving a command


from a program, the operating system delegates a logical file derived by
naming a file logical. Thus, a created logical file is employed in a program.

Physical File Logical File

Part of a memory constituting real Not a part of a memory space


data that does not have data

A physical file has a single record Ability to have 32 record


format formats
Operating Systems

It cannot exist without a


It can exist without a logical file physical fil.

If there is a logical file for a physical If there is a logical file for a


file, the physical file cannot be physical file, the logical file
deleted until and unless we delete the can be deleted without deleting
logical file the physical file

Table 4-2: Physical versus logical files:

4.2.6 Allocation Strategy Module

An Operating system constitutes files with allocated disk spaces. There are
multiple methods employed to assign disk space to the files. An ideal
allocation method will drastically affect the performance and efficiency in
a system. Allocation method instructs the ways off approaches in utilizing
and accessing a file in a disk.

Space allocation methods are of various kinds:

● Contiguous Allocation.

● Extents

● Linked Allocation

● Clustering

● FAT

● Indexed Allocation

● Linked Indexed Allocation

● Multilevel Indexed Allocation

● Inode

Some of the popular methods are:

Linked Allocation, Indexed Allocation, Contiguous Allocation, and


File Allocation Table

Linked Allocation: In this method,


Operating Systems

● Each file has a list of links.

● The directory contains a link or pointer in the first block of a file.

● The method rejects external fragmentation.

● This method is also employed along with sequential access files.

● This method does not support direct access.

Linked List allocation aids in tackling issues arising in contiguous


allocation. In a linked list allocation, every individual file is associated
with disk blocks of a linked list. However, each disk allotted to a specific
file must be transmittable on the disk. A pointer is present in every disk
block pointing to the adjacent disk allotted in the same.

Figure 4.7: Linked list allocation.

Advantages

• There is no external fragmentation with linked allocation.


• Any free block can be adopted to satisfy the file block requests.
• File can continue to generate by using available free blocks.
• Directory entry will only contain the starting block address.

Disadvantages

• Random Access is not available.


• Pointers demand space in the disk blocks.
• A file might get corrupt if the pointers in the linked list are
broken.
• Need to negotiate each block.

Indexed Allocation: In this method,

• Directory constitutes addresses of index blocks of specific files.


Operating Systems
• An index block is created, having all the pointers for specific
files.
• All files should have individual index blocks to store the
addresses for disk space.

Setbacks in an existing technology fosters new development besides


various allocation methods. They still have their own pros and cons. File
allocation tables faces a debacle as they tend to increase the size of FAT
with the rise in block numbers, this creates a need to assign more area to a
file allocation table. This task becomes impractical as the file location table
requires cache. It becomes unachievable to create space in a cache.

This can be resolved by employing an Index allocation scheme that


eliminates the need to maintain disc pointers in a file allocation. An
indexed block stores pointers to a given disk block entry.

Figure 4.8 Indexed allocation.

Advantages

• Permits a direct access.


• A defect in a data block affects only its respective block.

Disadvantages

• A failure index block can destroy the whole file.


• Size of a file corresponds to the number of pointers an index
block can hold.
• A small file for an index block is unnecessary.
• Multiple pointer overhead

Contiguous Allocation: This method allows,

• Users to occupy adjacent address space on memory to all files.


Operating Systems

• The OS allotted the disk address in a straight order.


• External fragmentation is a concern in the contiguous allocation
method.

Allocation of logical files in a manner that blocks in a file receive


contiguous physical blocks in a hard disk this form of allocation is called
a contiguous allocation.

Figure 4.9 below demonstrates a directory with three files. The tables
describe the starting block and the required length for each file. As shown
below in the table the contiguous blocks are allocated to each file as per
its requirement.

Fig.4.9 Contiguous allocation.

Advantages

• Easy implementation.
• Hits Excellent read performance.
• Permits Random Access into files.

Disadvantages

• Possibilities of disk getting fragmented.


• Curbs the fostering of a file.

File Allocation Table:

The major impediment for a linked list allocation is that the random access
to a particular block is not permitted. To access the file, it requires access
to all its previous blocks. File allocation table resolves this issue with the
aid of linked list allocation. This method works by collecting links of all
Operating Systems
disk blocks and permits single entry for each disk block with its block
number indexed in the table. A file allocation needs proper cache to lessen
the attempt of head seeks. A head need not negotiate with disk blocks to
access a successive block. It can plainly procced to its desired block entry
and access a block in the file allocation table. This method was earlier
adopted by FAT to establish a random access in the earlier version of MS-
DOS and Windows versions.

Fig.4.10 File Allocation Table.

Advantages

• Uses the whole disk block for data.


• one ineffective disk block does not affect the loss of all
successive blocks.
• Permitted random access yet constrained search.
• Only FAT requires traversing in each file operation.

Disadvantages

• FAT entry mandatory for all disk blocks.


• the size of a FAT is determined by the number of FAT entries.
• Number of FAT entries can be limited by increasing the block
size, but it will also increase internal fragmentation.
Operating Systems

Allocation of Disk Space

A disk space allocation facilitated by a file system constituting a file


divided among its own disk. An IOCS fails to recognize such partitions
and hence it is performed by disk space allocation. Previously, every file
system used a contiguous memory allocation model by assigning a single
contiguous disk area on creation.

Advantages and disadvantages of a contiguous allocation model are as


follows:

• Easy execution.
• Efficient access to data by constraining disk head movement in
the time of sequential access to data in a file.
• Besides the efficiency of the model, it increases the chances of
external fragmentation.
• Surprisingly, internal fragmentation of the disk block occurred as
the file system judiciously allocated some extra disk space to
allow for a file expansion.

Contiguity of disk space leads to complicated arrangements to escape bad


disk blocks. The file system identifies the bad disk blocks while formatting
the disk and notes their addresses.

It then allocates the substituted disk blocks for error causing ones and
constructs a table indicating addresses of bad blocks and their substitutes.
When read/write operation is carried the IOCS cross checks the disk block
accessed if it is a bad block and collects the address of the substitute disk
block to access it.

Modern file systems employ the noncontiguous memory allocation model


to disk space allocation. This approach provides a lump disk space when
the file is created or if its size grows because of an update operation. The
file system acknowledges the following concerns while implementing this
approach:

● Managing free disk space: it has to monitor free disk space and
make use of it when a file requires a new disk block.
Operating Systems
● Avoiding excessive disk head movement: Verify if the data in the
file are not escaping to various parts of a disk because this might lead
to unnecessary movement of the disk heads during file processing.

● Accessing file data: Keep track of disk space allocated to a file and
use it to find the disk block that contains required data.

The file system manages a free list of disk space and allocates it on
demand, i.e supplying it to the required disk block. This method can be
substituted by a table called the Disk Status Map (DSM)denoting the status
of disk blocks. If DSM lets the disk block for an entry it means the disk
block is vacant. This information can be retained in a single bit, and so a
DSM is also called a bit map.

Figure 4.11 below is a demonstration of DSM. 1 in an entry denotes the


corresponding disk block is occupied. The DSM is called upon with every
allocation of a new disk block.

Figure 4.11 Disk status map (DSM).

To restrain data from getting divided among the parts of the disk, the file
system restricts its disk space allocation for a file by directing it to its
successive disk block extension and to cylinders forming a cylinder group.
A DSM is comparatively effective over the free list as it effortlessly adopts
disk blocks from an extension or cylinder group. Two basic methods to
noncontiguous disk space allocation are Linked Allocation and Indexed
Allocation.

They differ in the ways they manage information about disk space
allocated to a file.

Linked Allocation

A file is rendered by a linked list of disk blocks with two fields in each file
—data and metadata. The data field contains data to be stored on a file
Operating Systems

whereas metadata field is the link constuting the address of the successive
block to be allocated into the file.

Figure 4.12 Linked allocation of disk space

Figure 4.12 above illustrates linked allocation. As shown in the figure 4.12
the directory alpha composing the field, location info is connected to the
first disk block of the file. Vacant blocks are accessed by remaining
pointers in the list of disk blocks. The last disk block contains null
information in its metadata field. Therefore, the file alpha is composed of
disk blocks 3 and 2, while the file beta consists of blocks 4, 5, and 7. Free
space on the disk is denoted by a free list in which each free disk block
holds a pointer to the following free disk block. A disk block is removed
from the free list and included to the file’s list of disk blocks to store new
data in a disk block and vice versa to delete a file.

Linked allocation is effortless in execution and sustains a low


allocation/deallocation overhead. It is efficient in working along with
sequential files but files with nonsequential organization are ineffective. It
also involves risk of losing the entire data in a disk block if metadata incurs
error, hence its inappropriate to trust a linked allocation. The condition
goes the same with a corrupted pointer in a free list.

File Allocation Table (FAT): MS-DOS uses a modified form of linked


allocation that stores the metadata separately from the file data. A file
allocation table (FAT) of a disk is an arrangement composed of a single
element corresponding to each disk block in a disk. For a disk block that
is allocated to a file, the corresponding FAT element contains the address
of the following disk block. Thus, the disk block and its FAT amalgamated
to form a pair that contains information found in the disk block in a
classical linked allocation method.
Operating Systems
The directory entry of a file contains the address of a first disk block with
its respective address followed by the FAT element of the second disk
block with the address of the second disk block, and so on. The FAT
element found in a last disk block holds a special code to denote the end
of a file on a disk block.

Indexed Allocation

A file map table (FMT) that constitutes an index managed to record the
addresses of a disk block allocated to a file. To put it plainly FMT is a list
of disk block addresses. Every disk block is composed of a single field
called disk field. The location info field of a file’s directory entry is
conducted to the FMT of a file.

Figure 4.13 Indexed allocation of disk space

The file alpha holds fmtalpha as its notation for the FMT of. If the file
alpha enlarges in its size, the DSM searches to find a free block, and the
address of the block is included to fmtalpha. Deallocation occurs on
deleting the alpha. Before the deletion of an alpha every disk blocks are
directed to a fmtalpha and are noted as free. An indexed allocation can be
dependent on a large scale since errors in an FMT reflect damage in less
number in comparison to a linked allocation. In terms of accessing records
in a file the direct-access file is quite convenient against a sequential-file
access and linked allocation as it reduces the need to visit a FMT to acquire
the address of the next disk block. For files with less data the FMT can be
stocked in the directory entry of the file as it is convenient and effective.
For bigger files, the FMT is hard to confine it into the directory entry and
this can be resolved by assigning a two-level index. To serve this purpose
of a two-level index each entry of the FMT must hold the address of an
index block with no data as such.
Operating Systems

An index block has addresses of data blocks as its only component. An


entry of the FMT is the only method to access the data block and address
of an index block. This structure of index block reflects a multilevel page
table. The index block echoes pages of a page table for the file, and the
FMT follows a higher-level page table making it compressed thus
addressing the issue of large files finding space in directory entry. The
speed of access is impeded since it is a two -level index.

There are exceptional file systems that involve a hybrid FMT organization
blending both characteristics of classical and multilevel indexed
allocation. A major boon of this structure is files of minimum data or less
data blocks function effectively and are accessible as the concerned FMT
eliminates the use of index blocks. Medium and large size files suffer a
minimum degradation of their access performance because of multiple
levels of indirection.

Performance Issues

A disk block as following problems in terms of performance:

● The unit of disk space allocation regarding the size of a metadata.


i.e., the control data of the file system.

● Efficiency of using file data.

These problems can be overcome by employing a bigger unit of allocation


of disk space. A modern file system employs an extension called a cluster,
as a unit of disk space allocation. An extent is a group of successive disk
blocks using bigger extensions to access files in a better way on the other
hand causing increased internal fragmentation. To balance these issues,
file systems go for variable extent sizes with the metadata containing an
extent along with its address.

File System Reliability

File system reliability is the level of potential to which a file system


reflects a linear progress encountering power break causing program
failure and data loss. The two goals of file system reliability are:

● Proper working of file creation, deletion, and updates.

● Protecting data in files.


Operating Systems
The former deals with consistency and correctness of metadata, i.e., the
control data in a file system, while the latter concerns consistency and
correctness of data stored in files. Reliability narrative exists between the
terms fault and failure. A fault is a deficiency in a system while failure is
inaccurate behaviour of a system. Fault and failure coexist as fault leads
to failure. A damaged disk head or power interruptions causing a data loss
is a failure while being invisible about a faulty block is a failure in some
part of the system.

Check Your Progress-1

1. Why are allocation strategy modules important in file systems?

__________________________________________________________
__________________________________________________________
________________________________________________________

2. How does an allocation strategy module handle file creation and


allocation?

__________________________________________________________
__________________________________________________________
________________________________________________________

3. What factors influence the choice of allocation strategy in a file system?

__________________________________________________________
__________________________________________________________
________________________________________________________

4.3 DEVICE STRATEGY MODULE

Read/write are basic commands but a direct access device looks for an
added I/O commands, like "seek" and "search", for ideal positioning. The
POSM and ASM involve only the logical read/write which helps transport
a group of command requests to the DSM of the form: "read record 24 into
location 5400, read record 49 into location 6400, and write record 27 from
location 9324". The work of DSM is to convert such commands into an
obscure I/O list format needed for the particular device.
Operating Systems

Further, features like latency and access time of a device confuses the
order of execution thus affecting the total amount of time in which a device
is kept "busy", for instance, if records 24 and 27 are "closer", in some
sense, to each other than record 49, it can very well-read record 24, write
record 27, and then shift to read record 49. The Input/Output Control
System pills together all the physical I/O on the computer. Nowadays,
modern computers depend highly over physical independent I/O devices
eventually leading to complexity over such coexistence among devices.
This is because of the dedicated nature of "selector" channels and device
control units with the liberty to jump between devices but provides only a
single service per device with one sitting. But this is impossible for devices
with high-speed like drums that are highly dependent over access time for
its main storage. Multiple processing of memory requests lead to
"overrun" causing inappropriate data transmission. The IOCS checks over
the status of all devices, control units, and channels. When an I/O
operation is requested, the IOCS ensures a smooth path to the device
through the channels and control units and to keep in control of the limit
of I/O capacity. If it fails to execute the request on issuing the command,
the IOCS stores the request on a queue and will be processed eventually
on adhering to the conditions.

An I/O interdependency among all devices is inevitable therefore each I/O


operation must check if the file system or dedicated special purpose device
must be directed through the IOCS.

Because of this reliability faults equally exist with them. But they can be
recovered, and the process is quite simple. During these times the IOCS
will initiate its repair process. The IOCS comes into action for the
following contexts with an I/O request, for example (1) successful
completion. (2) unrecoverable error condition, or (3) asynchronous
interrupt. The sophistication and scope of the IOCS defends upon the
devices to be handled and the goals of the file system and operating
system.
Operating Systems

4.4 I/O INITIATORS

As seen in previous chapters a module in a file system processes the input-


output control system (IOCS) along with the file system enabling users to
name, share and trust their files, indeed security. Operations are carried
out by the IOCS. The target for the IOCS is to impart the process
effectively and to have a high level of process for the entire I/O devices.
The access method and the physical methods are two layers created to
address this rising concern with IOCS. The former method manages
reading and writing of data and makes it function efficiently. It triggers
the physical IOCS to perform actual reading and writing of data. The
physical IOCS performs input-output at the I/O device level and
implements scheduling policies to enliven the process in the whole of an
I/O device.

Layers of the Input-Output Control System

Figure 4.14 Implementation of file operations by the IOCS.

The schematic of Figure 4.14 demonstrates the working of the input-output


control system (IOCS) processing file operations. Processes Pi and Pj are
involved in file processing activities and have already approved access to
some files. When either of these processes requests a read or write
command to a file, the IOCS receives the request through the file system.
It then stores a set of data files in memory spaces called buffers, the file
cache, or the disk cache to accelerate the file processing. For a read
operation, the IOCS looks if data required to process the file is present in
memory or not. If the memory is absent, the IOCS issues further I/O
operations to check for data stored as memory in a file buffer or the disk
cache and wait for the I/O to complete its job. This is not needed for the
process if data is stored in memory.
Operating Systems

If the I/O operations function simultaneously at various levels but disposes


in the scheduled time using a scheduling algorithm focusing to deliver
large throughput of the disk. Thus, the IOCS implements I/O operations in
a manner that provides efficiency of file processing activities in processes
and high throughput of I/O devices.

The IOCS’ dual two layers are the access method and the physical IOCS.
The former layer focuses to deliver efficient file processing and the later
aims for high device throughput. These two layers of the IOCS address
flaws in the efficient implementation of file operations from device-level
concerns.

Figure 4.15 Layers of the file system and the IOCS.

Figure above illustrates the pecking order of file system and IOCS layers.
The number of IOCS layers and their interfaces differ in accordance with
operating systems. Lately, many operating systems, used part of a Kernel
for the physical IOCS. But modern operating systems used the external
part of a kernel to improvise extensibility and reliability of the OS. The
system cells trigger the physical IOCS which in turn evokes other
functionalities of the kernel.

Physical • Mechanisms: I/O initiation, listing downI/O operation


IOCS status, I/O completion processing and resolving
errors.
• Policy: Optimization of I/O device performance
through scheduling algorithm and a disk cache.
Operating Systems

Access • Mechanisms: File open and close, read and write.


methods • Policy: Optimization of file access performance
through buffering and blocking of file data and use of
a file cache.

File System • Mechanisms: Allocation of disk blocks, directory


maintenance, arranging and keeping track of file
protection information.
• Policies: Disk space allocation for access efficiency,
sharing and safeguarding files.

Table 4-3: Mechanisms and policies in file system and Iocs layers

Table 4-3 above presents in a nutshell of significant mechanisms and


policies implemented by IOCS layers in a conventional two-layer IOCS
design. The physical IOCS layer implements device-level I/O. Its policy
modules work in a scheduled manner in which I/O operations should be
performed to achieve high device throughput. These modules trigger
physical IOCS mechanisms to implement I/O operations. The policy
method of an access method layer is efficient file processing and
mechanisms implemented through a file-level I/O by using physical IOCS
policy modules. The function of a file system layer is to enable sharing
and protection of files with the aids of the modules in an access method.

Table 4-3 summarizes the possible mechanisms that can be delivered and
sensibly accessed by a higher layer. Other mechanisms, which are
“private” to a layer, are not listed here. For example, mechanisms for
buffering and blocking of file data, and for maintaining a file cache are all
listed in the policy module of an access method layer hence they are
restrained from accessing straight from the file system layer. Likewise, the
physical IOCS curbs the access outside a physical IOCS layer maintaining
a disk cache.

I/O ORGANIZATION:

Three modes performing an I/O operation are:

1. Programmed mode,

2. Interrupt mode, and


Operating Systems

3. Direct memory access (DMA) mode.

Every I/O device is linked to device controllers holding an exclusive


numeric ID and these devices are successively linked to the DMA
controller. Devices linked to each device's controllers too have an
exclusive ID with a device address in a duo from (controller_id,
device_id). An I/O operation involves the following details:

● Operation to be performed—read, write, etc.

● Address of the I/O device.

● Number of bytes of data to be transferred.

● Addresses of areas in memory and on the I/O device involved in


the data transfer.

DMA mode comes into play when an I/O instruction is Implemented by


an I/O operation. The effects of an I/O instruction are spread along the
CPU, the DMA and the device controller. However, the CPU has no job
of transferring data between an I/O device and memory. The I/O
instruction channels its command from an I/O that mentions task found in
the data transfer. An I/O command execution cannot be performed without
the aid of the DMA controller. But a CPU is devoid of such help from the
device controller and the I/O device. Therefore, the CPU can perform the
other I/O instructions without impediments alongside the I/O operations.

In general, I/O commands are recorded in memory and the address of the
memory space are executed when the I/O instruction requires it
(exceptions are when the address is used from a standard memory location)
During the operation of an I/O instruction, the CPU delivers the picked-up
address to the DMA controller and thus it is now under the effect of the
I/O commands.

I/O DEVICES

I/O devices work with a variety of principles like electromechanical signal


generation and electromagnetic or optical data recording. I/O devices
operate with different I/O media, serve different purposes, and maintains
and access data in variety of ways hence they can be categorized based on
their functions such as its:
Operating Systems
● Purpose: Input, print and storage devices.

● Nature of access: Sequential and random-access devices.

● Data transfer mode: Character and block mode devices.

The information written (or read) in a single I/O command becomes a


record. sequential-access devices are a keyboard, a mouse, a network, and
a tape drive. These devices work in a linear way to use its I/O medium;
therefore, all of its operation is performed with its corresponding record of
an earlier operation. Apart from this, access to any other data demands a
separate command to escape the intervening records. A random-access
device can function its read/write operation on any place of the record
unlike sequential access record. Disks can be accessed in both sequential
and random manner.

A unit of I/O medium is called an I/O volume; thus, a tape cartridge and a
disk can be called a tape volume and a disk volume, respectively. I/O
volumes for some I/O devices can be removed. eg: floppy disks, compact
disks (CDs), or digital audiotape (DAT) cartridges on the other hand hard
disks can’t be removed from the I/O devices.

DEVICE-LEVEL I/O

In Execution of an I/O at the level of an I/O device has the following


functions:

1. Implementing an I/O operation,

2. Performing read/write operations,

3. Keep track of status of I/O device,

4. Managing interrupts raised by devices.

The first three functions are performed through I/O instructions and I/O
commands. Table 4.4 is a description of features in the computer system
facilitating these functions:

Function Description of computer system


facilitating the features

Initiating an I/O operation The I/O instruction I/O-init (cu, d),


command_address commences an I/O
Operating Systems

operation. The I/O-init instruction sets a


condition code to denote if the I/O operation
has been implemented successfully.

Performing read/write Device-specific I/O commands execute tasks


like positioning of read–write heads over a
record and reading of a record.

Checking device status The I/O instruction I/O-status (cu, d) obtains


status information for an I/O device. The
information informs whether the device is
busy, free, or in an error state, and cause of the
error, if any.

Handling interrupts The interrupt hardware implements the


interrupt action. The CPU is switched to the
physical IOCS when an I/O completion
interrupt occurs.

Table 4-4: Computer system features supporting functions in device-


level I/O

To understand two key aspects of I/O programming—namely, I/O


initiation and I/O completion processing, which is an assembly language
version of the following program in a higher-level language:

read a, b;

...

result := a + b;

The program uses a bare machine, i.e., a computer system devoid of


software layers between the program and the machine’s hardware. The
flag IO_FLAG denotes the running status of the I/O operation and if it is
IO_FLAG to 1 this will commence an I/O operation and loops until the
I/O operation completes before performing its computations.

I/O Initiation: When the I/O-init command is implemented, the CPU


transmits the device address to the DMA controller.
Operating Systems
The DMA controller looks for the availability of I/O operation to perform,
and informs the CPU; accordingly, the CPU creates an appropriate
condition code in the condition code field (also called the flags field) of
the PSW. If the device is available, the DMA also starts the I/O operation
by accessing and decoding the first I/O command. The I/O operation, if
initiated, will proceed in parallel with the CPU’s execution of instructions.

4.5 DEVICE HANDLERS

The function of a physical IOCS is to simplify the code of user processes


and by disentangling complexities of an I/O operations and to provide high
system performance. It is achieved through the following three functions:

• Handling device-level I/O: The physical IOCS provides an


interface for device level I/O to rule out the complexity of I/O
programming.
• Synchronizing a process with completion of an I/O operation:
This synchronization eliminates the need to hold its process for
the I/O to initiate and release the CPU for use by other processes.
• I/O scheduling: The physical IOCS performs in a scheduled
linear order to provide high device throughput.

Handling Device-Level I/O- While requesting initiation of an I/O


operation, a process needs to specify only the device address and details
of the I/O operation. The physical IOCS initiates an I/O operation
immediately if the I/O device is available; otherwise, it notes the request
for I/O initiation and initiates it sometime later. In either case, control is
returned to the process that made the I/O request.

When an interrupt arises, the physical IOCS notes which I/O operation has
completed and initiates another operation on the I/O device, if one is
pending.

Synchronizing a Process with Completion of an I/O Operation The


physical IOCS provides an “await I/O completion” functionality to block
a process until an I/O operation completes. Its parameters are the address
of the I/O device and details of the I/O operation. When a process invokes
this functionality, the physical IOCS checks whether the I/O operation has
Operating Systems

already completed. If it has not, it requests the kernel to block the process.
This action avoids the busy wait. The state of the process is changed to
ready when the I/O operation completes.

I/O Scheduling The throughput of an I/O device can be computed as the


number of bytes of data transferred per unit time, or the number of I/O
operations performed per unit time. Throughput can be optimized by
minimizing the access times suffered during I/O operations. In disk
devices it can be achieved by reducing the rotational latency and
mechanical motion of disk heads by performing I/O operations in a
suitable order. This function is called I/O scheduling. It is performed
automatically by the physical IOCS; it is not explicitly invoked by a
process.

Logical Devices

A logical device is an abstraction that is employed for a variety of useful


purposes. In the simplest case, a logical device is merely a name for a
physical I/O device. Use of a logical device in the code of a process solves
a practical difficulty—the address of a physical device that a process will
use is not known when its code is written. While creating a process that
uses a logical device, the kernel assigns a physical device to the logical
device. When the process performs an operation on the logical device, the
physical IOCS implements the operation on the physical device assigned
to the logical device.

A logical device can also be a virtual device. In this case, the kernel has to
map the logical device into a part of a physical device.

Many logical disks may be mapped into a physical disk in this manner;
the I/O operations directed at the logical disks would all be performed on
the same physical disk.

Physical IOCS Data Structures

The physical IOCS uses the following data structures:

● Physical device table (PDT)

● Logical device table (LDT)

● I/O control block (IOCB)


Operating Systems
● I/O queue (IOQ)

The physical device table (PDT) is a system wide data structure. Each
entry in it contains information about one I/O device. The IOQ pointer
field of an entry points to the queue of I/O operations that are to be
performed on the device. Each entry in the queue is a pointer to an I/O
control block (IOCB), which contains information concerning one I/O
operation. The current operation field points to the I/O control block that
contains information concerning the I/O operation that has been initiated
on the device. This information is useful in processing completion of the
I/O operation.

The logical device table (LDT) is a per-process data structure. There is


one copy of the LDT for every process in the system; this copy is
accessible from the process control block (PCB) of the process. The LDT
contains one entry for each logical device used by the process. The field
physical device address in the entry contains information concerning the
current assignment, if any, for the logical device. Note that many logical
devices, possibly belonging to different user processes, may be assigned
the same physical device such as a disk.

An I/O control block (IOCB) contains all information pertaining to an


I/O operation. The important fields in an IOCB are logical device name,
I/O details, and status flag. The I/O details field contains the address of the
first I/O command. The status flag indicates whether an I/O operation is
“in progress” or “completed”; it is the equivalent of IO_FLAG.

The I/O queue (IOQ) is a list of all I/O operations pending on a physical
device. Each entry of the IOQ contains a pointer to an I/O control block.
Information in the IOQ is used for I/O scheduling.

4.5.1 Disk Scheduling

The time required to locate a disk block corresponds to the present position
of the disk heads. Thus, the cumulative time depends on the number of I/O
operations being performed. The throughput of a disk can be defined as
the number of I/O operations performed per second, along with the
sequence in which I/O operations are performed. Consequently, the
physical IOCS and device drivers for disks use a disk scheduling scheme
Operating Systems

to perform disk I/O operations in a desired order. The following are the
disk scheduling policies:

● First-come, first-served (FCFS) scheduling: Choose the I/O


operation that was requested first.

● Shortest seek time first (SSTF) scheduling: Choose the I/O


operation whose location time from the current position of disk heads
is the shortest.

● SCAN scheduling: This policy moves the disk heads from one
position of the platter to the other, providing I/O operations for blocks
on each track or cylinder before shifting to the other one. This process
is called a scan. When the disk heads shift from one end to the other
end of the platter, they tread in the reverse direction hence freshly
arrived requests are processed in a reverse scan. Look scheduling
reverses is the modified form where the direction of disk heads stays
in the same place when no more I/O operations can be serviced in the
current direction. It is also called the elevator algorithm.

Circular SCAN or CSCAN scheduling: This policy resembles a SCAN


scheduling, but it never performs a reverse scan; instead, it shifts the heads
back to that end of the platter from where they started and initiates another
scan. The circular look variant (popularly called C-look scheduling)
moves the heads only if the service is demanded in a final I/O operation in
a scan before commencing another scan.

The FCFS disk scheduling policy is simple in execution but does not
ensure efficient disk throughput. To implement the shortest, seek time first
(SSTF) policy, the physical IOCS uses a structure of the disk to calculate
the seek time of the disk block involved in an I/O operation provided the
current position of the disk heads. Thus, the SSTF policy is parallel to the
shortest request next (SRN) scheduling policy, so while it achieves good
disk throughput, it would have some I/O requests in hold. SSTF and the
various scan policies can be efficiently implemented if the IOQs are
balanced in a dealt order by a track number.
Operating Systems
Buffering of Records

To process the stored information in a sequential file using the physical


IOCS, a process initiates a read operation on a record by invoking the start-
io module and immediately invokes the await-io module to track if the read
operation is done. The await-io module blocks the process if the I/O
operation is not processed completely. Thus, the process suffers a wait
time for each record, which affects its performance. An access method for
sequential files lessens the wait times encountered because of buffering of
records, which tries to overlap the I/O and CPU activities in the process.
It is accomplished through two means:

● Prefetching an input record into an I/O buffer, or

● Post-writing an output record from an I/O buffer where I/O buffer, or


simply a buffer, is a memory area that is temporarily used to hold the
data involved in an I/O operation.

In prefetching, the I/O operation enables the read operation for the
upcoming record into a buffer that commences earlier even if the request
is not generated by the process—it may be started while the process is
engaged in processing the previous record. This arrangement overlaps a
unit of time spent in reading the next record processing alongside the
previous record, which lessens the wait time for the upcoming record. In
post writing, the record to be written is simply copied into a buffer when
the process issues a write operation and the process is allowed to continue.
Actual writing is performed from the buffer sometime later. It can overlap
with (a part of) processing of the next record.

Access Methods

An access method is used for efficient processing of a group of files that


use a specific file organization. For the fundamental file organizations, the
IOCS may provide access methods for the following kinds of processing:

• Unbuffered processing of sequential-access files.


• Buffered processing of sequential-access files.
• Processing of direct-access files.
• Unbuffered processing of index sequential-access files.
• Buffered processing of index sequential-access files.
Operating Systems

Access methods for buffered processing of sequential-access and index


sequential access files incorporate the buffering technique.

Disk and File Caches

A generic technique of speeding up access to file data is to use a memory


hierarchy consisting of a part of memory and files stored on a disk.
Memory would contain some parts of the file data stored on the disk; other
parts would be loaded in memory when required. In essence, memory
would function as a cache between files on the disk and processes. Both
physical IOCS and access methods use this principle. The physical IOCS
uses a disk cache, which treats all files stored on a disk uniformly and
holds some data of some files in memory at any time. An access method,
on the other hand, uses a file cache, which focuses on keeping some part
of the data in a specific file in memory. The access method maintains a
separate file cache for each file.

The unit of data kept in a disk or file cache is typically a few consecutive
disk blocks; for simplicity we assume it to be a single disk block. We will
call the memory area used to store a unit of data a buffer. The cache is thus
a collection of buffers managed in the software. Each buffer has two
parts—the header part indicates what data is contained in it, and the data
part contains data.

The header contains the following information:

• Address of the disk blocks from where data has been loaded in
the buffer.
• A dirty flag.
• Information needed for performing replacement of data in the
buffer, such as the time of last reference made to it.

When a process issues a read operation, it specifies the offset of the


required data in the file. The IOCS determines the address of the disk block
that contains the required data and searches the cache to check whether
contents of that disk block are present in a buffer. If so, the required data
is copied from the buffer into the address space of the process. Otherwise,
a I/O operation is initiated to load the data from the disk block into a buffer
in the cache and it is copied into the address space of the process when the
Operating Systems
I/O operation completes. When a process performs a write operation, the
IOCS checks whether contents of the disk block that contains old values
of the data are present in a buffer. If so, it copies the values to be written
from address space of the process into the buffer and sets the dirty flag of
the buffer to true. Otherwise, it copies the disk block address and values
of the data to be written into a new buffer and sets its dirty flag to true. In
either case, contents of the buffer would be written on the disk.

To facilitate speedy search in the cache, the buffer headers are stored in an
efficient data structure such as a hash table.

File Cache A file cache is implemented in an access method and aims to


provide efficient access to data stored in a file.

Disk Cache The disk cache is implemented in the physical IOCS or device
driver of a disk. Its purpose is to speed up access to data stored on the disk.

Unified Disk Cache

Besides disk or file caches, the OS also maintains, implicitly or explicitly,


another cache called the page cache present in the virtual memory handler.
Employing various caches might inflate the number of copy operations
that needs to be executed to access data stored on a disk. The time and
memory overhead introduced by multiple copy operations motivates use
of a unified disk cache.

Figure 4.17 is a conceptual view of the disk cache and the page cache. The
page cache stores all code and data pages of processes that are present in
memory, including pages of any memory-mapped files. A new page is
inserted into the page cache when page error occurs. The page size
contains disk blocks in fewer numbers hence, this operation involves
reading a few blocks from a program file or a swap file creating an I/O file
making the disk blocks performing read into the disk cache followed by
moving it into page cache. For a modified page to be deleted from
memory, the first step is to copy it into the disk cache and write it back
into the disk after a while. This process constitutes a two-copy operation
from page-in and page-out. one copy operation between a disk and the disk
cache, and another between the disk cache and the page cache. On
successful completion of the page in operation a two-copy page would be
found in memory until either of the copies is overwritten.
Operating Systems

Figure 4.17 Disk caching: (a) separate disk and page caches; (b)
unified disk cache.

Multiple copy operations on pages and duplicate copies of pages cause


performance problems. The amount of memory to be committed to each
cache is also a difficult design decision; it can affect performance of the
system because under commitment of memory to the page cache could
lead to either a reduced degree of multiprogramming or thrashing, while
under commitment to the disk cache would slow down file processing
activities because of frequent accesses to the disk.

Merging the two caches would solve these problems: duplicate copies and
multiple copy operations would be eliminated, and portions of the cache
committed to the two uses could be varied to adapt to changes in the
system workload.

A unified disk cache being one cache serves the dual purpose of paging
and file I/O. The file system looks upon files as paged objects on the disk.
It decomposes the byte offset provided in a read or write statement into a
page number and an offset into a page. It passes the page number to the
unified disk cache to ensure that the page is loaded in memory and uses
the offset into the page to copy the data between the unified disk cache and
the address space of a process. Page I/O continues to be handled as in
conventional systems because the unified disk cache is really a page cache.
Operating Systems
Check Your Progress-2

1. How does a device handler interact with the operating system?

__________________________________________________________
__________________________________________________________
________________________________________________________

2. How does a device handler handle device errors?

__________________________________________________________
__________________________________________________________
________________________________________________________

4.6 FILE MANAGEMENT

File management is defined as the process of manipulating files in a


computer system, to process, create, modify, and delete files. The
functions of a file management of an operating system are as follows:

● It helps to create new files in the computer system and place them in
required locations.

● It helps in prompt and simple ways to search files in computer


systems.

● It permits users to share files without conditioning.

● It also has directories in them to store different files. These


directories help users to locate files easily and manage them in terms
of their types.

● It provides freedom to make changes to their files i.e, to modify the


data or modify the name of the file in their directories.

The figure 4.18 below illustrates the general hierarchy of storage in an


operating system. In this figure 4.18 the root directory is present at the top
level in the hierarchical structure. It includes all the subdirectories in which
the files are stored. Subdirectory is part of another directory in the file
storage system. The storage system that user’s directory ensures quality
organization of files in the memory of the computer system.
Operating Systems

Figure 4.18: The general hierarchy of the storage.

The file management of function in operating system (OS) is based on the


following concepts:

File Attributes

It demotes the characteristics of the files such as type, date of last


modification, size, location on disk etc. File attributes help users to locate
the value and location of files. File attributes is a key feature to describe
all the information concerning a particular file.

File Operations

It denotes the task to be performed on a file such as opening and closing a


file.

File Access permission

It signifies the permissions concerning access of a file and performing


read/write operations.

File Systems

It specifies the logical method of file storage in a computer system. Some


of the commonly used files systems are FAT and NTFS.
Operating Systems

4.7 DIRECTORY MANAGEMENT

The purpose of a file directory is to collect files that contain information


regarding the file, its attributes, location, and ownership. Storage
constitutes the majority of the information and is maintained by an
operating system. The directory is itself a file, accessible by various file
management routines.

The device directory constitutes information such as:

• Name
• Type
• Address
• Current length
• Maximum length
• Date last accessed
• Date last updated
• Owner id
• Protection information

Operation performed on directory are:

• File location
• Create a file
• Delete a file
• List a directory
• Rename a file
• Traverse the file system

Advantages of maintaining directories are:

● Efficiency: Prompt location of a file.

● Naming: It provides comfort to users to have the same name for


various files or vice versa.

● Grouping: Logical grouping of files based on its properties e.g.


grouping all java programs, all games etc.
Operating Systems

Single-Level Directory

A single directory is available and maintained for every user, but it has
two major concerns

● Naming problem: Each file should have a unique name.

● Grouping problem: Users are denied from grouping the files for their
requirement.

Figure 4.19: Single-level directory

Two-Level Directory

Here, each user is allotted a separate directory. A two-level directory


requires a path name for every file to locate IT. Files can have the same
name unlike single level directory. In comparison to other directories,
searching a file here is efficient.

Figure 4.20: Two-level directory

Tree-Structured Directory:

Directory is represented in a tree where seeking files are convenient and


provides grouping capability. Absolute or relative path names are chosen
for a file.
Operating Systems

Figure 4.21: Tree-structured Directory:

4.8 LET US SUM UP

• The file system is an apparatus for on-line storage and access to


both data and programs of the operating system to all the users of
the computer system.
• File processing refers to the general sequence of operations of
opening a file, reading data from the file or writing data in it, and
closing the file.
• The IOCS maintains a file’s data on an I/O device in respect to its
file type.
• A file system is a collection of data that is owned by a user, can be
shared by a set of authorized users, and must be reliably stored
over an extended period of time.
• Most of the operating systems use layering approach for every task
including file systems.
• The most common approach to the protection problem is to make
access dependent on the identity of the user.
• Record access pattern refers to the order in which records in a file
are accessed by a process.
• A file organization is a combination of two features—a method of
arranging records in a file and a procedure for accessing them.
• An access method is a module of the IOCS that implements access
to a class of files using a specific file organization.
Operating Systems

• A directory contains information about a group of files.


• The logical file system deals with all the meta data associated with
a file.
• Physical files contain the actual data that is stored on the system,
and a description of how data is to be presented to or received from
a program.
• A file processing activity is implemented through modules of the
file system and the input-output control system (IOCS).
• Three modes of performing I/O operations are —programmed
mode, interrupt mode, and direct memory access (DMA) mode.
• The seek time of a disk block depends on its position relative to the
current position of the disk heads.
• A generic technique of speeding up access to file data is to use a
memory hierarchy consisting of a part of memory and files stored
on a disk.

4.9 KEYWORDS

• File System: A method used by operating systems to organize and


store data on storage devices such as hard drives, solid-state drives
(SSDs), and flash drives. It provides a hierarchical structure for
organizing files and directories and manages the allocation of
storage space.
• Directory: Also known as a folder, a directory is a container used to
organize files and other directories hierarchically within a file
system. It provides a way to group related files together and navigate
the file system.
• File Allocation Table (FAT): A data structure used by some file
systems, such as FAT16 and FAT32, to keep track of the allocation
status of storage space on a disk. It maintains a table of entries, each
representing a cluster of storage space.
• Master File Table (MFT): A data structure used by the NTFS (New
Technology File System) file system in Windows to store metadata
Operating Systems
about each file and directory on a volume, including file attributes,
security descriptors, and file content.
• Allocation Unit: Also known as a cluster or block, an allocation unit
is the smallest unit of storage space allocated by a file system. Files
are stored in multiples of allocation units, and unused space within
an allocation unit may be wasted due to internal fragmentation.

4.10 SOME USEFUL BOOKS

Reference Books

● Crowley, Charles. 2001.Operating System: A Design-oriented


Approach. McGraw-Hill,Inc.

Textbook References

● Silberschatz, Abraham and Galvin, Peter B., and Gagne, Greg,


2018. Operating System Concepts (10th edition), Hoboken, NJ:
John Wiley & Sons, Inc.

● Stallings, William.2017. Operating systems: Internals and design


principles (Ninth edition). New Jersey: Pearson Education, Inc

● Dhamdhere, Dhananjay M. 2009. Operating Systems: A Concept-


Based Approach (First Edition), New York, McGraw-Hill.

Website:

● https://www.javatpoint.com/os-indexed-allocation

● https://basicittopic.com/file-system-interface/

● https://techdifferences.com/difference-between-fat32-and-
ntfs.html

● https://docs.oracle.com/cd/E53394_01/html/E54850/fmaiofs.html

● https://developer.ibm.com/languages/java/articles/j-zerocopy/
Operating Systems

4.11 ANSWER TO CHECK YOUR PROGRESS

Answer to check your progress- 1 Q. 1 …

Allocation strategy modules are important because they directly affect the
efficiency of storage space utilization, file access performance, and
fragmentation levels in the file system.

Answer to check your progress- 1 Q. 2 …

An allocation strategy module determines the appropriate allocation


strategy for new files based on factors such as file size, available space,
and file system characteristics. It allocates storage space to files according
to the chosen strategy and updates metadata to track file allocations.

Answer to check your progress- 1 Q. 3 …

Factors such as file system type, storage device characteristics, file access
patterns, and performance requirements influence the choice of allocation
strategy in a file system. Different allocation strategies may be suitable for
different use cases and environments.

Answer to check your progress- 2 Q. 1 …

A device handler performs functions such as initializing the device,


handling device-specific commands and requests, managing data transfers
between the device and the operating system, and handling device
interrupts and errors.

Answer to check your progress- 2 Q. 2 ….

When a hardware device encounters an error condition, such as a


communication error or hardware malfunction, the device handler detects
the error and takes appropriate action, such as reporting the error to the
operating system, attempting to recover from the error, or initiating error
recovery procedures.
Operating Systems

4.12 TERMINAL QUESTION

1. Explain the components of a simple file system and their


functions. How does a simple file system differ from more
complex file systems?

2. Discuss the general model of a file system, including its symbolic


representation and access control verification mechanisms.

3. Differentiate between the logical file system and the physical file
system. How do these components interact to manage files on
storage devices?

4. Describe the allocation strategy module used in file systems.


What are the key factors considered when designing an allocation
strategy?

5. Discuss the components of IO systems, including I/O initiators,


device handlers, and disk scheduling algorithms. How do these
components collaborate to manage input and output operations
effectively?

You might also like