0% found this document useful (0 votes)
7 views48 pages

OS Module 5

The document provides an overview of file and storage management in operating systems, detailing file structures, operations, access methods, directory structures, and file allocation methods. It discusses various file operations such as creating, opening, reading, writing, renaming, and deleting files, along with different access methods including sequential, direct, and index sequential access. Additionally, it outlines directory structures like single-level, two-level, tree, acyclic graph, and general-graph, as well as file allocation methods such as contiguous, linked, and indexed allocation.
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)
7 views48 pages

OS Module 5

The document provides an overview of file and storage management in operating systems, detailing file structures, operations, access methods, directory structures, and file allocation methods. It discusses various file operations such as creating, opening, reading, writing, renaming, and deleting files, along with different access methods including sequential, direct, and index sequential access. Additionally, it outlines directory structures like single-level, two-level, tree, acyclic graph, and general-graph, as well as file allocation methods such as contiguous, linked, and indexed allocation.
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/ 48

OS Module 5

Storage Management
Prof. Prachii Shrivastava
File and File Structure:
► File is the named collection of related information that is recorded on
secondary storage such as magnetic disks, magnetic tapes and optical disks.
► In general, file is a sequence of bits, bytes, lines or records whose meaning is
defined by the file creator and user.
► File Structure:
OS File Operations
► File operations within an operating system (OS) encompass a set of essential
tasks and actions directed at files and directories residing within a computer's
file system. These operations are fundamental for the effective management
and manipulation of data stored on various storage devices. In this article, we
will learn different file operations and what are the system calls and APIs
used to perform them in a Linux / Windows-based OS.

•open() (Linux-like systems)
Creating Files Create a new file for data storage.
•CreateFile() (Windows)

Create a new directory for organizing •mkdir() (Linux systems)


Creating Directories
files. •CreateDirectory() (Windows)

Open a file that you already have •open() (Linux systems)


Opening Files
open to read or write from. •CreateFile() (Windows)

•read() (Linux systems)


Reading Files Retrieve data from an open file.
•ReadFile() (Windows)

•write() (Linux systems)


Writing Files Store data in an open file.
•WriteFile() (Windows)

If you want to rename a file or •rename() (Linux systems)


Renaming Files and Directories
directory,. •MoveFile() (Windows)

•unlink() (Linux systems)


•remove() (Linux systems)
Deleting Files and Directories Remove files or directories.
•DeleteFile() (Windows)
•RemoveDirectory() (Windows)
File Type:
File Access Methods:

► File access methods in an operating system are the techniques and processes used to read
from and write to files stored on a computer’s storage devices. There are several ways to
access this information in the file. Some systems provide only one access method for files.
Other systems, such as those of IBM, support many access methods, and choosing the right
one for a particular application is a major design problem.
► These methods determine how data is organized, retrieved, and modified within a file
system. Understanding file access methods is crucial for efficient data management and
system performance. In this article, we are going to discuss different types of methods to
access the file.
► File Access Methods
There are three ways to access a file in a computer system:
► Sequential-Access
► Direct Access
► Index sequential Method
Sequential Access
► It is the simplest access method. Information in the file is processed in order, one record
after the other. This mode of access is by far the most common; for example, the editor
and compiler usually access the file in this fashion.
Read and write make up the bulk of the operation on a file. A read operation -read
next- reads the next position of the file and automatically advances a file pointer, which
keeps track of the I/O location. Similarly, for the -write next- append to the end of the file
and advance to the newly written material. Key Points related to Sequential Access
► Data is accessed from one record right after another record in an order.
► When we use the read command, it moves ahead pointer by one.
► When we use the write command, it will allocate memory and move the pointer to the end
of the file.
► Such a method is reasonable for tape.
Advantages of Sequential Access Method
► It is simple to implement this file access mechanism.
► It useslexicographic order to quickly access the next entry.
► It is suitable for applications that require access to all records in a file, in a specific order.
► It is less prone to data corruption as the data is written sequentially and not randomly.
► It is a more efficient method for reading large files, as it only reads the required data and
does not waste time reading unnecessary data.
► It is a reliable method forbackup and restore operations, as the data is stored sequentially
and can be easily restored if required.
Disadvantages of Sequential Access Method
► If the file record that needs to be accessed next is not present next to the current record,
this type of file access method is slow.
► Moving a sizable chunk of the file may be necessary to insert a new record.
► It does not allow for quick access to specific records in the file. The entire file must be
searched sequentially to find a specific record, which can be time-consuming.
► It is not well-suited for applications that require frequent updates or modifications to the
file. Updating or inserting a record in the middle of a large file can be a slow and
cumbersome process.
► Sequential access can also result in wasted storage space if records are of varying lengths.
The space between records cannot be used by other records, which can result in inefficient
use of storage.
Direct Access Method
► Another method is direct access method also known as relative access
method. A fixed-length logical record that allows the program to read and
write record rapidly. in no particular order. The direct access is based on the
disk model of a file since disk allows random access to any file block. For
direct access, the file is viewed as a numbered sequence of block or record.
Thus, we may read block 14 then block 59, and then we can write block 17.
There is no restriction on the order of reading and writing for a direct access
file.
A block number provided by the user to the operating system is normally
a relative block number, the first relative block of the file is 0 and then 1 and
so on.
Advantages of Direct Access Method
► The files can be immediately accessed decreasing the average access time.
► In the direct access method, in order to access a block, there is no need of
traversing all the blocks present before it.

