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

OS - Unit 5 Complete

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)
22 views

OS - Unit 5 Complete

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/ 41

Operating Systems

Unit 5
• I/O Management and Disk Scheduling:
• I/O devices and I/O subsystems,
• I/O buffering,
• Disk storage and disk scheduling,
• RAID.
• File System:
• File concept,
• File organization and access mechanism,
• File directories, and File sharing,
• File system implementation issues,
• File system protection and security.
I/O Devices
• There are three Categories:
• Human readable: Devices used to
communicate with the user
• Printers and terminals,
Video display, Keyboard,
Mouse etc.
• Machine readable : Used to communicate
with electronic equipment
• Disk drives, USB keys,
USB keys, Sensors,
Controllers, Actuators
• Communications : Used to communicate
with remote devices
• Digital line drivers,
Modems
• I/O devices differ from each in a number
of respects–
• Data Rate
• Application
• Complexity of Control
• Unit of Transfer
• Data Representation
• Error Conditions
Techniques for performing I/O
Sync. And Async

• Programmed I/O
• Process is busy-waiting for the operation to complete
• Processes must wait for I/O to complete before proceeding
• To avoid deadlock certain pages must remain in main
memory during I/O
• It may be more efficient to perform input transfers in
advance of requests being made and to perform output
transfers some time after the request is made.
• Interrupt-driven I/O
• I/O command is issued
• Processor continues executing instructions
• I/O module sends an interrupt when done
• Processor does not spend time waiting for an I/O operation
to be performed
Techniques for performing I/O
• Direct Memory Access (DMA)
• DMA controls exchange of data
between main memory and
the I/O device
• Processor interrupted only
after entire block has been
transferred
• Blocks of data are moved into
memory without involving the
processor
• Processor involved at
beginning and end only
I/O Buffering
• Reasons for buffering
• Processes must wait for I/O to complete before proceeding
• Process cannot be entirely swapped out–corresponding pages must remain in main memory
during I/O
• Risk of single process deadlock– process swapped out before I/O operation starts
• Block-oriented
• Information is stored in fixed sized blocks
• Transfers are made a block at a time
• Used for disks and tapes
• User process can process one block of data while next block is read in Swapping can occur
since input is taking place in system memory, not user memory
• Operating system keeps track of assignment of system buffers to user processes
• Stream-oriented
• Transfer information as a stream of bytes
• Used for terminals, printers, communication ports, mouse and other pointing devices, and
most other devices that are not secondary storage.
• Used a line-at-a-time, e.g. line printer (or byte at- a-time, e.g., form-mode terminals)
• Output to the terminal is one line at a time
I/O Buffering
OS assigns a buffer in MM for an I/O request
Single Buffer
• Input transfers made to buffer
• Block moved to user space when needed
• Another block is moved into the buffer
(read ahead)

• Double Buffer
• Use two system buffers instead of one
• A process can transfer data to or from one
buffer while the operating system empties
or fills the other buffer
• Circular Buffer
• More than two buffers are used
• Each individual buffer is one unit in a
circular buffer
• Used when I/O operation must keep up
with process
Disk Structure

• Seek Time: Seek time is the time taken to locate the disk arm to a specified
track where the data is to be read or write. So the disk scheduling algorithm
that gives minimum average seek time is better.
• Rotational Latency: Rotational Latency is the time taken by the desired sector
of disk to rotate into a position so that it can access the read/write heads. So
the disk scheduling algorithm that gives minimum rotational latency is better.
• Transfer Time: Transfer time is the time to transfer the data. It depends on the
rotating speed of the disk and number of bytes to be transferred.
• Disk Access Time: Disk Access Time is:
• Disk Access Time = Seek Time + Rotational Latency + Transfer Time
• Disk Response Time: Response Time is the average of time spent by a request
waiting to perform its I/O operation. Average Response time is the response
time of the all requests. Variance Response Time is measure of how individual
request are serviced with respect to average response time. So the disk
scheduling algorithm that gives minimum variance response time is better.
• Average I/O time = average access time + (amount to transfer / transfer rate) +
controller overhead.
Disk Scheduling
• Disk scheduling is done by operating systems to
schedule I/O requests arriving for the disk. Disk
scheduling is also known as I/O scheduling.
• Disk scheduling is important because:
• Multiple I/O requests may arrive by different
processes and only one I/O request can be
served at a time by the disk controller. Thus
other I/O requests need to wait in the waiting
queue and need to be scheduled.
• Two or more request may be far from each other
so can result in greater disk arm movement.
• Hard drives are one of the slowest parts of the
computer system and thus need to be accessed
in an efficient manner.
FCFS
FCFS: FCFS is the simplest of all the Disk Scheduling
Algorithms. In FCFS, the requests are addressed in the
order they arrive in the disk queue.

