0% found this document useful (0 votes)
24 views19 pages

OS-UNIT-5-NOTES-26-SEP-2024

Uploaded by

22eg112a15
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)
24 views19 pages

OS-UNIT-5-NOTES-26-SEP-2024

Uploaded by

22eg112a15
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/ 19

OPERATING SYSTEMS

UNIT-5
FILE SYSTEMS
1. A) File Concept :

The operating system abstracts from the physical properties of its


storage devices to define a logical storage unit, called ‘the file’.

There are three types of files :

a) Text File : is a sequence of characters organized into lines.

b) Source File : is a sequence of functions, each of which is further


organized as declarations followed by executable statements.

c) Executable File :is a series of code sections that the loader can bring
into memory and execute.
B) File attributes :
a) Name : The symbolic file name is the only information kept in human
readable form.

b) Identifier : This unique tag, usually a number, identifies the file within
the file system; it is the non-human-readable name for the file.

c) Type : This information is needed for systems that support different


types of files.

d) Location : This information is a pointer to a device and the location of


the file on that device.

e) Size : The current size of the file (in bytes) and possibly the maximum
allowed size are included in this attribute.

f) Protection : Access-control information determines who can do


reading, writing, executing and so on.

g) Time, date and user identification : this information may be kept for
creation, last modification, and last use.

1
C) File Operations :
The following is the set of file operations :
a) Creating a file : First, space in the file system must be found for the
file.

b) Writing a file : To write a file, we make a system call specifying


both the name of the file and information to be written to the file.

c) Reading a file : To read from a file, we use a system call that


specifies the name of the file and where the next block of the file
should be put.

d) Repositioning within a file : The directed is searched for the


appropriate entry, and the current-file-position pointer is
repositioned to a given value.

e) Deleting a file : To delete a file, we search the director for the


named file.

f) Truncating a file : The user may want to erase the contents of a file
but keep its attributes.
There are some other points associated with an open file.
a) File Pointer :The system must track the last read-write location as a
current-file-position pointer. This pointer is unique to each process
operating on the file.

b) File-Open Count : As files are closed, the operating system must


reuse its open-file table entries or it could run out of space in the
table.
c) Disk location of the file : Most file operations require the system to
modify data within the file. The information needed to locate the
file on disk is kept in memory so that the system does not to read it
from disk for each operation.

d) Access rights :Each process opens a file in an access mode. This


information is stored on the per-process table so the operating
system can allow or deny subsequent I/O request.

2
D) File Types :
The operating system should recognize and support file types.
If an operating system recognizes the types of a file, it can then
operate on the file in reasonable ways.
The following are some of the file types :

2. A) Access Methods :
a) Sequential Access :
The simplest access method is ‘sequential access’.
Information in the file is processed in order, one record after the other.

3
b) Direct Access :
This method is also called ‘Relative Access’.
Here a file is made up of fixed-length logical records that allow programs
to read and write records rapidly in no particular order.
The block number provided by the user to the operating system is
known as a ‘relative block number’.
The disk allows random access to any file block.
For direct access, the file is viewed as a numbered sequence of blocks or
records.
Thus we may read block 14, then read block 53 and then write block 7.
There are no restrictions on the order of reading or writing for a direct-
access file.
Let ‘cp’ defines the ‘current position’.
In the following figure, simulating a direct-access file on a sequential-
access file is shown :

 Simulation of Sequential Access on direct-access file 


For the direct-access method, the file operations must be modified to
include the block number as a parameter.
Thus, we have read(n), where n is the block number, and write(n).
The read_next(n) and write-next(n) are used with sequential access.
The another operation is ‘position_file(n)’.

4
c) Index and Relative Files :

Indexed Sequential Access Method (ISAM) uses a small master index


that points to disk blocks of a secondary index.

The secondary index blocks point to the actual file blocks.

The file is kept stored on a defined key.

To find a particular item, we first make a binary search of the master


index, which provides the block number of the secondary index.

This block is read in, and again a binary search is used to find the
block containing the desired record.

Finally this block is searched sequentially.

Example of Index and Relative File 

3. A) Directory and Disk Structure :


A storage device can be used in its entirety for a file system.
A disk can be partitioned in to quarters, and each quarter can hold a
separate file system.
The information about the files is kept in entries in a ‘device directory’
records information – such as name, location, size and type for all files
in that volume.
The following figure shows file system organization.

5
 A typical File System Organization 