Disadvantages of Direct Access Method


► Complex Implementation : Implementing direct access can be complex,
requiring sophisticated algorithms and data structures to manage and locate
records efficiently.
► Higher Storage Overhead : Direct access methods often require additional
storage for maintaining data location information (such as pointers or address
tables), which can increase the overall storage requirements.
Index Sequential method

► It is the other method of accessing a file that is built on the top of the
sequential access method. These methods construct an index for the file. The
index, like an index in the back of a book, contains the pointer to the various
blocks. To find a record in the file, we first search the index, and then by the
help of pointer we access the file directly.
► Key Points Related to Index Sequential Method
► It is built on top of Sequential access.
► It control the pointer by using index.
Advantages of Index Sequential Method
► Efficient Searching : Index sequential method allows for quick searches through the index.
► Balanced Performance : It combines the simplicity of sequential access with the speed of direct
access, offering a balanced approach that can handle various types of data access needs efficiently.
► Flexibility : This method allows both sequential and random access to data, making it versatile for
different types of applications, such as batch processing and real-time querying.
► Improved Data Management : Indexing helps in better organization and management of data. It
makes data retrieval faster and more efficient, especially in large databases.
► Reduced Access Time : By using an index to directly locate data blocks, the time spent searching for
data within large datasets is significantly reduced.

Disadvantages of Index Sequential Method


► Complex Implementation : The index sequential method is more complex to implement and
maintain compared to simple sequential access methods.
► Additional Storage : Indexes require additional storage space, which can be significant for large
datasets. This extra space can sometimes offset the benefits of faster access.
► Update Overhead : Updating the data can be more time-consuming because both the data and the
indexes need to be updated. This can lead to increased processing time for insertions, deletions, and
modifications.
► Index Maintenance : Keeping the index up to date requires regular maintenance, especially in
dynamic environments where data changes frequently. This can add to the system’s overhead.
Directory Structure:
► A directory is a container that is used to contain folders and files. It organizes files and
folders in a hierarchical manner. In other words, directories are like folders that help
organize files on a computer. Just like you use folders to keep your papers and documents
in order, the operating system uses directories to keep track of files and where they are
stored. Different structures of directories can be used to organize these files, making it
easier to find and manage them.
► Understanding these directory structures is important because it helps in efficiently
organizing and accessing files on your computer. Following are the logical structures of a
directory, each providing a solution to the problem faced in the previous type of directory
structure.
Different Types of Directory in OS

► In an operating system, there are different types of directory structures that help
organize and manage files efficiently.
► Directories in an OS can be single-level, two-level, or hierarchical. To gain a
comprehensive understanding of file systems, explore the GATE CS Self-Paced
Course which covers operating systems in great detail.
► Each type of directory has its own way of arranging files and directories, offering
unique benefits and features.These are:
► Single-Level Directory
► Two-Level Directory
► Tree Structure/ Hierarchical Structure
► Acyclic Graph Structure
► General-Graph Directory Structure
1) Single-Level Directory

