Chapter 6
6.1 Disk Performance
The structure of the magnetic disk is shown below.
o Each disk platter has a flat circular shape, like a CD. As shown below.
o Common platter diameters range from 1.8 to 3.5 inches.
o The two surfaces of a platter are covered with a magnetic material.
o Information is stored by recording it magnetically on both surfaces of the
platters.
o A read-write head ‘files’ just above each surface of every platter.
o The heads are attached to a disk arm that moves all the heads as a unit.
o The surface of a platter is logically divided into circular tracks, which are
subdivided into sectors as shown below.
o The set of tracks that are at one arm position makes up a cylinder. There
may be thousands of concentric cylinders in a disk drive, and each track
may contain hundreds of sectors.
o The storage capacity of common disk drives is measured in gigabytes.
o When the disk is in use, a drive motor spins it at high speed. Most drives
rotate 60 to 250 times per second, specified in terms of rotations per
minute (RPM). Common drives spin at 5400, 7200, 10000, and 15000
RPM.
Disk speed has two parts.
1. The transfer rate is the rate at which data flows between the drive and
the computer. Normally it will be in Megabytes per second.
2. The positioning time, or random-access time, consists of two parts:
a) Seek Time: The time necessary to move the disk arm to the desired
cylinder. It will be in milliseconds.
b) Latency Time: The time necessary for the desired sector to rotate
to the disk head. It will be in milliseconds.
A disk can be removable, allowing different disks to be mounted as
Needed. Removable hard disks generally consist of one platter, held in a
plastic case to prevent damage while not in the disk drive. Other forms of
removable disks include CDs, DVDs, and Blu-ray discs.
Modern hard disk drives are addressed as large one-dimensional arrays
of logical blocks, where the logical block is the smallest transfer unit. The size
of a logical block is usually 512 bytes.
The one-dimensional array of logical blocks is mapped onto the sectors
of the disk sequentially. Sector 0 is the first sector of the first track on the
outermost cylinder.
The mapping proceeds in order through that track, then through the rest
of the tracks in that cylinder, and then through the rest of the cylinders from
outermost to innermost.
The drive increases its rotation speed as the head moves from the outer
to the inner tracks to keep the same rate of data moving under the head. This
method is used in CD-ROM and DVD-ROM drives.
The number of sectors per track and cylinders per disk has been
increasing as disk technology improves.
Head Types:
There are two types of disks available.
1. Fixed-head Disk: In which
Separate head for each track.
High-speed access.
Large number of Heads.
Very expensive.
2. Moving-head Disk: In which (Most common in modern disks)
Only one head for each surface.
Moves in and out to access different tracks.
Less expensive.
Additional hardware required to move the head.
Increasing Storage Capacity:
Disk storage capacity can be increased by using the following techniques.
Improving recording density by increasing the number of tracks per inch.
Using two sides of the platter for storing information in which an additional
read-write head is required and storage capacity is doubled.
Stacking several disks in which additional read/write heads are required for
each disk but only one motor drive is sufficient.
Working Principle:
To read or write information from disk or to disk the sequence of
operations done in the case of disks with moving heads are
The drive motor spins, the disk at high speed.
The read-write head is positioned just above the surface of the disk.
The head will be moved to the required cylinder (inner or outer).
Waits till the required sector (block) reaches the head (Circularly).
Information is stored/retrieved magnetically to or from the required sector.
Disk characteristics:
The salient features of the disk are
Read, modify, and write it back in the same place.
Access any block/sector directly.
Sequential or random access is allowed.
Supports large volumes of data.
Both fixed and removable disks are available to suit various user needs.
6.2 Disk Scheduling Algorithms/Policies
In disk accessing in any operating system, the seek time is very
important. Since all device requests are linked in queues, the seek time is
increased causing the system to slow down. Disk Scheduling
Algorithms/Policies are used to reduce the total seek of any request.
There exists a variety of types of disk scheduling algorithms. Some of
them are:
First Come-First Serve (FCFS) Scheduling.
Shortest Seek Time First (SSTF) Scheduling.
Elevator (SCAN) Scheduling. (LOOK)
Circular SCAN (C-SCAN) Scheduling. (C-LOOK)
1. First Come First Serve (FCFS) Scheduling:
In the FCFS Scheduling, all incoming requests are placed at the end of the
queue. Whatever number is next in the queue will be the next number served.
Steps:
Step 1. Serve the request at the current head position.
Step 2. Move the head to the next request in the queue.
Step 3. Repeat steps 1 and 2 till all the requests are processed.
Example:
Consider for example an ordered disk queue with requests involving the
Tracks 98,183,37,122,14,124,65,67 and assume that the initial head is at track
53. The request queue supports the tracks from 0 to 199.
Working of FCFS Scheduling:
Now let us see how the head moves from the current track to the next
track and in each movement, the number of tracks moved.
If the disk head is initially at cylinder 53.
It will first move from 53 to 98.
Then to 183,37,122,14,124,65 and 67 as shown in the table.
The total head movements are 640 tracks.
The movement of the head is shown pictorially as given below.
Note: The number on the arrow indicates the order of movements based on the
request.
Advantages:
Simplest form of disk scheduling algorithm.
Easy to program.
Intrinsically fair.
Disadvantages:
It is the worst scheduling algorithm.
Causes the head to span across a greater number of tracks.
Seek time is highest.
Disk throughput is less.
2. Shortest Seek Time First (SSTF) Scheduling:
In this case request is serviced according to the next shortest distance
from the current position. As the distance reduces the seek time is also
reduced. Hence it serves the next request that causes the least seek time.
Steps:
Step 1. Service the request at the current head position.
Step 2. Move the head to the request that is closest to the head among all the
remaining requests. (Calculate the distance (absolute difference) between the
current request and all other leftover requests in the queue and choose the
request with the least distance).
Step 3. Repeat steps 1 and 2 till all the requests are processed.
Example:
Consider for example an ordered disk queue with requests involving the
Tracks 98,183,37,122,14,124,65,67 and assume that the initial head is at track
53.
The following table shows the distances between the current request and
all leftover requests, the least distance is highlighted and the next request to be
served is given in the last column.
Working of SSTF Scheduling:
The order of requests will be based on the above table and it is as given below.
If the disk head is initially at cylinder 53,
It will first move from 53 to 65 (since the distance between 53 and 65 is
the least and it is 12 only as per the first row of the above table).
Then to next closest position to 65 is 67 (since the distance between 65
and 67 is the least and it is 2 only as per the second row of the above
table).
The next requests processed are 37,14,98,122,124, and 183 as shown in
the following table (refer to the last table).
The SSFT scheduling requests are as shown below.
The total number of tracks moved is only 236.
The movement of the head is shown pictorially as given below.
Advantages:
It is a substantial improvement over FCFS.
It is an essential form of Shortest Job First Scheduling.
Disadvantages:
It may cause starvation of some requests.
It is not optimal.
The total head movement can be further reduced.
3. SCAN Scheduling (Elevator):
This algorithm works like an Elevator. The elevator moves up (down)
serving all the floors in that direction, after reaching the last floor in that
direction elevator reverses its direction and serves the requests at all the floors
till it reaches the last floor in the reverse direction and this process will be
continued.
Steps:
Step 1. Service the request at the current head position.
Step 2. Move the head towards one end (say inner or left) of the disk till it
reaches a request in that direction and serve it.
Step 3. Continue serving all the requests (i.e., step 2) till it reaches the end (left
or inner).
Step 4. Reverse the direction of head movement (towards right or outer) of the
disk till it reaches a request in that direction and serve it.
Step 5. Continue serving all the requests (i.e., step 4) till it reaches the end
(right or outer).
Step 6. Continue the above process (step 1 to step 5) scanning back and forth
continuously.
Example:
Consider for example an ordered disk queue with requests involving the
Tracks 98,183,37,122,14,124,65,67 and assume that the initial Head is at track
53. The request queue supports the tracks from 0 to 199 and the head is
moving towards the inner side or left.
Working of SCAN Scheduling:
If the disk head is initially at cylinder 53 and the direction is towards left.
It will first move from 53 to 37 (towards the left).
Then to 14,0 (reaches the left end).
Reverses direction towards right.
Serves the requests
65,67,98,122,124, and 183 as
shown ->
The total head movement of 236 tracks.
The movement of head is shown pictorially as given below.
Disadvantages:
Doesn’t provide uniform waiting time.
4. C-SCAN Scheduling:
This works like upward elevator, that serves only in upward direction
from ground floor to top floor, but it will never serve in downward direction.
C-SCAN Scheduling is a variant of SCAN Scheduling. It is designed to
provide uniform wait time. C-SCAN moves the head from one end of the disk to
other end, servicing requests along the way. When the head reaches the other
end, it immediately returns to the other end of the disk without servicing any
requests on the return trip.
It treats the cylinders as a circular list that wraps around from the last
cylinder to the first one.
Steps:
Step 1. Service the request at the current head position.
Step 2. Move the head towards one end (outer or right) of the disk till it reaches
a request in that direction and serve it.
Step 3. Continue serving all the requests (i.e. step 2) till it reaches the end
(outer or right).
Step 4. Reverse the direction of head movement (towards left or inner) of the
disk till it reaches the end without serving any request.
Step 5. Reverse the direction of head towards right or outer.
Step 6. Continue the Step 2 to step 5 continuously till all the requests are
completed.
Example:
Consider for example an ordered disk queue with requests involving the
tracks 98,183,37,122,14,124,65,67 and assume that the initial Head is at track
53. The request queue supports the tracks 0 to 199.
Working of C-SCAN Scheduling:
First it serves in right direction. Moves from 53 to 65.
Completes the services 65,67,122,124,183 and reaches right end till 199.
Reverses the direction and reaches 0 without serving any request. (this
jump from 199 to 0 is treated as huge jump and can be counted).
Now serves the request at the tracks 14,37 i.e., the head movements are
(to cylinders/tracks 53,65, (towards right) 67,98,122,124,183,199,0,14,
and 37) as shown in the next table.
Note:
Jump 199 to 0 is treated as huge jump and it will never be counted.
The total number of head movements is only 183 tracks.
The movement of head is shown pictorially as given below.
Advantages:
Better than SCAN Scheduling in terms of waiting time.
Provides Uniform waiting to all the requests.
Disadvantages:
The movement of head in reverse direction is an overhead.
It is not optimal.
6.3 Introduction to File System.
A File System is an integral part of an OS. A File System is a data
structure that stores data and information on storage devices (hard drives,
floppy discs, etc.), making them easily retrievable. Different OS’s use different
file systems, but all have similar features.
The most important part of the file system is indexing files on the hard
drive. This index allows the OS to know at any given time where to find a
specific file on the hard drive. This index is most typically based on file names.
Depending on the operating system there are different file systems, and thus
different indexing methods.
1. Windows: 3 file systems
You will find one of three file systems in the Windows environment, each with
different indexing methods.
1. The first is known as the FAT (12, 16, or 32) file system. This system uses
what is known as a File Allocation Table to index the files on the disc.
This file allocation table is very simple to implement and use but can be
somewhat slow. It divides hard disks into one or more partitions (parts)
that become letters, like C: D: etc.
2. The second file system you may encounter when using Windows is
known as NTFS (New Technology File System). NTFS uses binary trees
that, while complex, allow for high-speed access times. It builds on the
features of FAT, adds new features, and changes a few others. It is a
recoverable file system, which means that it keeps track of actions in the
file system.
3. The third file system, exFAT, is a lightweight file system used primarily in
flash storage applications and SD cards. It has large file size and partition
size limits, which means you can store files over 4GB on a flash drive or
SD card that is formatted with exFAT.
2. MAC OS
In the macOS environment you will find the HFS+ file system (pronounce
it HFS Plus). As of June 2016, Apple has implemented its new file system
“APFS”. This has become the replacement for HFS+ on macOS High Sierra and
onward, as well as iOS 10.3+.
3. Linux
Depending on which type of Linux environment you are running, you may
run into several different file systems. Some of them are ext2, ext3, and ext4.
XFS, JFS, and a few others are also used. ext3 is a journaling extension to the
ext2 file system on Linux. ext4 is the successor to ext3.
6.4 File Management System
A file management system is a component of operating system, that
manages data files in a computer system. It is also called as file manager.
The basic functions of the file management system include:
1. Managing individual files by permitting a user to create, delete, modify
and read the files.
2. Organizing the individual files as groups/directories by permitting the
user to create, delete and organize directories and subdirectories.
3. Providing different file access methods like sequential, random, direct,
indexed accessing techniques.
4. Protecting the files and directories from malicious operations and from
unauthorized users.
5. Allowing a file to have attributes like read, write, hidden etc.
6. Displaying a report showing the details like owner, creation date, type of
file, size, etc.
6.5 File Operations
The operating system provides system calls to perform 6 basic
operations on files, namely create, write, read, reset, truncate and delete files.
1. Creating a file: Creates a new empty file.
2. Writing a file: Writes data into an existing file.
3. Reading a file: Reads the data from an existing file and stored it
somewhere else.
4. Deleting a file: Removes the file entirely. i.e., the file name, attributes and
file contents are removed.
5. Repositioning within a file: Places the pointer at anywhere like at the
beginning of the file, ending of the file or at required position of the file.
This operation is also called as file seeking.
6. Truncating a file: Just deletes the contents of the file but not file name
and its attributes.
The additional operations that are applied on files include:
7. Editing the file: To modify its contents.
8. Appending the file: A special case of editing a file is appending new
information at the end of the file.
9. Renaming the file: Only the name of the file is changed but all other
remain the same.
10. Making copies of the file: Open the file to perform read/write
operations.
11. Close the file: After read/write operations are completed, close the file.
12. Get the file length of the file: To know the size of the file in number of
bytes.
13. Set attributes of the file: To change the owner’s name, access
permissions, etc.
6.6 Access Methods
Files store information. This information must be brought into the main
memory for use. The following access methods are used to serve this purpose.
1. Sequential Access.
2. Direct Access.
3. Indexed Sequential Access.
1. Sequential Access Method:
Sequential access is a technique in which the information in the file is
processed sequentially (one record after the other). This method is used on
tape mode of storage.
On tape, songs are played one after the other. To listen to the 10th song,
all the previous 9 songs must be listened to or forwarded.
Begin
1st 2nd 3rd 4th 5th 6th 7th End
Current Position
2. Direct Access Method (Random Access Method):
Direct access is based on the disk model of a file. Any record can be
accessed directly without processing previous records.
It is like songs recorded on a CD. To listen to the 10th song, we can
directly listen to it without listening to the previous 9 songs. Direct access
allows any data to be read or written. Hence, after block 18, block 36 can be
read, and then block 2.
Direct Access
2 3 8
10 18
36
3. Indexed Sequential Access Method:
It is a combination of both direct access and sequential access. An index
for a file is created with pointers to various records (blocks).
To retrieve information, an index is searched first then pointer is used to
access record directly (direct access) and within record, data can be accessed
sequentially (sequential access). This can be shown in the following figure.
Name Pointer
Ravi
Megha Krish 30 Engineer Record
.
.
. File
Krish
Lava
Index of file
It is like a DVD containing movies. To open a movie, we go to the index
(movie names) and choose a movie and it will be played sequentially.
6.6 Directory Structure Organization
Directories are used both in Linux and Windows Operating systems. The
most common directory structures are:
1. Single-level directory.
2. Two-level directory.
3. Tree-structured directory.
4. Acyclic graph directory.
1. Single-level directory:
In this directory structure, all the files are stored in one directory.
For example:
Cat Dog Test Mail Directory
Files
Advantage:
1. It is easy to implement.
Disadvantages:
1. File names must be unique otherwise name collision occurs.
2. We can’t share files.
2. Two-level Directory:
In this, the system maintains a master block that has one entry for each
user. The system maintains a Master File Directory (MFD). A separate directory
for each user is created.
User 1 User 2 User 3 Master File Directory
Vkt Test ABC Songs Movies DS Linux Directories
Files
Advantages:
1. Solves the name collision problem to some extent.
2. Provide efficient searching.
Disadvantages:
1. Sharing of files is difficult.
3. Tree-Structured Directory:
In this directory system, the directories can be treated as files, hence,
each directory contains files and subdirectories.
1. The tree directory has a root.
2. The root directory contains a set of files and other sub-directories.
3. Each sub-directory further contains a set of files and other sub-
directories.
4. The directory can be created using the MKDIR command (Linux).
5. The directory can be removed using the RMDIR command.
Tree-structured directory is used both in Linux and Windows. This can be
shown below.
Advantages:
1. Very scalable and name collision is less.
2. Searching becomes very easy.
Disadvantages:
1. We cannot share files.
4. Acyclic Graph Directory:
This directory structure allows the sharing of files and sub-directories. In
this system, two or more entries of a directory point to the same file or sub-
directory. The acyclic graph structure can be shown below:
Advantages:
1. We can share files.
2. Searching is easy.
Disadvantages:
1. Files are shared via links, but if links are deleted then it may create a
problem.
6.7 File Protection (Optional)
File protection in an operating system refers to the various mechanisms
and techniques used to secure files from unauthorized access, alteration, or
deletion. It involves controlling access to files, ensuring their security and
confidentiality, and preventing data breaches and other security incidents.
Operating systems provide several file protection features, including file
permissions, encryption, access control lists, auditing, and physical file
security. These measures allow administrators to manage access to files,
determine who can access them, what actions can be performed on them, and
how they are stored and backed up. Proper file protection requires ongoing
updates and patches to fix vulnerabilities and prevent security breaches. It is
crucial for data security in the digital age where cyber threats are prevalent. By
implementing file protection measures, organizations can safeguard their files,
maintain data confidentiality, and minimize the risk of data breaches and other
security incidents.
Types of file protection:
1. File Permissions.
2. Encryption.
3. Access Control Lists (ACLs).
4. Auditing and Logging.
5. Physical File Security.
Advantages:
1. Data Security.
2. Compliance.
3. Business Continuity.
4. Increased Productivity.
5. Enhanced Collaboration.
6. Reputation.
Disadvantages:
1. Overhead.
2. Complexity.
3. Compatibility Issues.
4. Cost.
5. User Frustation.