Unit 4
Unit 4
of Technology, Gorakhpur
Content
Information Management: File concept, file support, directory
structures, symbolic file directory, basic file directory, logical file
system, physical file system, access methods, file protection, file
allocation strategies. Protection: Goals, policies and mechanisms,
domain of protection, access matrix and its implementation, access
lists, capability lists, Lock/Key mechanisms, passwords, dynamic
protection scheme, security concepts and public and private keys, RSA
encryption and decryption algorithms.
A case study: A UNIX OS file system, shell, filters, shell
programming, programming with the standard I/O, UNIX system calls.
21-05-2023 Side 2
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Information Management
21-05-2023 Side 3
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
File Concept
A file is a named collection of related information that is recorded on secondary
storage such as magnetic disks, magnetic tapes and optical disks. In general, a file is a
sequence of bits, bytes, lines or records whose meaning is defined by the files creator
and user.
File Structure
A File Structure should be according to a required format that the operating system can
understand.
A file has a certain defined structure according to its type.
A text file is a sequence of characters organized into lines.
A source file is a sequence of procedures and functions.
An object file is a sequence of bytes organized into blocks that are understandable by
the machine.
When operating system defines different file structures, it also contains the code to
support these file structure. Unix, MS-DOS support minimum number of file
21-05-2023
structure. Side 4
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
File Support
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 support of a file system. Here, are some important File support 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
21-05-2023
monitoring Side 5
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Directory Structures
A Directory is the collection of the correlated files on the disk. In simple
words, a directory is like a container which contains file and folder. In a
directory, we can store the complete file attributes or some attributes of the
file. A directory can be comprised of various files. With the help of the
directory, we can maintain the information related to the files.
21-05-2023 Side 6
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 8
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Two-Level Directory
Two-Level Directory is another type of directory structure. In this, it is possible to
create an individual directory for each of the users. There is one master node in the
two-level directory that include an individual directory for every user. At the
second level of the directory, there is a different directory present for each of the
users. Without permission, no user can enter into the other user’s directory.
21-05-2023 Side 9
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Tree-Structured Directory
In a tree-structured directory, there is an own directory of each user, and any user
is not allowed to enter into the directory of another user. Although the user can
read the data of root, the user cannot modify or write it. The system administrator
only has full access to the root directory. In this, searching is quite effective and
we use the current working concept. We can access the file by using two kinds of
paths, either absolute or relative.
21-05-2023 Side 10
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Acyclic-Graph Directory
In the tree-structure directory, the same files cannot exist in the multiple
directories, so sharing the files is the main problem in the tree-structure directory.
With the help of the acyclic-graph directory, we can provide the sharing of files.
In the acyclic-graph directory, more than one directory can point to a similar file
or subdirectory. We can share those files among the two directory entries.
With the help of aliases, and links, we can create this type of directory graph. We
may also have a different path for the same file. Links may be of two kinds, which
are hard link (physical) and symbolic (logical).
If we delete the files in acyclic graph structures, then
1. In the hard link (physical) case, we can remove the actual files only if all the
references to the file are deleted.
2. In the symbolic link (logical) case, we just delete the file, and there is only a
dangling point that is left.
21-05-2023 Side 11
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
General-Graph Directory
The General-Graph directory is another vital type of directory structure. In this
type of directory, within a directory we can create cycle of the directory where we
can derive the various directory with the help of more than one parent directory.
The main issue in the general-graph directory is to calculate the total space or size,
taken by the directories and the files.
21-05-2023 Side 12
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 13
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 14
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
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.
21-05-2023 Side 15
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Logical files do not contain data. They contain a description of records that are
found in one or more physical files. A logical file is a view or representation of
one or more physical files. Logical files that contain more than one format are
referred to as multi-format logical files.
If your program processes a logical file which contains more than one record
format, you can use the _Rformat() function to set the format you wish to use.
Some operations cannot be performed on logical files. If you open a logical file
for stream file processing with open modes W, W+, WB or WB+, the file is
opened but not cleared. If you open a logical file for record file processing with
open modes WR or WR+, the file is opened but not cleared. Records in i Series
database files can be described using either a field level description or record
level description.
21-05-2023 Side 16
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 17
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Access Methods
The file contains the information but when it required to used this information
can be access by the access methods and reads into the computer memory.
Some system provides only one access method and some provide more than on
access method to access the file.
Sequential Access Method
A sequential access is that in which the records are accessed in some sequence,
i.e., the information in the file is processed in order, one record after the other.
This access method is the most primitive one.
The idea of sequential access is based on the tape model which is a sequential
access device. We consider sequential access method is best because most of
the records in a file are to be processed. For example, transaction files.
21-05-2023 Side 18
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 19
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 20
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
File Protection
In computer systems, alot of user’s information is stored, the objective of the
operating system is to keep safe the data of the user from the improper access to
the system. Protection can be provided in number of ways.
Types of Access :
The files which have direct access of the any user have the need of protection.
The files which are not accessible to other users doesn’t require any kind of
protection. The mechanism of the protection provide the facility of the
controlled access by just limiting the types of access to the file. Access can be
given or not given to any user depends on several factors, one of which is the
type of access required. Several different types of operations can be controlled:
21-05-2023 Side 21
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 22
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
File Allocation Strategies
The allocation methods define how the files are stored in the disk blocks. There are
three main disk space or file allocation methods:
1) Contiguous Allocation
2) Linked Allocation
3) Indexed Allocation
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.
21-05-2023 Side 23
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
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.
21-05-2023 Side 24
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Advantages:
Both the Sequential and Direct Accesses are supported by this.
This is extremely fast because of contiguous allocation of file blocks.
Disadvantages:
This method suffers from both internal and external fragmentation.
Increasing file size is difficult because it depends on the availability of
contiguous memory at a particular instance.
21-05-2023 Side 25
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 26
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Advantages:
This is very flexible in terms of file size. File size can be increased easily .
This method does not suffer from external fragmentation. This makes it relatively
better in terms of memory utilization.
Disadvantages:
It does not support random or direct access. We can not directly access the blocks
of a file.
21-05-2023 Side 27
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
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:
21-05-2023 Side 28
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
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.
21-05-2023 Side 29
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Protection
21-05-2023 Side 30
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Role of Protection:
The role of protection is to provide a mechanism that implement policies which
defines the uses of resources in the computer system. Some policies are defined
at the time of design of the system, some are designed by management of the
system and some are defined by the users of the system to protect their own
files and programs.
Every application has different policies for use of the resources and they may
change over time so protection of the system is not only concern of the designer
of the operating system. Application programmer should also design the
protection mechanism to protect their system against misuse.
Policy is different from mechanism. Mechanisms determine how something will
be done and policies determine what will be done. Policies are changed over
time and place to place.
21-05-2023 Side 31
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Goals
The role of protection in a computer system is to provide a mechanism
for the enforcement of the policies governing resource use. These
policies can be established in a variety of ways. Some are fixed in the
design of the system, while others are formulated by the management
of a system. Still others are defined by the individual users to protect
their own files and programs. A protection system must have the
flexibility to enforce a variety of policies.
21-05-2023 Side 32
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 33
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Protection Mechanisms
Protection plays a very crucial role in a multiuser environment, where several
users will be making concurrent use of the computer resources such as CPU,
memory etc. It is the duty of the operating system to provide a mechanism that
protects each process from others.
All the items that require protection in a multiuser environment are down as
objects and those that want to access these objects are known as subjects. The
operating system grants different 'access rights' to different subjects.
These rights may include read, write, execute, append, delete etc.
21-05-2023 Side 34
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Domain
A domain is a combination of different objects and a set of different 'access rights'
that can be granted to different subjects to operate on each of these objects. An
operating system maintains several such domains with different combinations of
access rights. The user processes can execute in one of those domains and can
access the objects in that domain according to the access rights given to those
objects.
Encryption
It is one of the most powerful and important tools of protection. The process of
encryption involves two steps: encryption of the original data into some other form
about which nothing is known to the third person and decryption of the data into the
original form the encrypted form.
The most commonly used methods to achieve encryption are: transposition ciphers
and substitution ciphers.
In transposition ciphers, the letters in the original message are not changed; only the
order in which they are contained in the original message gets changed.
The set of characters in the encrypted form will be different from the original ones
if we use substitution ciphers every letter may be replaced by its previous alphabet,
for instance.
The key idea behind the encryption schemes is that the encryption process must be
restorable. Means, once we encrypt the original message to a different form, there
should be a way to restore it to the original form.
21-05-2023 Side 37
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 38
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Domain of Protection
A computer system is a collection of processes and objects. By objects,
we mean both hardware objects (such as the CPU, printer) and software
objects(such as files, programs).
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.
A process should be allowed to access only those resources for which it
has authorization Furthermore, at any time, a process should be able to
access only those resources that it currently requires to complete its task.
21-05-2023 Side 39
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Access Matrix and Its Implementation
Access Matrix is a security model of protection state in computer system. It is represented
as a matrix. Access matrix is used to define the rights of each process executing in the
domain with respect to each object. The rows of matrix represent domains and columns
represent objects. Each cell of matrix represents set of access rights which are given to the
processes of domain means each entry(i , j) defines the set of operations that a process
executing in domain Di can invoke on object Oj.
21-05-2023 Side 40
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
According to the above matrix: there are four domains and four objects- three
files(F1, F2, F3) and one printer. A process executing in D1 can read files F1
and F3. A process executing in domain D4 has same rights as D1 but it can also
write on files. Printer can be accessed by only one process executing in domain
D2. The mechanism of access matrix consists of many policies and semantic
properties. Specifically, We must ensure that a process executing in domain Di
can access only those objects that are specified in row i.
Policies of access matrix concerning protection involve which rights should be
included in the (i, j) th entry. We must also decide the domain in which each
process executes. This policy is usually decided by the operating system. The
Users decide the contents of the access-matrix entries.
21-05-2023 Side 41
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Association between the domain and processes can be either static or dynamic. Access
matrix provides an mechanism for defining the control for this association between domain
and processes. When we switch a process from one domain to another, we execute a switch
operation on an object(the domain). We can control domain switching by including
domains among the objects of the access matrix. Processes should be able to switch from
one domain (Di) to another domain (Dj) if and only is a switch right is given to access(i , j).
21-05-2023 Side 42
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 43
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Access lists
21-05-2023 Side 44
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Types of ACL –
There are two main different types of Access-list namely:
Standard Access-list – These are the Access-list which are made using the
source IP address only. These ACLs permit or deny the entire protocol suite.
They don’t distinguish between the IP traffic such as TCP, UDP, Https etc. By
using numbers 1-99 or 1300-1999, router will understand it as a standard ACL
and the specified address as source IP address.
Extended Access-list – These are the ACL which uses both source and
destination IP address. In these type of ACL, we can also mention which IP
traffic should be allowed or denied. These use range 100-199 and 2000-2699.
21-05-2023 Side 45
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Capability lists
A capability is a token, ticket, or key that gives the possessor permission to
access an entity or object in a computer system.
A capability can be thought of as a pair (x, r) where x is the name of an
object and r is a set of privileges or rights. With each subject we can store
that subject's capabilities.
Capability is completely transferable; it doesn't matter who presents the
capability.
21-05-2023 Side 46
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Lock/Key Mechanisms
The Lock variable mechanism is a synchronization mechanism that is
implemented in a user mode. It is a software procedure.
In the lock variable mechanism, we use a lock variable, i.e., Lock. There are
two values of Lock variable, which are 1 and 0. If the value of Lock is 1, then
it means the critical section is occupied, but if the value of lock is 0, then it
means the critical section is empty.
If a process wants to enter into the critical section, then first the process checks
the value of Lock variable, and if the value of lock is 0, then we set the value
of lock as 1, and after setting the value, the process enters into the critical
section. Otherwise, the process waits for its turn.
21-05-2023 Side 47
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
The Pseudo code of the lock variable mechanism is:
In the following Pseudo code, we have three sections, i.e., Entry section,
Critical section, and the exit section.
Initially, the value of the lock variable was 0. When any process wishes to
enter into the critical section, it checks the condition of the while loop. It
continuously waits until the value of the lock variable is 1. Because to enter,
the value of lock variable should be 1. So, it is clear that initially, the critical
section is empty, and thus the process enters into the critical section, and the
value of the lock variable sets to1. This means another process will wait until
the value becomes 0. In the exit section, we will reset the value of lock variable
as 0 when the process will exit from the critical section.
21-05-2023 Side 48
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Passwords
21-05-2023 Side 49
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
In Private key, the same key (secret key) is used for encryption and
decryption. In this key the only one key is copy or share by another party
to decrypt the cipher text. It is faster than the public key cryptography.
In Public key, two keys are used for encryption and another key is used
for decryption. One key (public key) is used for encrypt the plain text to
convert it into cipher text and another key (private key) is used by
receiver to decrypt the cipher text to read the message.
21-05-2023 Side 50
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Now, we see the difference between them:
S.NO Private Key Public Key
1. Private key is faster than public key. It is slower than private key.
In this, the same key (secret key) and In public key cryptography, two keys are
2. algorithm is used to encrypt and decrypt used, one key is used for encryption and
the message. while the other is used for decryption.
In private key cryptography, the key is In public key cryptography, one of the two
3.
kept as a secret. keys is kept as a secret.
Private key is Symmetrical because Public key is Asymmetrical because there
4. there is only one key that is called secret are two types of key: private and public
key. key.
In this cryptography, sender and In this cryptography, sender and receiver
5.
receiver need to share the same key. does not need to share the same key.
21-05-2023 Side 52
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 53
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 54
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Directories or Files and their Description –
/ : The slash / character alone denotes the root of the file system tree.
/bin : Stands for “binaries” and contains certain fundamental utilities which are
generally needed by all users.
/boot : Contains all the files that are required for successful booting process.
/dev : Stands for “devices”. Contains file representations of peripheral devices
and pseudo-devices.
/etc : Contains system-wide configuration files and system databases.
/home : Contains the home directories for the users.
/lib : Contains system libraries, and some critical files such as kernel modules
or device drivers.
21-05-2023 Side 55
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
/media : Default mount point for removable devices, such as USB sticks,
media players, etc.
/mnt : Stands for “mount”. Contains file system mount points.
/proc : procfs virtual file system showing information about processes as
files.
/root : The home directory for the super user “root” – that is, the system
administrator.
/tmp : A place for temporary files.
/usr : Originally the directory holding user home directories, its use has
changed.
/usr/bin : This directory stores all binary programs distributed with the
operating system.
21-05-2023 Side 56
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 57
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Shell
A Shell provides an interface to the Unix system. It gathers input from user and
executes programs based on that input. When a program finishes executing, it
displays that program's output.
Shell is an environment in which we can run our commands, programs, and shell
scripts. There are different flavors of a shell, just as there are different flavors of
operating systems. Each flavor of shell has its own set of recognized commands
and functions.
The shell is the outermost layer of the operating system. Shells incorporate a
programming language to control processes and files, as well as to start and control
other programs.
Shell Types : In Unix, there are two major types of shells −
Bourne shell − If you are using a Bourne-type shell, the $ character is the default
prompt.
C shell − If you are using a C-type shell, the % character is the default prompt.
21-05-2023 Side 58
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Filters
Filters are programs that take plain text as standard input, transforms it into a
meaningful format, and then returns it as standard output. Linux has a number of
filters. Some of the most commonly used filters are explained below:
cat : Displays the text of the file line by line.
Syntax: cat [path]
head : Displays the first n lines of the specified text files.
Syntax: head [-number_of_lines_to_print] [path]
tail : It works the same way as head, just in reverse order. The only difference in
returns the lines from bottom to up.
Syntax: tail [-number_of_lines_to_print] [path]
sort : Sorts the lines alphabetically.
Syntax: sort [-options] [path]
21-05-2023 Side 59
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 60
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Shell Programming
A shell is special user program which provide an interface to user to use
operating system services. Shell accept human readable commands from user
and convert them into something which kernel can understand. It is a command
language interpreter that execute commands read from input devices such as
keyboards or from files. The shell gets started when the user logs in or start the
terminal.
21-05-2023 Side 61
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 62
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 63
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
System calls in Unix are used for file system control, process control,
interprocess communication etc. Access to the Unix kernel is only
available through these system calls. Generally, system calls are similar to
function calls, the only difference is that they remove the control from the
user process.
There are around 80 system calls in the Unix interface currently. Details
about some of the important ones are given as follows -
21-05-2023 Side 64
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
System Call Description
access() This checks if a calling process has access to the required file
chdir() The chdir command changes the current directory of the system
chmod() The mode of a file can be changed using this command
chown() This changes the ownership of a particular file
kill() This system call sends kill signal to one or more processes
link() A new file name is linked to an existing file using link system call.
open() This opens a file for the reading or writing process
pause() The pause call suspends a file until a particular signal occurs.
stime() This system call sets the correct time.
times() Gets the parent and child process times
alarm() The alarm system call sets the alarm clock of a process
fork() A new process is created using this command
chroot() This changes the root directory of a file.
21-05-2023 exit() The exit system call is used to exit a process. Side 65
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
THE END
21-05-2023 Side 66