► The single-level directory is the simplest directory structure. In it, all files
are contained in the same directory which makes it easy to support and
understand.
A single level directory has a significant limitation, however, when the
number of files increases or when the system has more than one user. Since
all the files are in the same directory, they must have a unique name. If two
users call their dataset test, then the unique name rule violated.
Advantages
► Since it is a single directory, so its implementation is very easy.
► If the files are smaller in size, searching will become faster.
► The operations like file creation, searching, deletion, updating are very easy in such a directory structure.
► Logical Organization : Directory structures help to logically organize files and directories in a hierarchical
structure. This provides an easy way to navigate and manage files, making it easier for users to access the data
they need.
► Increased Efficiency: Directory structures can increase the efficiency of the file system by reducing the time
required to search for files. This is because directory structures are optimized for fast file access, allowing
users to quickly locate the file they need.
► Improved Security : Directory structures can provide better security for files by allowing access to be
restricted at the directory level. This helps to prevent unauthorized access to sensitive data and ensures that
important files are protected.
► Facilitates Backup and Recovery : Directory structures make it easier to backup and recover files in the event
of a system failure or data loss. By storing related files in the same directory, it is easier to locate and backup
all the files that need to be protected.
► Scalability: Directory structures are scalable, making it easy to add new directories and files as needed. This
helps to accommodate growth in the system and makes it easier to manage large amounts of data.
Disadvantages
► There may chance of name collision because two files can have the same name.
► Searching will become time taking if the directory is large.
► This can not group the same type of files together.
2) Two-Level Directory
► As we have seen, a single level directory often leads to confusion of files
names among different users. The solution to this problem is to create
a separate directory for each user.
► In the two-level directory structure, each user has their own user files
directory (UFD). The UFDs have similar structures, but each lists only the
files of a single user. System’s master file directory (MFD) is searched
whenever a new user id is created.
Advantages
► The main advantage is there can be more than two files with same name, and
would be very helpful if there are multiple users.
► A security would be there which would prevent user to access other user’s
files.
► Searching of the files becomes very easy in this directory structure.
Disadvantages
► As there is advantage of security, there is also disadvantage that the user
cannot share the file with the other users.
► Unlike the advantage users can create their own files, users don’t have the
ability to create subdirectories.
► Scalability is not possible because one user can’t group the same types of files
together.
3) Tree Structure/ Hierarchical Structure
► Tree directory structure of operating system is most commonly used in our personal
computers. User can create files and subdirectories too, which was a disadvantage in
the previous directory structures.
► This directory structure resembles a real tree upside down, where the root directory is
at the peak. This root contains all the directories for each user. The users can create
subdirectories and even store files in their directory.
► A user do not have access to the root directory data and cannot modify it. And, even in
this directory the user do not have access to other user’s directories. The structure of
tree directory is given below which shows how there are files and subdirectories in each
user’s directory.
Advantages
► This directory structure allows subdirectories inside a directory.
► The searching is easier.
► File sorting of important and unimportant becomes easier.
► This directory is more scalable than the other two directory structures
explained.
Disadvantages
► As the user isn’t allowed to access other user’s directory, this prevents the
file sharing among users.
► As the user has the capability to make subdirectories, if the number of
subdirectories increase the searching may become complicated.
► Users cannot modify the root directory data.
► If files do not fit in one, they might have to be fit into other directories.
4) Acyclic Graph Structure
► As we have seen the above three directory structures, where none of them have the
capability to access one file from multiple directories. The file or the subdirectory could be
accessed through the directory it was present in, but not from the other directory.
► This problem is solved in acyclic graph directory structure, where a file in one directory can
be accessed from multiple directories. In this way, the files could be shared in between the
users. It is designed in a way that multiple directories point to a particular directory or file
with the help of links.
► In the below figure, this explanation can be nicely observed, where a file is shared between
multiple users. If any user makes a change, it would be reflected to both the users.
Advantages
► Sharing of files and directories is allowed between multiple users.
► Searching becomes too easy.
► Flexibility is increased as file sharing and editing access is there for multiple
users.

Disadvantages
► Because of the complex structure it has, it is difficult to implement this
directory structure.
► The user must be very cautious to edit or even deletion of file as the file is
accessed by multiple users.
► If we need to delete the file, then we need to delete all the references of the
file inorder to delete it permanently.
5) General-Graph Directory Structure
► Unlike the acyclic-graph directory, which avoids loops, the general-graph
directory can have cycles, meaning a directory can contain paths that loop
back to the starting point. This can make navigating and managing files more
complex.
Advantages of General-Graph Directory
► More flexible than other directory structures.
► Allows cycles, meaning directories can loop back to each other.

Disadvantages of General-Graph Directory


► More expensive to implement compared to other solutions.
► Requires garbage collection to manage and clean up unused files and
directories.
File Allocation Methods:

► The allocation methods define how the files are stored in the disk blocks.
There are three main disk space or file allocation methods.
► Contiguous Allocation
► Linked Allocation
► Indexed Allocation
The main idea behind these methods is to provide:
► Efficient disk space utilization.
► Fast access to the file blocks.
1. Contiguous Allocation
► In this scheme, each file occupies a contiguous set of blocks on the disk. For example, if a file
requires n blocks and is given a block b as the starting location, then the blocks assigned to the file
will be: b, b+1, b+2,……b+n-1. This means that given the starting block address and the length of the
file (in terms of blocks required), we can determine the blocks occupied by the file.
The directory entry for a file with contiguous allocation contains
► Address of starting block
► Length of the allocated portion.
► The file ‘mail’ in the following figure starts from the block 19 with length = 6 blocks. Therefore, it
occupies 19, 20, 21, 22, 23, 24 blocks.

