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

File Management

A file system provides organization and structure to files stored on storage devices. It allows files to be created, read, updated and deleted in an organized manner. A file system defines file attributes like name, size, permissions and location. It also supports different file types like text, binary and directories. File access methods like sequential, direct and indexed access are used to retrieve files from storage. Directories are used to group related files and provide a hierarchical structure to file systems.

Uploaded by

Mamatha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views

File Management

A file system provides organization and structure to files stored on storage devices. It allows files to be created, read, updated and deleted in an organized manner. A file system defines file attributes like name, size, permissions and location. It also supports different file types like text, binary and directories. File access methods like sequential, direct and indexed access are used to retrieve files from storage. Directories are used to group related files and provide a hierarchical structure to file systems.

Uploaded by

Mamatha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

What is File System?

A file is a collection of correlated information which is recorded on secondary or


non-volatile storage like magnetic disks, optical disks, and tapes. It is a method
of data collection that is used as a medium for giving input and receiving output
from that program.

In general, a file is a sequence of bits, bytes, or records whose meaning is


defined by the file creator and user. Every File has a logical location where they
are located for storage and retrieval.

Objective of File management System

Here are the main objectives of the file management system:ay

 It provides I/O support for a variety of storage device types.


 Minimizes the chances of lost or destroyed data
 Helps OS to standardized I/O interface routines for user processes.
 It provides I/O support for multiple users in a multiuser systems
environment.

Properties of a File System

Here, are important properties of a file system:

 Files are stored on disk or other storage and do not disappear when a user
logs off.
 Files have names and are associated with access permission that permits
controlled sharing.
 Files could be arranged or more complex structures to reflect the
relationship between them.

File structure

A File Structure needs to be predefined format in such a way that an operating


system understands . It has an exclusively defined structure, which is based on
its type.

Three types of files structure in OS:

 A text file: It is a series of characters that is organized in lines.


 An object file: It is a series of bytes that is organized into blocks.
 A source file: It is a series of functions and processes.

File Attributes
A file has a name and data. Moreover, it also stores meta information like file
creation date and time, current size, last modified date, etc. All this information is
called the attributes of a file system.

Here, are some important File attributes used in OS:

 Name: It is the only information stored in a human-readable form.


 Identifier: Every file is identified by a unique tag number within a file
system known as an identifier.
 Location: Points to file location on device.
 Type: This attribute is required for systems that support various types of
files.
 Size. Attribute used to display the current file size.
 Protection. This attribute assigns and controls the access rights of
reading, writing, and executing the file.
 Time, date and security: It is used for protection, security, and also used
for monitoring

File Type

It refers to the ability of the operating system to differentiate various types of files
like text files, binary, and source files. However, Operating systems like MS_DOS
and UNIX has the following type of files:

Character Special File

It is a hardware file that reads or writes data character by character, like mouse,
printer, and more.

Ordinary files

 These types of files stores user information.


 It may be text, executable programs, and databases.
 It allows the user to perform operations like add, delete, and modify.

Directory Files

 Directory contains files and other related information about those files. Its
basically a folder to hold and organize multiple files.

Special Files

 These files are also called device files. It represents physical devices like
printers, disks, networks, flash drive, etc.

Functions of File

 Create file, find space on disk, and make an entry in the directory.
 Write to file, requires positioning within the file
 Read from file involves positioning within the file
 Delete directory entry, regain disk space.
 Reposition: move read/write position.

Commonly used terms in File systems

Field:

This element stores a single value, which can be static or variable length.

DATABASE:

Collection of related data is called a database. Relationships among elements of


data are explicit.

FILES:

Files is the collection of similar record which is treated as a single entity.

RECORD:

A Record type is a complex data type that allows the programmer to create a
new data type with the desired column structure. Its groups one or more columns
to form a new data type. These columns will have their own names and data
type.

File Access Methods

File access is a process that determines the way that files are accessed and read
into memory. Generally, a single access method is always supported by
operating systems. Though there are some operating system which also
supports multiple access methods.

