OS Unit-IV - File Organization and Disk Scheduling
OS Unit-IV - File Organization and Disk Scheduling
Create
Write
Read
Delete
Truncate
File Organization - Access Methods
A file can be accessed in several ways
Sequential Access
Indexed Access
Device Directory:
A collection of nodes containing information about all
files on a partition.
8
Information in a Device Directory
File Name
File Type
Address or Location
Current Length
Maximum Length
Date created, Date last accessed
Date last updated
Operations Performed on Directory
Search for a file
Create a file
Delete a file
List a directory
Rename a file
Traverse the file system
Single Level Directory
A single directory for all users
Naming Problem and Grouping Problem
As the number of files increases, difficult to
remember unique names
As the number of users increase, users must have
unique names.
Two Level Directory
Introduced to remove naming problem between users
First Level contains list of user directories
Second Level contains user files
Need to specify Path name
Can have same file names for different users.
System files kept in separate directory or Level 1.
Efficient searching
Two Level Directory
Tree Structured Directories
Arbitrary depth of directories
Leaf nodes are files, interior nodes are directories.
Efficient Searching
Grouping Capability
Current Directory (working directory)
MS-DOS, Linux uses a tree structured directory
Tree structured Directories
Tree Structured Directories
Absolute or relative path name
Absolute from root
Relative paths from current working directory
pointer.
Creating a new file is done in current directory
Creating a new subdirectory is done in current
directory, e.g. mkdir <dir-name>
Delete a file , e.g. rm file-name
Deletion of directory
Option 1 : Only delete if directory is empty
Option 2: delete all files and subdirectories under
directory
Allocation Methods
An allocation method refers to how disk blocks are allocated
for files.
Contiguous Allocation
Linked Allocation
Indexed Allocation
Contiguous Allocation
Each file occupies a set of contiguous blocks on the disk.
Problems
Wastage of disk space.
Use first fit or best fit. Leads to external fragmentation on
disk.
Files cannot grow - expanding file requires copying
Contiguous Allocation
Linked Allocation
Each file is a linked list of disk blocks
Blocks may be scattered anywhere on the disk.
The directory contains a pointer to the first and last
blocks of a file.
Each block contains a pointer to the next block.
Disadvantages
Lot of disk space used to store pointers,
Efficient for sequential access files .
Linked Allocation
Indexed Allocation
All pointers are stored into one location - The index block.
Need index table.
Supports sequential, direct and indexed access.
For a new file all the pointers in the index block are set to NILL
Disadvantage
pointer overhead – Greater than linked allocation
Index table
Indexed Allocation
23
Disk Structure
Disks are used as secondary storage medium for modern
computer.
Disks are addressed as a large one dimensional arrays of
logical blocks.
The size of the logical block is 512 bytes.
The 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.
24
24
Disk Scheduling
The number of sectors per track has been increasing as disk
technology improves
When a process needs an I/O to or from the disk, it issues a
system call to the OS .
The request specifies several pieces of information such as:
Whether this operation is input or output
The disk address for the transfer
The memory address for the transfer
The number of sectors to be transferred
25
25
Disk Scheduling
If the desired disk drive and controller are available the
request can be processed immediately.
If it is busy new requests for service will be placed in the
queue of pending requests for that drive.
For multiprogramming system the disk queue may have
several pending requests.
scheduling algorithms decide which pending request to
service next
26
Disk Scheduling-terms
Access time
Time taken total time taken to locate the sector to read or
write
Seek time
It is the time for the disk head to travel to the track of the disk
where the data will be read or written.
Rotational latency
It is the additional time waiting for the disk to rotate the
desired sector to the disk head.
27
Disk Scheduling
Several algorithms exist to schedule the servicing of disk I/O
requests.
FCFS
SSTF
SCAN
C-SCAN
28
FCFS
The simplest form of disk scheduling is the FCFS
scheduling
This algorithm is fair.
But it generally does not provide fastest service.
29
FCFS
31
SSTF
32
SCAN
The disk arm starts at one end of the disk, and moves
toward the other end
Requests are serviced as it reaches each cylinder until it
gets to the other end of the disk.
At the other end the direction of head movement is
reversed and servicing continues.
The head continuously scans back and forth across the
disk.
Also called the elevator algorithm.
33
SCAN (Cont.)
36