► Advantages:
► Both the Sequential and Direct Accesses are supported by this. For direct
access, the address of the kth block of the file which starts at block b can
easily be obtained as (b+k).
► This is extremely fast since the number of seeks are minimal because of
contiguous allocation of file blocks.
► Disadvantages:
► This method suffers from both internal and external fragmentation. This
makes it inefficient in terms of memory utilization.
► Increasing file size is difficult because it depends on the availability of
contiguous memory at a particular instance.
2. Linked List Allocation
► In this scheme, each file is a linked list of disk blocks which need not be contiguous. The
disk blocks can be scattered anywhere on the disk.
The directory entry contains a pointer to the starting and the ending file block. Each block
contains a pointer to the next block occupied by the file.
► The file ‘jeep’ in following image shows how the blocks are randomly distributed. The last
block (25) contains -1 indicating a null pointer and does not point to any other block.
► Advantages:
► This is very flexible in terms of file size. File size can be increased easily
since the system does not have to look for a contiguous chunk of memory.
► This method does not suffer from external fragmentation. This makes it
relatively better in terms of memory utilization.
► Disadvantages:
► Because the file blocks are distributed randomly on the disk, a large number
of seeks are needed to access every block individually. This makes linked
allocation slower.
► It does not support random or direct access. We can not directly access the
blocks of a file. A block k of a file can be accessed by traversing k blocks
sequentially (sequential access ) from the starting block of the file via block
pointers.
► Pointers required in the linked allocation incur some extra overhead.
3. Indexed Allocation

► In this scheme, a special block known as the Index block contains the
pointers to all the blocks occupied by a file. Each file has its own index block.
The ith entry in the index block contains the disk address of the ith file block.
The directory entry contains the address of the index block as shown in the
image:
► Advantages:
► This supports direct access to the blocks occupied by the file and therefore
provides fast access to the file blocks.
► It overcomes the problem of external fragmentation.
► Disadvantages:
► The pointer overhead for indexed allocation is greater than linked allocation.
► For very small files, say files that expand only 2-3 blocks, the indexed
allocation would keep one entire block (index block) for the pointers which is
inefficient in terms of memory utilization. However, in linked allocation we
lose the space of only 1 pointer per block.
Disk Scheduling:
Key Terms Associated with Disk Scheduling

► 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 written. So the disk scheduling algorithm that gives a minimum average seek time is
better.
► Rotational Latency: Rotational Latency is the time taken by the desired sector of the 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 the number of bytes to be transferred.
► Disk Access Time:
Disk Access Time = Seek Time + Rotational Latency + Transfer Time
Total Seek Time = Total head Movement * Seek TimeDisk Response Time: Response Time is the average
time spent by a request waiting to perform its I/O operation. The average Response time is the response
time of all requests. Variance Response Time is the measure of how individual requests are serviced with
respect to average response time. So the disk scheduling algorithm that gives minimum variance
response time is better.
Goal of Disk Scheduling Algorithms
► Minimize Seek Time
► Maximize Throughput
► Minimize Latency
► Fairness
► Efficiency in Resource Utilization

Disk Scheduling Algorithms


► FCFS (First Come First Serve)
► SSTF (Shortest Seek Time First)
► SCAN
► C-SCAN
► LOOK
► C-LOOK
► RSS (Random Scheduling)
► LIFO (Last-In First-Out)
► N-STEP SCAN
► F-SCAN
FCFS:
SSTF:
SCAN: 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”.

► cc
Suppose the requests to be addressed
C-SCAN: 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”.

► dg
Suppose the requests to be addressed
LOOK: 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”.

► ko
Suppose the requests to be addressed
C-LOOK: 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”.
Raid:
RAID (Redundant Arrays of Independent Disks) is a technique that makes use of a
combination of multiple disks for storing the data instead of using a single disk for
increased performance, data redundancy, or to protect data in the case of a drive
failure. The term was defined by David Patterson, Garth A. Gibson, and Randy Katz
at the University of California, Berkeley in 1987. In this article, we are going to
discuss RAID and types of RAID their Advantages and disadvantages in detail.
What is RAID?
RAID (Redundant Array of Independent Disks) is like having backup copies of your
important files stored in different places on several hard drives or solid-state drives
(SSDs). If one drive stops working, your data is still safe because you have other
copies stored on the other drives. It’s like having a safety net to protect your files
from being lost if one of your drives breaks down.
RAID (Redundant Array of Independent Disks) in a Database Management System
(DBMS) is a technology that combines multiple physical disk drives into a single
logical unit for data storage. The main purpose of RAID is to improve data
reliability, availability, and performance. There are different levels of RAID, each
offering a balance of these benefits.
RAID Level 0
RAID Level 1
RAID Level 1 0
RAID Level 2
Parity:
RAID Level 3
Raid Level 4
RAID Level 5
RAID Level 6

You might also like