Suppose the order of request is-


(82,170,43,140,24,16,190)
And current position of Read/Write head is : 50
So, total seek time:
=(82-50) + (170-82) + (170-43) + (140-43) + (140-24)+
(24-16) + (190-16) = 642

Advantages:
Every request gets a fair chance
No indefinite postponement
Disadvantages:
Does not try to optimize seek time
May not provide the best possible service
Shortest Seek Time First
SSTF: In SSTF (Shortest Seek Time First), requests having shortest
seek time are executed first. So, the seek time of every request is
calculated in advance in the queue and then they are scheduled
according to their calculated seek time. As a result, the request
near the disk arm will get executed first. SSTF is certainly an
improvement over FCFS as it decreases the average response time
and increases the throughput of system.

Suppose the order of request is- (82,170,43,140,24,16,190)


And current position of Read/Write head is : 50
So, total seek time:
=(50-43)+(43-24)+(24-16)+(82-16)+(140-82)+(170-140)+(190-170)
=208

Advantages:
• Average Response Time decreases
• Throughput increases
Disadvantages:
• Overhead to calculate seek time in advance
• Can cause Starvation for a request if it has higher seek time as
compared to incoming requests
• High variance of response time as SSTF favours only some
requests
SCAN
SCAN: In SCAN algorithm the disk arm moves into a particular
direction and services the requests coming in its path and after
reaching the end of disk, it reverses its direction and again
services the request arriving in its path. So, this algorithm works
as an elevator and hence also known as elevator algorithm. As a
result, the requests at the midrange are serviced more and
those arriving behind the disk arm will have to wait.
Suppose the requests to be addressed are-
82,170,43,140,24,16,190. And the Read/Write arm is at 50, and
it is also given that the disk arm should move “towards the
larger value”.
Therefore, the seek time is calculated as =(199-50)+(199-16)
=332
Advantages:
• High throughput
• Low variance of response time
• Average response time
Disadvantages:
• Long waiting time for requests for locations just visited by
disk arm
C-SCAN
C-SCAN: In SCAN algorithm, the disk arm again scans the
path that has been scanned, after reversing its direction.
So, it may be possible that too many requests are waiting
at the other end or there may be zero or few requests
pending at the scanned area.
These situations are avoided in CSCAN algorithm in which
the disk arm instead of reversing its direction goes to the
other end of the disk and starts servicing the requests from
there. So, the disk arm moves in a circular fashion and this
algorithm is also similar to SCAN algorithm and hence it is
known as C-SCAN (Circular SCAN).
Seek time is calculated as =(199-50)+(199-0)+(43-0) =391
Advantages:
• The waiting time for the cylinders just visited by the
head is reduced as compared to the SCAN Algorithm.
• It provides uniform waiting time.
• It provides better response time.
Disadvantages-
• It causes more seek movements as compared to SCAN
Algorithm.
• It causes the head to move till the end of the disk even
if there are no requests to be serviced.
LOOK
LOOK: It is similar to the SCAN disk scheduling algorithm except
for the difference that the disk arm in spite of going to the end of
the disk goes only to the last request to be serviced in front of the
head and then reverses its direction from there only. Thus it
prevents the extra delay which occurred due to unnecessary
traversal to the end of the disk.
Suppose the requests to be addressed are-
82,170,43,140,24,16,190. And the Read/Write arm is at 50, and it
is also given that the disk arm should move “towards the larger
value”.
So, the seek time is calculated as:
=(190-50)+(190-16) =314
Advantages-
• It does not causes the head to move till the ends of the disk
when there are no requests to be serviced.
• It provides better performance as compared to SCAN
Algorithm.
• It does not lead to starvation.
• It provides low variance in response time and waiting time.
Disadvantages-
• There is an overhead of finding the end requests.
• It causes long waiting time for the cylinders just visited by the
head.
C-LOOK
C-LOOK: As LOOK is similar to SCAN algorithm, in similar way, CLOOK is
similar to CSCAN disk scheduling algorithm. In CLOOK, the disk arm in
spite of going to the end goes only to the last request to be serviced in
front of the head and then from there goes to the other end’s last
request. Thus, it also prevents the extra delay which occurred due to
unnecessary traversal to the end of the disk.
Suppose the requests to be addressed are-82,170,43,140,24,16,190.
And the Read/Write arm is at 50, and it is also given that the disk arm
should move “towards the larger value”
So, the seek time is calculated as = (190-50)+(190-16)+(43-16) =341
Advantages-
• It does not causes the head to move till the ends of the disk when
there are no requests to be serviced.
• It reduces the waiting time for the cylinders just visited by the head.
• It provides better performance as compared to LOOK Algorithm.
• It does not lead to starvation.
• It provides low variance in response time and waiting time.
Disadvantages-
• There is an overhead of finding the end requests.
GATE Question 1
• Suppose a disk has 201 cylinders, numbered from 0 to 200. At some time the
disk arm is at cylinder 100, and there is a queue of disk access requests for
cylinders 30, 85, 90, 100, 105, 110, 135 and 145. If Shortest-Seek Time First
(SSTF) is being used for scheduling the disk access, the request for cylinder 90 is
serviced after servicing ____________ number of requests.

