0% found this document useful (0 votes)
8 views46 pages

OS Unit 4

The document discusses file management in operating systems, outlining key concepts such as file systems, attributes, types, and access methods. It details various directory structures including single-level, two-level, tree-structured, and acyclic graph directories, highlighting their advantages and disadvantages. Additionally, it covers file allocation methods and the importance of directories in maintaining file information and organization.

Uploaded by

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

OS Unit 4

The document discusses file management in operating systems, outlining key concepts such as file systems, attributes, types, and access methods. It details various directory structures including single-level, two-level, tree-structured, and acyclic graph directories, highlighting their advantages and disadvantages. Additionally, it covers file allocation methods and the importance of directories in maintaining file information and organization.

Uploaded by

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

TECHNO NJR INSTITUTE OF ENGINEERING,UDAIPUR

Year & Sem – III year & V Sem


Subject – Operating System
Topic : File Management (UNIT 4)
Presented by – Mr.Pushpendra Singh Chundawat, Assistant Professor,
CSE

By Pushpendra Singh Chundawat 1 1


Introduction

1 2
By Pushpendra Singh Chundawat
Cont..

1 3
By Pushpendra Singh Chundawat
Cont..

1 4
By Pushpendra Singh Chundawat
Cont..
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.

By Pushpendra Singh Chundawat 1 5


Objective of File management System
Here are the main objectives of the file management system:

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.

By Pushpendra Singh Chundawat 1 6


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.

By Pushpendra Singh Chundawat 1 7


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.

By Pushpendra Singh Chundawat 1 8


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

By Pushpendra Singh Chundawat 1 9


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.

By Pushpendra Singh Chundawat 1 10


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.

By Pushpendra Singh Chundawat 1 11


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.

By Pushpendra Singh Chundawat 1 12


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
In this type of file access method, records are accessed in a certain pre-defined
sequence. In the sequential access method, information stored in the file is also
processed one by one. Most compilers access files using this access method.

By Pushpendra Singh Chundawat 1 13


Cont..

Random Access

The random access method is also called direct random access. This method
allow accessing the record directly. Each record has its own address on which
can be directly accessed for reading and writing.

Sequential Access

This type of accessing method is based on simple sequential access. In this


access method, an index is built for every file, with a direct pointer to different
memory blocks. In this method, the Index is searched sequentially, and its pointer
can access the file directly. Multiple levels of indexing can be used to offer
greater efficiency in access. It also reduces the time needed to access a single
record.

By Pushpendra Singh Chundawat 1 14


Space Allocation

In the Operating system, files are always allocated disk spaces.


Three types of space allocation methods are:
Linked Allocation
Indexed Allocation
Contiguous Allocation

Contiguous Allocation

In this method,
Every file users a contiguous address space on memory.
Here, the OS assigns disk address is in linear order.
In the contiguous allocation method, external fragmentation is the biggest issue.

By Pushpendra Singh Chundawat 1 15


Cont..

Linked Allocation
In this method,
Every file includes a list of links.
The directory contains a link or pointer in the first block of a file.
With this method, there is no external fragmentation
This File allocation method is used for sequential access files.
This method is not ideal for a direct access file.
Indexed Allocation
In this method,
Directory comprises the addresses of index blocks of the specific files.
An index block is created, having all the pointers for specific files.
All files should have individual index blocks to store the addresses for disk
space.

By Pushpendra Singh Chundawat 1 16


File Directories

A single directory may or may not contain multiple


files. It can also have sub-directories inside the
main directory. Information about files is
maintained by Directories. In Windows OS, it is
called folders.

Following is the information which is maintained in a directory:


• Name The name which is displayed to the user.
• Type: Type of the directory.
• Position: Current next-read/write pointers.
• Location: Location on the device where the file header is stored.
• Size : Number of bytes, block, and words in the file.
• Protection: Access control on read/write/execute/delete.
• Usage: Time of creation, access, modification

By Pushpendra Singh Chundawat 1 17


Extensions

By Pushpendra Singh Chundawat 1 18


Summary
• 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 provides I/O support for a variety of storage device types.
• Files are stored on disk or other storage and do not disappear when a user logs off.
• A File Structure needs to be predefined format in such a way that an operating system
understands it.
• File type refers to the ability of the operating system to differentiate different types of files
like text files, binary, and source files.
• Create find space on disk and make an entry in the directory.
• Indexed Sequential Access method is based on simple sequential access
• In Sequential Access method records are accessed in a certain pre-defined sequence
• The random access method is also called direct random access
• Three types of space allocation methods are:
• Linked Allocation
• Indexed Allocation
• Contiguous Allocation
• Information about files is maintained by Directories
By Pushpendra Singh Chundawat 1 19
File Directory
Collection of files is a file directory. The directory contains information about the files,
including attributes, location and ownership. Much of this information, especially that is
concerned with storage, is managed by the operating system. The directory is itself a file,
accessible by various file management routines.

Information contained in a device directory are:


