Professional Documents
Culture Documents
Mr.V.Yuvaraj
Assistant Professor – Department of Computer Applications
Dr. N.G.P. ARTS AND SCIENCE COLLEGE
Dr. N.G.P.-KALAPATTI ROAD
COIMBATORE-641 048
Tamil Nadu, India
Mobile: +917502919891,
E-mail: yuvaraj.v@drngpasc.ac.in
Dr. NGPASC
COIMBATORE | INDIA
Unit-V: Disk Scheduling and File System
Dr. NGPASC
COIMBATORE | INDIA
I/O Systems
• I/O Hardware
Dr. NGPASC
COIMBATORE | INDIA
Objectives
• Explore the structure of an operating
system’s I/O subsystem
Dr. NGPASC
COIMBATORE | INDIA
Overview
• I/O management is a major component of operating system
design and operation
– Important aspect of computer operation
– I/O devices vary greatly
– Various methods to control them
– Performance management
– New types of devices frequent
Dr. NGPASC
COIMBATORE | INDIA
I/O Hardware (Cont.)
• I/O instructions control devices
• Devices usually have registers where device driver places
commands, addresses, and data to write, or read data from
registers after command execution
– Data-in register, data-out register, status register, control register
– Typically 1-4 bytes, or FIFO buffer
• Devices have addresses, used by
– Direct I/O instructions
– Memory-mapped I/O
• Device data and command registers mapped to processor address
space
• Especially for large address spaces (graphics)
Dr. NGPASC
COIMBATORE | INDIA
Device I/O Port Locations on PCs (partial)
Dr. NGPASC
COIMBATORE | INDIA
Polling
• For each byte of I/O
1. Read busy bit from status register until 0
2. Host sets read or write bit and if write copies data into data-out register
3. Host sets command-ready bit
4. Controller sets busy bit, executes transfer
5. Controller clears busy bit, error bit, command-ready bit when transfer done
Dr. NGPASC
COIMBATORE | INDIA
Interrupts
• Polling can happen in 3 instruction cycles
– Read status, logical-and to extract status bit, branch if not zero
– How to be more efficient if non-zero infrequently?
• CPU Interrupt-request line triggered by I/O device
– Checked by processor after each instruction
• Interrupt handler receives interrupts
– Maskable to ignore or delay some interrupts
• Interrupt vector to dispatch interrupt to correct handler
– Context switch at start and end
– Based on priority
– Some nonmaskable
– Interrupt chaining if more than one device at same interrupt number
Dr. NGPASC
COIMBATORE | INDIA
Interrupt-Driven I/O Cycle
Dr. NGPASC
COIMBATORE | INDIA
Intel Pentium Processor Event-Vector Table
Dr. NGPASC
COIMBATORE | INDIA
Interrupts (Cont.)
• Interrupt mechanism also used for exceptions
– Terminate process, crash system due to hardware error
Dr. NGPASC
COIMBATORE | INDIA
Direct Memory Access
• Used to avoid programmed I/O (one byte at a time) for large data
movement
• Bypasses CPU to transfer data directly between I/O device and memory
Dr. NGPASC
COIMBATORE | INDIA
Six Step Process to Perform DMA Transfer
Dr. NGPASC
COIMBATORE | INDIA
Disk Scheduling
• The operating system is responsible for using
hardware efficiently — for the disk drives, this
means having a fast access time and disk
bandwidth
• Minimize seek time
• Seek time seek distance
• Disk bandwidth is the total number of bytes
transferred, divided by the total time between the
first request for service and the completion of the
last transfer
Dr. NGPASC
COIMBATORE | INDIA
Disk Scheduling (Cont.)
Head pointer 53
Dr. NGPASC
COIMBATORE | INDIA
FCFS
Dr. NGPASC
COIMBATORE | INDIA
SSTF
• Shortest Seek Time First selects the request with
the minimum seek time from the current head
position
Dr. NGPASC
COIMBATORE | INDIA
SSTF (Cont.)
Dr. NGPASC
COIMBATORE | INDIA
SCAN
• The disk arm starts at one end of the disk, and moves toward
the other end, servicing requests until it gets to the other end
of the disk, where the head movement is reversed and
servicing continues.
Dr. NGPASC
COIMBATORE | INDIA
SCAN (Cont.)
Dr. NGPASC
COIMBATORE | INDIA
C-SCAN
• The head moves from one end of the disk to the other, servicing
requests as it goes
– When it reaches the other end, however, it immediately returns to the
beginning of the disk, without servicing any requests on the return trip
• Treats the cylinders as a circular list that wraps around from the
last cylinder to the first one
Dr. NGPASC
COIMBATORE | INDIA
C-SCAN (Cont.)
Dr. NGPASC
COIMBATORE | INDIA
C-LOOK
• LOOK a version of SCAN, C-LOOK a version of C-SCAN
Dr. NGPASC
COIMBATORE | INDIA
C-LOOK (Cont.)
Dr. NGPASC
COIMBATORE | INDIA
File-System Interface
• File Concept
• Access Methods
• Directory Structure
Dr. NGPASC
COIMBATORE | INDIA
Objectives
• Types:
– Data
• numeric
• character
• binary
– Program
Dr. NGPASC
COIMBATORE | INDIA
File Structure
• None - sequence of words, bytes
• Simple record structure
– Lines
– Fixed length
– Variable length
• Complex Structures
– Formatted document
– Relocatable load file
• Can simulate last two with first method by inserting
appropriate control characters
• Who decides:
– Operating system
– Program
Dr. NGPASC
COIMBATORE | INDIA
File Attributes
• Name – only information kept in human-readable form
• Identifier – unique tag (number) identifies file within file
system
• Type – needed for systems that support different types
• Location – pointer to file location on device
• Size – current file size
• Protection – controls who can do reading, writing, executing
• Time, date, and user identification – data for protection,
security, and usage monitoring
• Information about files are kept in the directory structure,
which is maintained on the disk
Dr. NGPASC
COIMBATORE | INDIA
File Operations
• File is an abstract data type
• Create
• Write
• Read
• Reposition within file
• Delete
• Truncate
• Open(Fi) – search the directory structure on disk for entry
Fi, and move the content of entry to memory
• Close (Fi) – move the content of entry Fi in memory to
directory structure on disk
Dr. NGPASC
COIMBATORE | INDIA
Open Files
• Several pieces of data are needed to manage
open files:
– File pointer: pointer to last read/write location, per
process that has the file open
– File-open count: counter of number of times a file is
open – to allow removal of data from open-file table
when last processes closes it
– Disk location of the file: cache of data access
information
– Access rights: per-process access mode information
Dr. NGPASC
COIMBATORE | INDIA
Open File Locking
• Provided by some operating systems and file
systems
• Mandatory or advisory:
– Mandatory – access is denied depending on locks
held and requested
– Advisory – processes can find status of locks and
decide what to do
Dr. NGPASC
COIMBATORE | INDIA
File Locking Example – Java API
import java.io.*;
import java.nio.channels.*;
public class LockingExample {
public static final boolean EXCLUSIVE = false;
public static final boolean SHARED = true;
public static void main(String arsg[]) throws IOException {
FileLock sharedLock = null;
FileLock exclusiveLock = null;
try {
RandomAccessFile raf = new RandomAccessFile("file.txt", "rw");
// get the channel for the file
FileChannel ch = raf.getChannel();
// this locks the first half of the file - exclusive
exclusiveLock = ch.lock(0, raf.length()/2, EXCLUSIVE);
/** Now modify the data . . . */
// release the lock
exclusiveLock.release();
Dr. NGPASC
COIMBATORE | INDIA
File Locking Example –
Java API (Cont.)
Dr. NGPASC
COIMBATORE | INDIA
File Types – Name, Extension
Dr. NGPASC
COIMBATORE | INDIA
Access Methods
• Sequential Access
read next
write next
reset
no read after last write
(rewrite)
• Direct Access
read n
write n
position to n
read next
write next
rewrite n
n = relative block number
Dr. NGPASC
COIMBATORE | INDIA
Sequential-access File
Dr. NGPASC
COIMBATORE | INDIA
Simulation of Sequential Access on
Direct-access File
Dr. NGPASC
COIMBATORE | INDIA
Example of Index and Relative Files
Dr. NGPASC
COIMBATORE | INDIA
Directory Structure
• A collection of nodes containing information about all files
Directory
Files
F1 F2 F4
F3
Fn
Dr. NGPASC
COIMBATORE | INDIA
A Typical File-system Organization
Dr. NGPASC
COIMBATORE | INDIA
Operations Performed on Directory
Dr. NGPASC
COIMBATORE | INDIA
Single-Level Directory
• A single directory for all users
Naming problem
Grouping problem
Dr. NGPASC
COIMBATORE | INDIA
Two-Level Directory
• Separate directory for each user
Path name
Can have the same file name for different user
Efficient searching
No grouping capability
Dr. NGPASC
COIMBATORE | INDIA
Tree-Structured Directories
Dr. NGPASC
COIMBATORE | INDIA
Tree-Structured Directories (Cont.)
• Efficient searching
• Grouping Capability
Dr. NGPASC
COIMBATORE | INDIA
Tree-Structured Directories (Cont)
• Absolute or relative path name
• Creating a new file is done in current directory
• Delete a file
rm <file-name>
• Creating a new subdirectory is done in current directory
mkdir <dir-name>
Example: if in current directory /mail
mkdir count
Dr. NGPASC
COIMBATORE | INDIA
Acyclic-Graph Directories (Cont.)
Dr. NGPASC
COIMBATORE | INDIA
General Graph Directory (Cont.)
Dr. NGPASC
COIMBATORE | INDIA
Dr. NGPASC
COIMBATORE | INDIA 57