• In Shortest-Seek-First algorithm, request closest to the current position of the


disk arm and head is handled first.
• In this question, the arm is currently at cylinder number 100. Now the requests
come in the queue order for cylinder numbers 30, 85, 90, 100, 105, 110, 135 and
145.
• The disk will service that request first whose cylinder number is closest to its
arm. Hence 1st serviced request is for cylinder no 100 ( as the arm is itself
pointing to it ), then 105, then 110, and then the arm comes to service request
for cylinder 90. Hence before servicing request for cylinder 90, the disk would
had serviced 3 requests.
GATE Question 2
• Consider an operating system capable of loading and executing a single
sequential user process at a time. The disk head scheduling algorithm used is
First Come First Served (FCFS). If FCFS is replaced by Shortest Seek Time First
(SSTF), claimed by the vendor to give 50% better benchmark results, what is
the expected improvement in the I/O performance of user programs?

• Since Operating System can execute a single sequential user process at a


time, the disk is accessed in FCFS manner always.
• The OS never has a choice to pick an IO from multiple IOs as there is always
one IO at a time
GATE Question
• Suppose the following disk request sequence (track numbers)
3
for a disk with 100 tracks is given: 45, 20, 90, 10, 50, 60, 80,
25, 70. Assume that the initial position of the R/W head is on
track 50. The additional distance that will be traversed by the If Simple SCAN is used, requests are served as following
R/W head when the Shortest Seek Time First (SSTF) algorithm
is used compared to the SCAN (Elevator) algorithm (assuming Next Served Distance Travelled
that SCAN algorithm moves towards 100 when it starts 50 0
execution) is _________ tracks . 60 10
• In Shortest seek first (SSTF), closest request to the current 70 10
position of the head, and then services that request next. 80 10
• In SCAN (or Elevator) algorithm, requests are serviced only in 90 10
the current direction of arm movement until the arm reaches 45 65 [disk arm goes to 99, then to 45]
the edge of the disk. When this happens, the direction of the 25 20
arm reverses, and the requests that were remaining in the 20 5
opposite direction are serviced, and so on. Given a disk with 10 10
100 tracks And Sequence 45, 20, 90, 10, 50, 60, 80, 25, ----------------------------------------------------------------------------
70.Initial position of the R/W head is on track 50.In SSTF,
requests are served as following Total Distance = 140
Next Served Distance Travelled
50 0
45 5
60 15 Less Distance travelled in SSTF = 130 - 140 = 10
70 10
80 10
90 10
25 65
20 5
10 10
----------------------------------- -----------------------------
Total Distance = 130
Question 4
• Consider a disk with 200 tracks and the queue has random requests from different processes in the order:
55, 58, 39, 18, 90, 160, 150, 38, 184
• Initially arm is at 100. Find the Average Seek length using FIFO, SSTF, SCAN and C-SCAN algorithm..
Selecting a Disk-Scheduling Algorithm
• SSTF is common and has a natural appeal
• SCAN and C-SCAN perform better for systems that place a heavy load on the
disk
• Less starvation
• Performance depends on the number and types of requests
• Requests for disk service can be influenced by the file-allocation method and
metadata layout
• The disk-scheduling algorithm should be written as a separate module of the
operating system, allowing it to be replaced with a different algorithm if
necessary
• Either SSTF or LOOK is a reasonable choice for the default algorithm
Stable-Storage Implementation
• Write-ahead log scheme requires stable storage
• Stable storage means data is never lost (due to failure, etc)
• To implement stable storage:
• Replicate information on more than one non-volatile storage media with independent failure modes
• Update information in a controlled manner to ensure that we can recover the stable data after any failure during
data transfer or recovery
• Disk write has 1 of 3 outcomes
• Successful completion - The data were written correctly on disk
• Partial failure - A failure occurred in the midst of transfer, so only some of the sectors were written with the new
data, and the sector being written during the failure may have been corrupted
• Total failure - The failure occurred before the disk write started, so the previous data values on the disk remain
intact
• If failure occurs during block write, recovery procedure restores block to consistent state
• System maintains 2 physical blocks per logical block and does the following:
• Write to 1st physical
• When successful, write to 2nd physical
• Declare complete only after second write completes successfully
• Systems frequently use NVRAM as one physical to accelerate
RAID(Redundant Arrays of Independent Disks) Structure
• RAID, or “Redundant Arrays of Independent Disks” is a technique which makes use of a combination of
multiple disks instead of using a single disk for increased performance, data redundancy or both.
• The term was coined by David Patterson, Garth A. Gibson, and Randy Katz at the University of California,
Berkeley in 1987.
• RAID or redundant array of independent disks is a data storage virtualization technology that combines
multiple physical disk drive components into one or more logical units for data redundancy, performance
improvement, or both.
• It is a way of storing the same data in different places on multiple hard disks or solid-state drives to protect
data in the case of a drive failure.
• A RAID system consists of two or more drives working in parallel. These can be hard discs, but there is a trend
to use SSD technology (Solid State Drives).
• The disks included in the array are called array members. The disks can combine into the array in different
ways, which are known as RAID levels. Each of RAID levels has its own characteristics of:
• Fault-tolerance is the ability to survive one or several disk failures.
• Performance shows the change in the read and writes speed of the entire array compared to a single disk.
• The array's capacity is determined by the amount of user data written to the array. The array capacity
depends on the RAID level and does not always match the sum of the RAID member disks' sizes. To
calculate the particular RAID type's capacity and a set of member disks, you can use a free online RAID
calculator.
RAID Implementation Types
There are three ways of utilizing RAID, differing by where the processing takes
place :
• Hardware-based RAID : When installing the hardware setup, you insert a RAID
controller card in a fast PCI-Express slot on the motherboard and connect it to
the drives. External RAID drive enclosures with a built-in controller card are
also available.
• Software-based RAID : For the software setup, you connect the drives directly
to the computer, without using a RAID controller. In that case, you manage the
disks through utility software on the operating system.
• Firmware/Driver-based RAID : Firmware-based RAID (also known as a driver-
based RAID) are RAID systems often stored directly on the motherboard. All
its operations are performed by the computer's CPU, not by a dedicated
processor.
How RAID Works
• RAID works by placing data on multiple disks and allowing input/output
operations to overlap in a balanced way, improving performance. Because
various disks increase the mean time between failures (MTBF), storing
data redundantly also increases fault tolerance.
• RAID arrays appear to the operating system as a single logical drive. RAID
employs the techniques of disk mirroring or disk striping.
• Disk Mirroring will copy identical data onto more than one drive.
• Disk Striping partitions help spread data over multiple disk drives. Each
drive's storage space is divided into units ranging from 512 bytes up to
several megabytes. The stripes of all the disks are interleaved and
addressed in order.
• Disk mirroring and disk striping can also be combined in a RAID array.
• In a single-user system where significant records are stored, the stripes are
typically set up to be small (512 bytes) so that a single record spans all the
disks and can be accessed quickly by reading all the disks at the same time.
• In a multi-user system, better performance requires a stripe wide enough
to hold the typical or maximum size record, allowing overlapped disk I/O
across drives.
RAID Levels
1. RAID 0 (striped disks) : RAID 0 is taking any number of disks
and merging them into one large volume. It will increase
speeds as you're reading and writing from multiple disks at a
time. But all data on all disks is lost if any one disk fails. An
individual file can then use the speed and capacity of all the
drives of the array. The downside to RAID 0, though, is that it
is NOT redundant. The loss of any individual disk will cause
complete data loss. This RAID type is very much less reliable
than having a single disk.