Name
Type
Address
Current length
Maximum length
Date last accessed
Date last updated
Owner id
Protection information

1 20
By Pushpendra Singh Chundawat
Cont..
Operation performed on directory are:
Search for a file
Create a file
Delete a file
List a directory
Rename a file
Traverse the file system

Advantages of maintaining directories are:

Efficiency: A file can be located more quickly.

Naming: It becomes convenient for users as two users can have same name for
different files or may have different name for same file.

Grouping: Logical grouping of files can be done by properties e.g. all java programs,
all games etc.
1 21
By Pushpendra Singh Chundawat
Structures of Directory in Operating System
A directory is a container that is used to contain folders and file. It organizes files and
folders into a hierarchical manner.

By Pushpendra Singh Chundawat 1 22


Cont..
SINGLE-LEVEL DIRECTORY
In this a single directory is maintained for all the users.

Naming problem: Users cannot have same name for two files.
Grouping problem: Users cannot group files according to their need.

1 23
By Pushpendra Singh Chundawat
Cont..
Single-level directory –
Single level directory is simplest directory structure.In it all files are contained in same
directory which make 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 the
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.

Disadvantages:
There may chance of name collision because two files can not have the same name.
Searching will become time taking if the directory is large.
In this can not group the same type of files together.
1 24
By Pushpendra Singh Chundawat
Cont..
TWO-LEVEL DIRECTORY
In this separate directories for each user is maintained.

Path name: Due to two levels there is a path name for every file to locate that file.
Now, we can have same file name for different user.
Searching is efficient in this method.

1 25
By Pushpendra Singh Chundawat
Cont..
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 there own user files directory
(UFD). The UFDs has similar structures, but each lists only the files of a single user.
system’s master file directory (MFD) is searches whenever a new user id=s logged in.
The MFD is indexed by username or account number, and each entry points to the UFD
for that user.

1 26
By Pushpendra Singh Chundawat
Cont..
Advantages:
We can give full path like /User-name/directory-name/.
Different users can have same directory as well as file name.
Searching of files become more easy due to path name and user-grouping.

Disadvantages:
A user is not allowed to share files with other users.
Still it not very scalable, two files of the same type cannot be grouped together in the
same user.

1 27
By Pushpendra Singh Chundawat
Cont..
TREE-STRUCTURED DIRECTORY :

Directory is maintained in the form of a tree.


Searching is efficient and also there is grouping capability.
We have absolute or relative path name for a file.

1 28
By Pushpendra Singh Chundawat
Cont..
TREE-STRUCTURED DIRECTORY :

Once we have seen a two-level directory as a tree of height 2, the natural generalization
is to extend the directory structure to a tree of arbitrary height.
This generalization allows the user to create there own subdirectories and to organize
on their files accordingly.

1 29
By Pushpendra Singh Chundawat
Cont..
TREE-STRUCTURED DIRECTORY :

A tree structure is the most common directory structure. The tree has a root directory,
and every file in the system have a unique path.
Advantages:
Very generalize, since full path name can be given.
Very scalable, the probability of name collision is less.
Searching becomes very easy, we can use both absolute path as well as relative.
Disadvantages:
Every file does not fit into the hierarchical model, files may be saved into multiple
directories.
We can not share files.
It is inefficient, because accessing a file may go under multiple directories.

1 30
By Pushpendra Singh Chundawat
Acyclic graph directory –
An acyclic graph is a graph with no cycle and allows to share
subdirectories and files. The same file or subdirectories may
be in two different directories. It is a natural generalization of
the tree-structured directory.It is used in the situation like
when two programmers are working on a joint project and
they need to access files.

The associated files are stored in a subdirectory, separating


them from other projects and files of other programmers,
since they are working on a joint project so they want the
subdirectories to be into their own directories. The common
subdirectories should be shared. So here we use Acyclic
directories.

It is the point to note that shared file is not the same as copy
file . If any programmer makes some changes in the
subdirectory it will reflect in both subdirectories.
1 31
By Pushpendra Singh Chundawat
Acyclic graph directory –
Advantages:
We can share files.
Searching is easy due to different-different paths.

Disadvantages:
We share the files via linking, in case of deleting it may
create the problem,
If the link is softlink then after deleting the file we left with a
dangling pointer.
In case of hardlink, to delete a file we have to delete all the
reference associated with it.

1 32
By Pushpendra Singh Chundawat
General graph directory structure –
In general graph directory structure, cycles
are allowed within a directory structure where
multiple directories can be derived from more
than one parent directory.

The main problem with this kind of directory


structure is to calculate total size or space
that has been taken by the files and
directories.

Advantages:
It allows cycles.
It is more flexible than other directories
structure.
Disadvantages:
It is more costly than others.
It needs garbage collection.
1 33
By Pushpendra Singh Chundawat
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.

All the three methods have their own advantages and disadvantages as discussed

1 34
By Pushpendra Singh Chundawat
FILE ALLOCATION METHODS