B) Storage Structure :
Let us consider only general-purpose file systems.
A general-purpose file system has multiple storage devices and those
devices can be sliced up into volumes that hold file systems.
The types of file systems are given below.
tmpfs : a ‘temporary file system’ that is created in volatile main
memory and has its contents erased if the system reboots
or crashes.
objfs : a ‘virtual file system’ that gives debuggers access to kernel
symbols.
ctfs : a ‘virtual file system’ that maintains ‘contract information’ to
manage which processes start when the system boots and
must continue to run during operation.
lofs : a ‘loop back’ file system that allows one file system to be
accessed in place of another one.
procfs : a ‘virtual file system’ that presents information on all
Processes as a file system.
ufs, zfs : general-purpose file systems.

6
C) Directory Overview :
When considering a particular directory structure, one need to keep
in mind the operations that are to be performed on a directory.
a) Search for a file
b) Create a file
c) Delete a file
d) List a directory
e) Rename a file
f) Traverse the file system
D) Single Level Directory :
Here, all files are contained in the same directory, which is easy to
support and understand.
Since all files are in the same directory, they must have unique
names.

 Single Level Directory 


E) Two-Level Directory :
It is better to create a separate directory for each user.

In the two-level directory structure, each user has his own ‘user file
directory (UFD).

The UFDs have similar structures, but each lists only the files of a
single user.

When a user job starts or a user logs in, the system’s ‘master file
directory (MFD) is searched.

7
The MFD is indexed by user name or account number, and each
entry points to the UFD for that user.

When a user refers to a particular file, only his own UFD is


searched.

That is, different users may have files with the same name, as long
as all the file names within each UFD are unique.

To create a file for a user, the operating system searches only that
user’s UFD are unique.

To delete a file, the operating system confines its search to the


local UFD; thus, it cannot accidentally delete another user’s file
that has the same name.

F) Tree-Structured Directories :
It is better to create a separate directory for each user.

The conversion of a directory structure to a tree of arbitrary height


allows users to create their own sub directories and to organize their
files accordingly.

A tree is the most common directory structure.

The tree has a root directory, and every file in the system has a
unique path name.

8
A directory contains a set of files or subdirectories.

A directory is simply another file.

All directories have the same internal format.

One bit in each directory defines the entry as a file (0) or as a sub
directory (1).

 Tree Structured- Directory Structure 

G) Acyclic Graph Directories :


A tree structure prohibits the sharing of files or directories.

An ‘acyclic graph’ is a graph with no cycles – allows directories to


share subdirectories and files.

The same file or subdirectory may be in two different directories.


IT is important to note that a shared file (or directory) is not the same
as two copies of the file.
With a shared file, only one actual file exists, so any changes made by
one person are immediately visible to the other.

9
 Acyclic Graph Directory Structure 
H) General Graph Directory :
A serious problem with using an acyclic graph structure is ensuring
that there are no cycles.

If we start with a two-level directory and allow users to create sub-


directories, a tree-structured directory results.

However, when we add links, the tree structure is destroyed,


resulting in a simple graph structure as follows :

 General Graph Directory 

10
4. File System Mounting :
A file must be opened before it is used.
A file system should be mounted before it can be available to processes
on the system.
More specifically, the directory structure may be built out of multiple
volumes, which must be mounted to make them available with in the
file-system name space.
Mount procedure : The operating system is given the name of the device
and the mount point – the location within the file structure where the
file system is to be attached.
The operating system verifies that the device contains a valid file system.
It does so by asking the device driver to read the device directory and
verifying that the directory has the expected format.
Finally, the operating system notes in its directory structure that a file
system is mounted at the specified mount point.
Consider the file system depicted here :

File System : (a) Existing (b) Unmounted Volume

11
Here, the triangles represent subtrees of directories that are of interest.
At this point, only the files on the existing file system can be accessed.
The following diagram shows the effects of mounting the volume
residing on /device/dsiover/users.
If the volume is unmounted, the file system is restored to the situation
depicted in the above figure.

 Mount Point 

A system may disallow a mount over a directory that contains files.


Or it may take the mounted file system available at that directory and
obscure the directory’s existing files until the file system is unmounted,
terminating the use of the file system and allowing access to the original
files in that directory.
Also a system may allow the same file system to be mounted repeatedly,
at different mount points; or it may only allow one mount per the file
system.