Three file access methods are:

 Sequential access
 Direct random access
 Index sequential access

Sequential Access
 Most of the operating systems access the file sequentially. In
other words, we can say that most of the files need to be
accessed sequentially by the operating system.
 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.
 Suppose every block of the storage stores 4 records and we
know that the record we needed is stored in 10th block. In that
case, the sequential access will not be implemented because it
will traverse all the blocks in order to access the needed record.
 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

What is a directory?

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.
A directory can be viewed as a file which contains the Meta data of the
bunch of files.

Every Directory supports a number of common operations on the file:

1. File Creation
2. Search for the file
3. File deletion
4. Renaming the file
5. Traversing Files
6. Listing of files

Single Level Directory

The simplest method is to have one big list of all the files on the
disk. The entire system will contain only one directory which is
supposed to mention all the files present in the file system. The
directory contains one entry per each file present on the file system.

This type of directories can be used for a simple system.


Advantages

1. Implementation is very simple.


2. If the sizes of the files are very small then the searching
becomes faster.
3. File creation, searching, deletion is very simple since we have
only one directory.

Disadvantages

1. We cannot have two files with the same name.


2. The directory may be very big therefore searching for a file
may take so much time.
3. Protection cannot be implemented for multiple users.
4. There are no ways to group same kind of files.
5. Choosing the unique name for every file is a bit complex and
limits the number of files in the system because most of the
Operating System limits the number of characters used to
construct the file name.

Two Level Directory

In two level directory systems, we can create a separate directory for


each user. There is one master directory which contains separate
directories dedicated to each user. For each user, there is a different
directory present at the second level, containing group of user's file.
The system doesn't let a user to enter in the other user's directory
without permission.

Characteristics of two level directory system


1. Each files has a path name as /User-name/directory-name/
2. Different users can have the same file name.
3. Searching becomes more efficient as only one user's list needs to
be traversed.
4. The same kind of files cannot be grouped into a single directory
for a particular user.

Every Operating System maintains a variable as PWD which contains


the present directory name (present user name) so that the searching
can be done appropriately.

Tree Structured Directory

In Tree structured directory system, any directory entry can either


be a file or sub directory. Tree structured directory system
overcomes the drawbacks of two level directory system. The similar
kind of files can now be grouped in one directory.

Each user has its own directory and it cannot enter in the other
user's directory. However, the user has the permission to read the
root's data but he cannot write or modify this. Only administrator of
the system has the complete access of root directory.

Searching is more efficient in this directory structure. The concept of


current working directory is used. A file can be accessed by two
types of path, either relative or absolute.

Absolute path is the path of the file with respect to the root directory
of the system while relative path is the path with respect to the
current working directory of the system. In tree structured directory
systems, the user is given the privilege to create the files as well as
directories.
Permissions on the file and directory

A tree structured directory system may consist of various levels


therefore there is a set of permissions assigned to each file and
directory.

The permissions are R W X which are regarding reading, writing and


the execution of the files or directory. The permissions are assigned
to three types of users: owner, group and others.

There is a identification bit which differentiate between directory and


file. For a directory, it is d and for a file, it is dot (.)

File Allocation Methods

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.

There are following methods which can be used for allocation.

1. Contiguous Allocation.
2. Extents
3. Linked Allocation
4. Clustering
5. FAT
6. Indexed Allocation
7. Linked Indexed Allocation
8. Multilevel Indexed Allocation
9. Inode

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 allocation scheme is known as contiguous allocation.

In the image shown below, there are three files in the directory. The
starting block and the length of each file are mentioned in the table.
We can check in the table that the contiguous blocks are assigned to
each file as per its need.

Advantages

1. It is simple to implement.
2. We will get Excellent read performance.
3. Supports Random Access into files.

Disadvantages

1. The disk will become fragmented.


2. It may be difficult to have a file grow.

Linked List Allocation

Linked List allocation 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

1. There is no external fragmentation with linked allocation.


2. Any free block can be utilized in order to satisfy the file block
requests.
3. File can continue to grow as long as the free blocks are available.
4. Directory entry will only contain the starting block address.