Continuous Allocation: A single continuous set


of blocks is allocated to a file at the time of file
creation. Thus, this is a pre-allocation strategy,
using variable size portions. The file allocation
table needs just a single entry for each file,
showing the starting block and the length of the
file.

This method is best from the point of view of the


individual sequential file. Multiple blocks can be
read in at a time to improve I/O performance for
sequential processing. It is also easy to retrieve a
single block. For example, if a file starts at block
b, and the ith block of the file is wanted, its
location on secondary storage is simply b+i-1.

1 35
By Pushpendra Singh Chundawat
Cont..
The directory entry for a file with contiguous allocation contains
Address of starting block
Length of the allocated portion.

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.

By Pushpendra Singh Chundawat 1 36


Cont..
Disadvantage

External fragmentation will occur, making it difficult to find contiguous blocks of space of
sufficient length.

Compaction algorithm will be necessary to free up additional space on disk.

Also, with pre-allocation, it is necessary to declare the size of the file at the time of
creation.

By Pushpendra Singh Chundawat 1 37


Linked Allocation(Non-contiguous allocation) :
Allocation is on an individual block basis. Each
block contains a pointer to the next block in the
chain. Again the file table needs just a single
entry for each file, showing the starting block
and the length of the file. Although pre-
allocation is possible, it is more common simply
to allocate blocks as needed. Any free block can
be added to the chain. The blocks need not be
continuous. Increase in file size is always
possible if free disk block is available. There is
no external fragmentation because only one
block at a time is needed but there can be
internal fragmentation but it exists only in the
last disk block of file.

By Pushpendra Singh Chundawat 1 38


Linked Allocation(Non-contiguous allocation) :
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.
Internal fragmentation exists in last disk block of file.
There is an overhead of maintaining the pointer in every disk block.
If the pointer of any disk block is lost, the file will be truncated.
It supports only the sequencial access of files.
By Pushpendra Singh Chundawat 1 39
Indexed Allocation
It addresses many of the problems of contiguous
and chained allocation. In this case, the file
allocation table contains a separate one-level
index for each file.

The index has one entry for each block allocated


to the file. Allocation may be on the basis of
fixed-size blocks or variable-sized blocks.

Allocation by blocks eliminates external


fragmentation, whereas allocation by variable-
size blocks improves locality. This allocation
technique supports both sequential and direct
access to the file and thus is the most popular
form of file allocation.

By Pushpendra Singh Chundawat 1 40


Indexed Allocation
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.

By Pushpendra Singh Chundawat 1 41


Cont..
For files that are very large, single index block may not be able to hold all the pointers.
Following mechanisms can be used to resolve this:

Linked scheme: This scheme links two or more index blocks together for holding the
pointers. Every index block would then contain a pointer or the address to the next index
block.

Multilevel index: In this policy, a first level index block is used to point to the second
level index blocks which inturn points to the disk blocks occupied by the file. This can be
extended to 3 or more levels depending on the maximum file size.

Combined Scheme: In this scheme, a special block called the Inode (information
Node) contains all the information about the file such as the name, size, authority, etc
and the remaining space of Inode is used to store the Disk Block addresses which
contain the actual file

By Pushpendra Singh Chundawat 1 42


Disk Free Space Management
Just as the space that is allocated to files must be managed ,so the space that is not
currently allocated to any file must be managed. To perform any of the file allocation
techniques,it is necessary to know what blocks on the disk are available. Thus we need a
disk allocation table in addition to a file allocation table.The following are the approaches
used for free space management.

Bit Tables : This method uses a vector containing one bit for each block on the disk. Each
entry for a 0 corresponds to a free block and each 1 corresponds to a block in use.
For example: 00011010111100110001In this vector every bit correspond to a particular
block and 0 implies that, that particular block is free and 1 implies that the block is already
occupied. A bit table has the advantage that it is relatively easy to find one or a contiguous
group of free blocks.
Advantages
a bit table works well with any of the file allocation methods.
Another advantage is that it is as small as possible.

By Pushpendra Singh Chundawat 1 43


Disk Free Space Management
Free Block List : In this method, each block is assigned a number sequentially and the list
of the numbers of all free blocks is maintained in a reserved block of the disk.

By Pushpendra Singh Chundawat 1 44


REFERENCES
Text/Reference Books:

1. A. Silberschatz and Peter B Galvin: Operating System Principals, Wiley India


Pvt. Ltd.

2. Achyut S Godbole: Operating Systems, Tata McGraw Hill

3. Tanenbaum: Modern Operating System, Prentice Hall.

4. DM Dhamdhere: Operating Systems – A Concepts Based Approach, Tata


McGraw Hill 5.

5. Charles Crowly: Operating System A Design – Oriented Approach, Tata


McGraw Hill.

By Pushpendra Singh Chundawat 1 45


By Pushpendra Singh Chundawat 46
B.Umamaheswari (Asst. Prof, CSE) , JECRC, JAIPUR

You might also like