2. RAID 1 (mirrored disks) : It duplicates data across two disks in


the array, providing full redundancy. Both disks are store
exactly the same data, at the same time, and at all times. Data
is not lost as long as one disk survives. The total capacity of
the array equals the capacity of the smallest disk in the array.
At any given instant, the contents of both disks in the array
are identical.
RAID Levels
3. RAID 5(striped disks with single parity) : RAID 5 requires the use of at least three
drives. It combines these disks to protect data against loss of any one disk; the
array's storage capacity is reduced by one disk. It strips data across multiple drives
to increase performance. But, it also adds the aspect of redundancy by distributing
parity information across the disks.
Advantages of RAID 5
• Read data transactions are very fast while write data transactions are
somewhat slower (due to the parity that has to be calculated).
• If a drive fails, you still have access to all data, even while the failed drive is
being replaced and the storage controller rebuilds the data on the new drive.
Disadvantages of RAID 5
• Drive failures have an effect on throughput, although this is still acceptable.
• This is complex technology. If one of the disks in an array using 4TB disks fails
and is replaced, restoring the data (the rebuild time) may take a day or longer,
depending on the load on the array and the speed of the controller. If another
disk goes bad during that time, data are lost forever.
4. RAID 6 (Striped disks with double parity) : RAID 6 is similar to RAID 5, but the parity
data are written to two drives. The use of additional parity enables the array to
continue to function even if two disks fail simultaneously. However, this extra
protection comes at a cost. RAID 6 has a slower write performance than RAID 5.
Advantages of RAID 6
• Like with RAID 5, read data transactions are very fast.
• If two drives fail, you still have access to all data, even while the failed drives
are being replaced. So RAID 6 is more secure than RAID 5.
Disadvantages of RAID 6
• Write data transactions are slower than RAID 5 due to the additional parity
data that have to be calculated. In one report I read the write performance was
20% lower.
• Drive failures have an effect on throughput, although this is still acceptable.
Nested RAID levels
• RAID 10 (1+0) : This level Combines RAID 1 and RAID 0 in a single system,
which offers higher performance than RAID 1, but at a much higher cost.
This is a nested or hybrid RAID configuration. It provides security by
mirroring all data on secondary drives while using striping across each set
of drives to speed up data transfers.
Advantages of RAID 10
• If something goes wrong with one of the disks in a RAID 10
configuration, the rebuild time is very fast since all that is needed is
copying all the data from the surviving mirror to a new drive. This
can take as little as 30 minutes for drives of 1 TB.
Disadvantages of RAID 10
• Half of the storage capacity goes to mirroring, so compared to large
RAID 5 or RAID 6 arrays, this is an expensive way to have
redundancy.
RAID 01 (0+1) : RAID 0+1 is similar to RAID 1+0, except the data organization method is slightly different. Rather than
creating a mirror and then striping the mirror, RAID 0+1 creates a stripe set and then mirrors the stripe set.