Disadvantages

1. Random Access is not provided.


2. Pointers require some space in the disk blocks.
3. Any of the pointers in the linked list must not be broken
otherwise the file will get corrupted.
4. Need to traverse each block.

Indexed Allocation Scheme

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

1. Supports direct access


2. A bad data block causes the lost of only that block.

Disadvantages

1. A bad index block could cause the lost of entire file.


2. Size of a file depends upon the number of pointers, a index block
can hold.
3. Having an index block for a small file is totally wastage.
4. More pointer overhead

Free Space Management

A file system is responsible to allocate the free blocks to the file


therefore it has to keep track of all the free blocks present in the disk.
There are mainly two approaches by using which, the free blocks in
the disk are managed.

1. Bit Vector

In this approach, the free space list is implemented as a bit map


vector. It contains the number of bits where each bit represents each
block.

If the block is empty then the bit is 1 otherwise it is 0. Initially all the
blocks are empty therefore each bit in the bit map vector contains 1.

LAs the space allocation proceeds, the file system starts allocating
blocks to the files and setting the respective bit to 0.

2. Linked List
It is another approach for free space management. This approach
suggests linking together all the free blocks and keeping a pointer in
the cache which points to the first free block.

Therefore, all the free blocks on the disks will be linked together with a
pointer. Whenever a block gets allocated, its previous free block will be
linked to its next free block.

Disk Scheduling

As we know, a process needs two type of time, CPU time and IO


time. For I/O, it requests the Operating system to access the disk.

However, the operating system must be fare enough to satisfy each


request and at the same time, operating system must maintain the
efficiency and speed of process execution.

The technique that operating system uses to determine the request


which is to be satisfied next is called disk scheduling.

Let's discuss some important terms related to disk scheduling.

Seek Time

Seek time is the time taken in locating the disk arm to a specified
track where the read/write request will be satisfied.

Rotational Latency

It is the time taken by the desired sector to rotate itself to the


position from where it can access the R/W heads.

Transfer Time

It is the time taken to transfer the data.

Disk Access Time

Disk access time is given as,

Disk Access Time = Rotational Latency + Seek Time + Transfer Time


Disk Response Time

It is the average of time spent by each request waiting for the IO


operation.

Purpose of Disk Scheduling

The main purpose of disk scheduling algorithm is to select a disk


request from the queue of IO requests and decide the schedule
when this request will be processed.

Goal of Disk Scheduling Algorithm


o Fairness
o High throughout
o Minimal traveling head time

Disk Scheduling Algorithms

The list of various disks scheduling algorithm is given below. Each


algorithm is carrying some advantages and disadvantages. The
limitation of each algorithm leads to the evolution of a new
algorithm.

o FCFS scheduling algorithm


o SSTF (shortest seek time first) algorithm
o SCAN scheduling
o C-SCAN scheduling
o LOOK Scheduling
o C-LOOK scheduling

FCFS Scheduling Algorithm

It is the simplest Disk Scheduling algorithm. It services the IO


requests in the order in which they arrive. There is no starvation in
this algorithm, every request is serviced.

Disadvantages

o The scheme does not optimize the seek time.


o The request may come from different processes therefore there
is the possibility of inappropriate movement of the head.
Example

Consider the following disk request sequence for a disk with 100 tracks
45, 21, 67, 90, 4, 50, 89, 52, 61, 87, 25

Head pointer starting at 50 and moving in left direction. Find the


number of head movements in cylinders using FCFS scheduling.

Solution

Number of cylinders moved by the head

= (50-45)+(45-21)+(67-21)+(90-67)+(90-4)+(50-4)+(89-50)+(61-
52)+(87-61)+(87-25)

= 5 + 24 + 46 + 23 + 86 + 46 + 49 + 9 + 26 + 62

= 376

SSTF Scheduling Algorithm

Shortest seek time first (SSTF) algorithm selects the disk I/O request
which requires the least disk arm movement from its current position
regardless of the direction. It reduces the total seek time as compared
to FCFS.