12
5. System Protection :
The process in an operating system must be protected from one
another’s activities.
Protection refers to a mechanism for controlling the access of programs,
processes or users to the resources defined by a computer system.
Modern protection concepts have evolved to increase the reliability of
any complex system that makes use of shared resources.
The role of protection in a computer system is to provide a mechanism
for the enforcement of the policies governing resource use.
Mechanisms determine ‘how’ something will be done; policies decided
‘what’ will be done.
Principles of Protection :
A key, time-tested guiding principle for protection is the ‘principle of
least privilege’.
It dictates that programs, users and even systems be given just enough
privileges to perform their tasks.
An operating system following the ‘principle of lest privilege’
implements its features, programs, system calls, and data structures so
that failure or compromise of a component does the minimum damage
and allows the minimum damage to be done.
Domain of Protection :
A computer system is a collection of processes and objects.
By objects, we mean both hardware objects (CPU, memory, disks) and
software objects (files, programs and semaphores).
Each object has a unique name that differentiates it from all other
objects in the system, and each can be accessed only through well-
defined and meaningful operations.
The operations that are possible may depend on the objects.
A process should be allowed to access only those resources for which it
has authorization.

13
Domain Structure :
A process operates within a ‘protection domain’, which specifies the
resources that the process may access.
Each domain defines a set of objects and the types of operations that
may be invoked on each object.
The ability to execute an operation on an object is an ‘access right’.
A domain is a collection of access rights, each of which is an ordered pair
<object-name, rights-set>.
For example, if domain D has the access right <file F, {read, write}>, then
a process executing in domain D can both read and write the file F.
It can not perform any other operation on that object.
The association between a process and a domain may be either ‘static’,
if the set of resources available to the process is fixed throughout the
process’s life time, or ‘dynamic’.
If the association between processes and domains is fixed, and we want
to adhere to the need-to-know principle, then a mechanism must be
available to change the content of a domain.
If the association is dynamic, a mechanism is available to allow ‘domain
switching’, enabling the process to switch from one domain to another.

System with three protection domains 

14
6. Access Matrix :
The general method of protection can be viewed abstractly as a matrix,
called ‘Access Matrix’.
The rows of the access matrix represent ‘domains’, and the columns
represent ‘objects’.
Each entry in the matrix consists of a set of access rights.
The entry access(i,j) defines the set of operations that a process
executing in domain Di can invoke on object Oj.
Consider the access matrix given below :

 Access Matrix 
Here, there are three files F1, F2 and F3 and One laser Printer.
A process executing in Domain D1 can read files F1 and F3.
A process executing in domain D4 has the same privileges as one
executing in domain D1, it can also write onto files F1 and F3.
The laser printer can be accessed only by a process executing in domain
D2.
The process executing in domain D3 can perform ‘read’ operation on F2
and can perform ‘execute’ operation on F3.

15
Processes should be able to switch from one domain to another.
Switching from domain Di to domain Dj is allowed if and only if the
access right ‘switch’  access(i,j).
Thus, in the following figure, a process executing in domain D2 can
switch to domain D3 or to domain D4 can switch to D1 and one in
domain D1 can switch to D2.

Access Matrix with domains as objects  2


Allowing controlled change in the contents of the access-matrix entries
requires three additional operations
copy owner control
The ability to copy an access right from one domain (row) of the access
matrix to another is denoted by an asterisk (*) appended to the access
right.
The copy right allows the access right to be copies only within the
column for which the right is defined.
For example, in the following figure-(a), a process executing in domain
D2 can copy the read operation into any entry associated with file F2.
Hence the access matrix of figure-(a) can be modified to the access
matrix shown in figure-(b).

16
 Access Matrix with ‘copy’ rights 
It is also required a mechanism to allow addition of new rights and
removal of some rights.
The ‘owner’ right controls these operations.
If access(i,j) includes the ‘owner’ right, then a process executing in
domain Di can add and remove any right in any entry in column j.
For example, in the following figure-(a), domain D1 is the owner of F1
and thus can add and delete any valid right in column F1.
Similarly, domain D2 is the owner of F2 and F3 and thus can add and
remove any valid right within these two columns.
Thus, the access matrix of figure-(a) can be modified to the access matrix
shown in figure-(b).
The ‘copy’ and ‘owner’ rights allow a process to change the entries in a
column.

17
 Access Matrix with ‘owner’ rights 
A mechanism is also needed to change the entries in a ‘row’.
The ‘control’ right is applicable only to domain objects.
If access(i,j) includes the ‘control’ right, then a process executing in
domain Di can remove any access right from row j.
For example, suppose that in the following figure, one can include the
‘control’ right in access(D2, D4).
Then, a process executing in domain D2 could modify domain D4, as
shown in the following figure.
The ‘copy’ and ‘owner rights provide us with a mechanism to limit the
propagation of access rights.
The problem of guaranteeing that no information initially held in an
object can migrate outside of its execution environment is called the
‘confinement problem’.

18
 Modified Access Matrix 

* * * * *

19

You might also like