RAID 03 (0+3, also known as RAID 53 or RAID 5+3) : This level uses striping similar to RAID 0 for RAID 3's virtual disk
blocks. This offers higher performance than RAID 3 but at a higher cost.

RAID 50 (5+0): This configuration combines RAID 5 distributed parity with RAID 0 striping to improve RAID 5
performance without reducing data protection.
File System
• File system is the part of the operating system which is responsible for file management. It provides a
mechanism to store the data and access to the file contents including data and programs. Some
Operating systems treats everything as a file for example Ubuntu.
• The name of the file is divided into two parts as shown below:
• Name
• Extension (separated by a period .)
• The File system takes care of the following issues
1. File Structure : We have seen various data structures in which the file can be stored. The task of
the file system is to maintain an optimal file structure.
2. Recovering Free space : Whenever a file gets deleted from the hard disk, there is a free space
created in the disk. There can be many such spaces which need to be recovered in order to
reallocate them to other files.
3. Disk space assignment to the files :The major concern about the file is deciding where to store
the files on the hard disk. There are various disks scheduling algorithm which will be covered later
in this tutorial.
4. Tracking data location : A File may or may not be stored within only one block. It can be stored in
the non contiguous blocks on the disk. We need to keep track of all the blocks on which the part
of the files reside.
File System Structure
• File System provide efficient access to the disk by allowing data to be stored,
located and retrieved in a convenient way. A file System must be able to store
the file, locate the file and retrieve the file.
• Most of the Operating Systems use layering approach for every task including
file systems. Every layer of the file system is responsible for some activities.
• The image shown ,elaborates how the file system is divided in different layers,
and also the functionality of each layer.
• When an application program asks for a file, the first request is directed to the
logical file system. The logical file system contains the Meta data of the file and
directory structure. If the application program doesn't have the required
permissions of the file then this layer will throw an error. Logical file systems
also verify the path to the file.
• Generally, files are divided into various logical blocks. Files are to be stored in
the hard disk and to be retrieved from the hard disk. Hard disk is divided into
various tracks and sectors. Therefore, in order to store and retrieve the files, the
logical blocks need to be mapped to physical blocks. This mapping is done by
File organization module. It is also responsible for free space management.
• Once File organization module decided which physical block the application
program needs, it passes this information to basic file system. The basic file
system is responsible for issuing the commands to I/O control in order to fetch
those blocks.
• I/O controls contain the codes by using which it can access hard disk. These
codes are known as device drivers. I/O controls are also responsible for handling
interrupts.
Attributes of the File
1. Name : Every file carries a name by which the file is recognized in the file system.
One directory cannot have two files with the same name.
2. Identifier : Along with the name, Each File has its own extension which identifies
the type of the file. For example, a text file has the extension .txt, A video file can
have the extension .mp4.
3. Type : In a File System, the Files are classified in different types such as video files,
audio files, text files, executable files, etc.
4. Location : In the File System, there are several locations on which, the files can be
stored. Each file carries its location as its attribute.
5. Size : The Size of the File is one of its most important attribute. By size of the file,
we mean the number of bytes acquired by the file in the memory.
6. Protection : The Admin of the computer may want the different protections for
the different files. Therefore each file carries its own set of permissions to the
different group of Users.
7. Time and Date : Every file carries a time stamp which contains the time and date
on which the file is last modified.
Operations on the File
1.Create operation : This operation is used to create a file in the file system. It is the most widely used operation performed on the file system. To
create a new file of a particular type the associated application program calls the file system. This file system allocates space to the file. As the file
system knows the format of directory structure, so entry of this new file is made into the appropriate directory.
2. Open operation: This operation is the common operation performed on the file. Once the file is created, it must be opened before performing
the file processing operations. When the user wants to open a file, it provides a file name to open the particular file in the file system. It tells the
operating system to invoke the open system call and passes the file name to the file system.
3. Write operation: This operation is used to write the information into a file. A system call write is issued that specifies the name of the file and
the length of the data has to be written to the file. Whenever the file length is increased by specified value and the file pointer is repositioned
after the last byte written.
4. Read operation: This operation reads the contents from a file. A Read pointer is maintained by the OS, pointing to the position up to which the
data has been read.
5. Re-position or Seek operation: The seek system call re-positions the file pointers from the current position to a specific place in the file i.e.
forward or backward depending upon the user's requirement. This operation is generally performed with those file management systems that
support direct access files.
6. Delete operation : Deleting the file will not only delete all the data stored inside the file it is also used so that disk space occupied by it is freed.
In order to delete the specified file the directory is searched. When the directory entry is located, all the associated file space and the directory
entry is released.
7. Truncate operation : Truncating is simply deleting the file except deleting attributes. The file is not completely deleted although the
information stored inside the file gets replaced.
8. Close operation : When the processing of the file is complete, it should be closed so that all the changes made permanent and all the resources
occupied should be released. On closing it deallocates all the internal descriptors that were created when the file was opened.
9. Append operation: This operation adds data to the end of the file.
10. Rename operation : This operation is used to rename the existing file.
File system protection and security
• The mechanism of the protection provide the facility of the controlled access by just limiting the types
of access to the file. Access can be given or not given to any user depends on several factors, one of
which is the type of access required. Several different types of operations can be controlled:
• Read –Reading from a file.
• Write –Writing or rewriting the file.
• Execute –Loading the file and after loading the execution process starts.
• Append –Writing the new information to the already existing file, editing must be end at the end of
the existing file.
• Delete –Deleting the file which is of no use and using its space for the another data.
• List –List the name and attributes of the file.
• Access Control : There are different methods used by different users to access any file. The general way
of protection is to associate identity-dependent access with all the files and directories an list called
access-control list (ACL) which specify the names of the users and the types of access associate with
each of the user. The main problem with the access list is their length. If we want to allow everyone to
read a file, we must list all the users with the read access. To condense the length of the access-control
list, many systems recognize three classification of users in connection with each file:
• Owner –Owner is the user who has created the file.
• Group –A group is a set of members who has similar needs and they are sharing the same file.
• Universe –In the system, all other users are under the category called universe.
File Access Methods
• Sequential Access : In sequential access, the OS read the file
word by word. A pointer is maintained which initially points
to the base address of the file. If the user wants to read first
word of the file then the pointer provides that word to the
user and increases its value by 1 word. This process
continues till the end of the file.
Modern word systems do provide the
concept of direct access and indexed access but the most
used method is sequential access due to the fact that most
of the files such as text files, audio files, video files, etc need
to be sequentially accessed.
• Direct Access : The Direct Access is mostly required in the case of database systems. In most
of the cases, we need filtered information from the database. The sequential access can be
very slow and inefficient in such cases.
Direct access will give the required result despite of the fact that the
operating system has to perform some complex tasks such as determining the desired block
number. However, that is generally implemented in database applications.
• Indexed Access : If a file can be sorted on any of the filed then an index can be assigned to a
group of certain records. However, A particular record can be accessed by its index. The index
is nothing but the address of a record in the file.
In index accessing, searching in a large database became very quick and easy
but we need to have some extra space in the memory to store the index value.
Directory Structure and File Allocation Table
• Directory can be defined as the listing of the related files on the disk. The
directory may store some or the entire file attributes. To get the benefit of
different file systems on the different operating systems, A hard disk can be
divided into the number of partitions of different sizes. The partitions are
also called volumes or mini disks. Each partition must have at least one
directory in which, all the files of the partition can be listed. A directory
entry is maintained for each file in the directory which stores all the
information related to that file.
• File Allocation Table : File Allocation Table overcomes this drawback of
linked list allocation. In this scheme, a file allocation table is maintained,
which gathers all the disk block links. The table has one entry for each disk
block and is indexed by block number. File allocation table needs to be
cached in order to reduce the number of head seeks. Now the head doesn't
need to traverse all the disk blocks in order to access one successive block.
• Directory Implementation :
• Linear List : It maintains a linear list of filenames with pointers to the
data blocks. It is time-consuming also. To create a new file, we must
first search the directory to be sure that no existing file has the same
name then we add a file at end of the directory. To delete a file, we
search the directory for the named file and release the space. To reuse
the directory entry either we can mark the entry as unused or we can
attach it to a list of free directories.
• Hash Table : The hash table takes a value computed from the file name
and returns a pointer to the file. It decreases the directory search time.
The insertion and deletion process of files is easy. The major difficulty
is hash tables are its generally fixed size and hash tables are dependent
on hash function on that size.
Ways to Implement Directory
File system implementation
• We can implement file system by using two types data structures :
1. On-disk Structures : Generally they contain information about total number of disk blocks, free disk
blocks, location of them and etc. Below given are different on-disk structures :
• Boot Control Block –It is usually the first block of volume and it contains information needed to boot
an operating system. In UNIX it is called boot block and in NTFS it is called as partition boot sector.
• Volume Control Block –It has information about a particular partition ex:- free block count, block size
and block pointers etc. In UNIX it is called super block and in NTFS it is stored in master file table.
• Directory Structure –They store file names and associated inode numbers. In UNIX, includes file
names and associated file names and in NTFS, it is stored in master file table.
• Per-File FCB –It contains details about files and it has a unique identifier number to allow association
with directory entry. In NTFS it is stored in master file table.
2. In-Memory Structure : They are maintained in main-memory and these are helpful for file system
management for caching. Several in-memory structures given below :
• Mount Table – It contains information about each mounted volume.
• Directory-Structure cache – This cache holds the directory information of recently accessed
directories.
• System wide open-file table – It contains the copy of FCB of each open file.
• Per-process open-file table – It contains information opened by that particular process and it maps
with appropriate system wide open-file.
File System Implementation Issues