It allows the head to move to the closest track in the service queue.

Disadvantages

o It may cause starvation for some requests.


o Switching direction on the frequent basis slows the working of
algorithm.
o It is not the most optimal algorithm.

Example

Consider the following disk request sequence for a disk with 100 tracks

45, 21, 67, 90, 4, 89, 52, 61, 87, 25

Head pointer starting at 50. Find the number of head movements in


cylinders using SSTF scheduling.

Solution:

Number of cylinders = 5 + 7 + 9 + 6 + 20 + 2 + 1 + 65 + 4 + 17 =
136

SCAN and C-SCAN algorithm

Scan Algorithm

It is also called as Elevator Algorithm. In this algorithm, the disk arm


moves into a particular direction till the end, satisfying all the requests
coming in its path,and then it turns backand moves in the reverse
direction satisfying requests coming in its path.

It works in the way an elevator works, elevator moves in a direction


completely till the last floor of that direction and then turns back.

Example

Consider the following disk request sequence for a disk with 100 tracks
98, 137, 122, 183, 14, 133, 65, 78

Head pointer starting at 54 and moving in left direction. Find the


number of head movements in cylinders using SCAN scheduling.

Number of Cylinders = 40 + 14 + 65 + 13 + 20 + 24 + 11 + 4 + 46 =
237

C-SCAN algorithm

In C-SCAN algorithm, the arm of the disk moves in a particular


direction servicing requests until it reaches the last cylinder, then it
jumps to the last cylinder of the opposite direction without servicing
any request then it turns back and start moving in that direction
servicing the remaining requests.

Example

Consider the following disk request sequence for a disk with 100 tracks

98, 137, 122, 183, 14, 133, 65, 78

Head pointer starting at 54 and moving in left direction. Find the


number of head movements in cylinders using C-SCAN scheduling.
No. of cylinders crossed = 40 + 14 + 199 + 16 + 46 + 4 + 11 + 24 +
20 + 13 = 387

Look Scheduling

It is like SCAN scheduling Algorithm to some extant except the


difference that, in this scheduling algorithm, the arm of the disk stops
moving inwards (or outwards) when no more request in that direction
exists. This algorithm tries to overcome the overhead of SCAN
algorithm which forces disk arm to move in one direction till the end
regardless of knowing if any request exists in the direction or not.

Example

Consider the following disk request sequence for a disk with 100 tracks

98, 137, 122, 183, 14, 133, 65, 78

Head pointer starting at 54 and moving in left direction. Find the


number of head movements in cylinders using LOOK scheduling.
Number of cylinders crossed = 40 + 51 + 13 + +20 + 24 + 11 + 4 +
46 = 209

C Look Scheduling

C Look Algorithm is similar to C-SCAN algorithm to some extent. In


this algorithm, the arm of the disk moves outwards servicing requests
until it reaches the highest request cylinder, then it jumps to the
lowest request cylinder without servicing any request then it again
start moving outwards servicing the remaining requests.

It is different from C SCAN algorithm in the sense that, C SCAN force


the disk arm to move till the last cylinder regardless of knowing
whether any request is to be serviced on that cylinder or not.

Example

Consider the following disk request sequence for a disk with 100 tracks

98, 137, 122, 183, 14, 133, 65, 78

Head pointer starting at 54 and moving in left direction. Find the


number of head movements in cylinders using C LOOK scheduling.
Number of cylinders crossed = 11 + 13 + 20 + 24 + 11 + 4 + 46 +
169 = 298

File types- name, extension

File Type Usual extension Function

Executable exe, com, bin or ready-to-run machine- language program


none

Object obj, o complied, machine language, not linked

Source code c. p, pas, 177, source code in various languages


asm, a

Batch bat, sh Series of commands to be executed

Text txt, doc textual data documents

Word doc,docs, tex, rrf, various word-processor formats


processor etc.

Library lib, h libraries of routines


Archive arc, zip, tar related files grouped into one file, sometimes
compressed.

You might also like