• What data/metadata is stored in the device?


• How is that information arranged?
• How is that information used by the OS during open(), read(), write(), close(),
etc.
• What happens upon crash or outage?
• What details are left to the device itself?
File Allocation Methods : Contiguous Allocation
• There are various methods which can be
used to allocate disk space to the files.
Selection of an appropriate allocation
method will significantly affect the
performance and efficiency of the system.
Allocation method provides a way in which
the disk will be utilized and the files will be
accessed.
• Contiguous Allocation : If the blocks are
allocated to the file in such a way that all the
logical blocks of the file get the contiguous
physical block in the hard disk then such Advantages
allocation scheme is known as contiguous • It is simple to implement.
allocation. • We will get Excellent read performance.
• In the image shown ,there are three files in • Supports Random Access into files.
the directory. The starting block and the Disadvantages
length of each file are mentioned in the • The disk will become fragmented.
table. We can check in the table that the • It may be difficult to have a file grow.
contiguous blocks are assigned to each file
as per its need.
File Allocation Methods : Linked List allocation
• Linked List allocation : It solves all problems of contiguous allocation. In
linked list allocation, each file is considered as the linked list of disk
blocks. However, the disks blocks allocated to a particular file need not
to be contiguous on the disk. Each disk block allocated to a file contains
a pointer which points to the next disk block allocated to the same file.
• Advantages
• There is no external fragmentation with linked allocation.
• Any free block can be utilized in order to satisfy the file block
requests.
• File can continue to grow as long as the free blocks are available.
• Directory entry will only contain the starting block address.
• Disadvantages
• Random Access is not provided.
• Pointers require some space in the disk blocks.
• Any of the pointers in the linked list must not be broken otherwise
the file will get corrupted.
• Need to traverse each block.
File Allocation Methods : Indexed Allocation
• Indexed Allocation : Instead of maintaining a file allocation table of all the disk pointers, Indexed
allocation scheme stores all the disk pointers in one of the blocks called as indexed block. Indexed block
doesn't hold the file data, but it holds the pointers to all the disk blocks allocated to that particular file.
Directory entry will only contain the index block address.
• Advantages
• Supports direct access
• A bad data block causes the lost of only that block.
• Disadvantages
• A bad index block could cause the lost of entire file.
• Size of a file depends upon the number of pointers, a
index block can hold.
• Having an index block for a small file is totally
wastage.
• More pointer overhead
Master Boot Record (MBR)
• Master boot record is the information present in the first sector of any hard
disk. It contains the information regarding how and where the Operating
system is located in the hard disk so that it can be booted in the RAM.
• MBR is sometimes called master partition table because it includes a partition
table which locates every partition in the hard disk.
• Master boot record (MBR) also includes a program which reads the boot
sector record of the partition that contains operating system.

You might also like