Os Notes (Unit-Iv)
Os Notes (Unit-Iv)
UNIT-IV
UNIT:4 (11
Hours)
File System Interface - The Concept of a File, Access
methods, Directory Structure, File System Mounting, File
Sharing, Protection, File System Implementation - File System
Structure, File System Implementation, Allocation methods,
Free-space Management, Directory Implementation,
Efficiency and Performance. Mass Storage Structure -
Overview of Mass Storage Structure, Disk Structure, Disk
Attachment, Disk Scheduling, Disk Management, Swap space
Management.
Protection - System Protection, Goals of Protection, Principles
of Protection, Domain of Protection, Access Matrix,
Implementation of Access Matrix, Access Control, Revocation
of Access Rights, Capability-Based Systems, Language-
Based Protection.
File
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.
File Type
File type refers to the ability of the operating system to distinguish different types of file such
as text files source files and binary files etc. Many operating systems support many types of
files. Operating system like MS-DOS and UNIX have the following types of files −
Ordinary files
Directory files
These files contain list of file names and other information related to these files.
Special files
Sequential access
Direct/Random access
Indexed sequential access
Sequential access
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. Example: Compilers usually access files in this fashion.
Direct/Random access
Space Allocation
Files are allocated disk spaces by operating system. Operating systems deploy following
three main ways to allocate disk space to files.
Contiguous Allocation
Linked Allocation
Indexed Allocation
Contiguous Allocation
Indexed Allocation
Word Processor wp, tex, rrf, doc Various word processor formats
Archive arc, zip, tar Related files grouped into one compressed file
FILE DIRECTORIES:
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.
Name
Type
Address
Current length
Maximum length
Date last accessed
Date last updated
Owner id
Protection information
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.
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.
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.
FILE ALLOCATION METHODS
1. 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.
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.
3. 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.
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.
2. 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.
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.
Fixed Blocking
----------------------------
• Fixed-length records are used, and an integral number of records are stored in a
block.
• Unused space at the end of a block is internal fragmentation Fixed Blocking
Variable Length Spanned Blocking
-------------------------------------------------
• Variable-length records are used and are packed into blocks with no unused space.
• Some records may span multiple blocks – Continuation is indicated by a pointer to
the successor block.
FCFS
Illustration shows total head movement of 640
cylinders
SSTF
Selects the request with the minimum seek time from the
current head position SSTF scheduling may cause starvation
of some requests Illustration shows total head movement of
236 cylinders
SCAN
The disk arm starts at one end of the disk, and moves
toward the other end, servicing requests until it gets to the
other end of the disk, where the head movement is reversed
and servicing continues. SCAN algorithm sometimes called
the elevator algorithm. Illustration shows total head
movement of 208 cylinders
C-SCAN
Provides a more uniform wait time than SCAN
The head moves from one end of the disk to the other,
servicing requests as it goes
When it reaches the other end, however, it immediately
returns to the beginning of the disk,
without servicing any requests on the return trip.
C-LOOK
Version of C-SCAN
Arm only goes as far as the last request in each direction,
then reverses direction immediately, without first going all
the way to the end of the disk.
Selecting a Disk-Scheduling Algorithm
Network-Attached Storage
Network-attached storage (NAS) is storage made available over
a network
rather than over a local connection (such as a bus)
Implemented via remote procedure calls (RPCs) between host
and storage
Stable-Storage Implementation
Removable Disks
WORM Disks
The data on read-write disks can be modified over and over
WORM (“Write Once, Read Many Times”) disks can be
written only once
Thin aluminum film sandwiched between two glass or plastic
platters
To write a bit, the drive uses a laser light to burn a small hole
through the aluminum;
information can be destroyed by not altered
Very durable and reliable
Read-only disks, such as CD-ROM and DVD, come from the
factory with the data pre-recorded
Magnetic tape
Speed
Access time for a disk – move the arm to the selected cylinder and
wait for the rotational latency; < 35 milliseconds
Access on tape requires winding the tape reels until the selected block
reaches the tape head;
Cost
Protection
14.1 Goals of Protection
Obviously to prevent malicious misuse of the system by users or programs. See chapter 15
for a more thorough coverage of this goal.
To ensure that each shared resource is used only in accordance with system policies, which
may be set either by system designers or by system administrators.
To ensure that errant programs cause the minimal amount of damage possible.
Note that protection systems only provide the mechanisms for enforcing policies and
ensuring reliable systems. It is up to administrators and users to implement those
mechanisms effectively.
The principle of least privilege dictates that programs, users, and systems be given just
enough privileges to perform their tasks.
This ensures that failures do the least amount of harm and allow the least of harm to be
done.
For example, if a program needs special privileges to perform a task, it is better to make it a
SGID program with group ownership of "network" or "backup" or some other pseudo group,
rather than SUID with root ownership. This limits the amount of damage that can occur if
something goes wrong.
Typically each user is given their own account, and has only enough privilege to modify their
own files.
The root account should not be used for normal day to day activities - The System
Administrator should also have an ordinary account, and reserve use of the root account for
only those tasks which need the root privileges
14.3 Domain of Protection
The MULTICS system uses a complex system of rings, each corresponding to a different
protection domain, as shown below:
Rings are numbered from 0 to 7, with outer rings having a subset of the privileges of the
inner rings.
Each file is a memory segment, and each segment description includes an entry that
indicates the ring number associated with that segment, as well as read, write, and execute
privileges.
Each process runs in a ring, according to the current-ring-number, a counter associated with
each process.
A process operating in one ring can only access segments associated with higher ( farther
out ) rings, and then only according to the access bits. Processes cannot access segments
associated with lower rings.
Domain switching is achieved by a process in one ring calling upon a process operating in a
lower ring, which is controlled by several factors stored with each segment descriptor:
o An access bracket, defined by integers b1 <= b2.
o A limit b3 > b2
o A list of gates, identifying the entry points at which the segments may be called.
If a process operating in ring i calls a segment whose bracket is such that b1 <= i <= b2, then
the call succeeds and the process remains in ring i.
Otherwise a trap to the OS occurs, and is handled as follows:
o If i < b1, then the call is allowed, because we are transferring to a procedure with
fewer privileges. However if any of the parameters being passed are of segments
below b1, then they must be copied to an area accessible by the called procedure.
o If i > b2, then the call is allowed only if i <= b3 and the call is directed to one of the
entries on the list of gates.
Overall this approach is more complex and less efficient than other protection schemes.
The model of protection that we have been discussing can be viewed as an access matrix, in
which columns represent different system resources and rows represent different protection
domains. Entries within the matrix indicate what access that domain has to that resource.
Domain switching can be easily supported under this model, simply by providing "switch"
access to other domains:
The ability to copy rights is denoted by an asterisk, indicating that processes in that domain
have the right to copy that access within the same column, i.e. for the same object. There
are two important variations:
o If the asterisk is removed from the original access right, then the right is transferred,
rather than being copied. This may be termed a transfer right as opposed to a copy
right.
o If only the right and not the asterisk is copied, then the access right is added to the
new domain, but it may not be propagated further. That is the new domain does not
also receive the right to copy the access. This may be termed a limited copy right, as
shown in Figure 14.5 below:
The owner right adds the privilege of adding new rights or removing existing ones:
Figure 14.6 - Access matrix with owner rights.
Copy and owner rights only allow the modification of rights within a column. The addition of
control rights, which only apply to domain objects, allow a process operating in one domain
to affect the rights available in other domains. For example in the table below, a process
operating in domain D2 has the right to control any of the rights in domain D4.
The simplest approach is one big global table with < domain, object, rights > entries.
Unfortunately this table is very large ( even if sparse ) and so cannot be kept in memory
( without invoking virtual memory techniques. )
There is also no good way to specify groupings - If everyone has access to some resource,
then it still needs a separate entry for every domain.
Each column of the table can be kept as a list of the access rights for that particular object,
discarding blank entries.
For efficiency a separate list of default access rights can also be kept, and checked first.
In a similar fashion, each row of the table can be kept as a list of the capabilities of that
domain.
Capability lists are associated with each domain, but not directly accessible by the domain or
any user process.
Capability lists are themselves protected resources, distinguished from other data in one of
two ways:
o A tag, possibly hardware implemented, distinguishing this special type of data.
( other types may be floats, pointers, booleans, etc. )
o The address space for a program may be split into multiple segments, at least one of
which is inaccessible by the program itself, and used by the operating system for
maintaining the process's access right capability list.
14.5.5 Comparison
Each of the methods here has certain advantages or disadvantages, depending on the
particular situation and task at hand.
Many systems employ some combination of the listed methods.
Hydra is a capability-based system that includes both system-defined rights and user-
defined rights. The interpretation of user-defined rights is up to the specific user programs,
but the OS provides support for protecting access to those rights, whatever they may be
Operations on objects are defined procedurally, and those procedures are themselves
protected objects, accessed indirectly through capabilities.
The names of user-defined procedures must be identified to the protection system if it is to
deal with user-defined rights.
When an object is created, the names of operations defined on that object become auxiliary
rights, described in a capability for an instance of the type. For a process to act on an object,
the capabilities it holds for that object must contain the name of the operation being
invoked. This allows access to be controlled on an instance-by-instance and process-by-
process basis.
Hydra also allows rights amplification, in which a process is deemed to be trustworthy, and
thereby allowed to act on any object corresponding to its parameters.
Programmers can make direct use of the Hydra protection system, using suitable libraries
which are documented in appropriate reference manuals.
o As systems have developed, protection systems have become more powerful, and
also more specific and specialized.
o To refine protection even further requires putting protection capabilities into the
hands of individual programmers, so that protection policies can be implemented on
the application level, i.e. to protect resources in ways that are known to the specific
applications but not to the more general operating system.
14.9.1 Compiler-Based Enforcement
In a compiler-based approach to protection enforcement, programmers directly specify the
protection needed for different resources at the time the resources are declared.
This approach has several advantages:
1. Protection needs are simply declared, as opposed to a complex series of procedure
calls.
2. Protection requirements can be stated independently of the support provided by a
particular OS.
3. The means of enforcement need not be provided directly by the developer.
4. Declarative notation is natural, because access privileges are closely related to the
concept of data types.
Regardless of the means of implementation, compiler-based protection relies upon the
underlying protection mechanisms provided by the underlying OS, such as the Cambridge
CAP or Hydra systems.
Even if the underlying OS does not provide advanced protection mechanisms, the compiler
can still offer some protection, such as treating memory accesses differently in code versus
data segments. ( E.g. code segments cant be modified, data segments can't be executed. )
There are several areas in which compiler-based protection can be compared to kernel-
enforced protection:
o Security. Security provided by the kernel offers better protection than that provided
by a compiler. The security of the compiler-based enforcement is dependent upon
the integrity of the compiler itself, as well as requiring that files not be modified
after they are compiled. The kernel is in a better position to protect itself from
modification, as well as protecting access to specific files. Where hardware support
of individual memory accesses is available, the protection is stronger still.
o Flexibility. A kernel-based protection system is not as flexible to provide the specific
protection needed by an individual programmer, though it may provide support
which the programmer may make use of. Compilers are more easily changed and
updated when necessary to change the protection services offered or their
implementation.
o Efficiency. The most efficient protection mechanism is one supported by hardware
and microcode. Insofar as software based protection is concerned, compiler-based
systems have the advantage that many checks can be made off-line, at compile time,
rather that during execution.
The concept of incorporating protection mechanisms into programming languages is in its
infancy, and still remains to be fully developed. However the general goal is to provide
mechanisms for three functions:
1. Distributing capabilities safely and efficiently among customer processes. In
particular a user process should only be able to access resources for which it was
issued capabilities.
2. Specifying the type of operations a process may execute on a resource, such as
reading or writing.
3. Specifying the order in which operations are performed on the resource, such as
opening before reading.
14.9.2 Protection in Java
Java was designed from the very beginning to operate in a distributed environment, where
code would be executed from a variety of trusted and untrusted sources. As a result the Java
Virtual Machine, JVM incorporates many protection mechanisms
When a Java program runs, it load up classes dynamically, in response to requests to
instantiates objects of particular types. These classes may come from a variety of different
sources, some trusted and some not, which requires that the protection mechanism be
implemented at the resolution of individual classes, something not supported by the basic
operating system.
As each class is loaded, it is placed into a separate protection domain. The capabilities of
each domain depend upon whether the source URL is trusted or not, the presence or
absence of any digital signatures on the class ( Chapter 15 ), and a configurable policy file
indicating which servers a particular user trusts, etc.
When a request is made to access a restricted resource in Java, ( e.g. open a local file ), some
process on the current call stack must specifically assert a privilege to perform the
operation. In essence this method assumes responsibility for the restricted access. Naturally
the method must be part of a class which resides in a protection domain that includes the
capability for the requested operation. This approach is termed stack inspection, and works
like this:
o When a caller may not be trusted, a method executes an access request within a
doPrivileged( ) block, which is noted on the calling stack.
o When access to a protected resource is requested, checkPermissions( ) inspects the
call stack to see if a method has asserted the privilege to access the protected
resource.
If a suitable doPriveleged block is encountered on the stack before a domain
in which the privilege is disallowed, then the request is granted.
If a domain in which the request is disallowed is encountered first, then the
access is denied and a AccessControlException is thrown.
If neither is encountered, then the response is implementation dependent.
In the example below the untrusted applet's call to get( ) succeeds, because the trusted URL
loader asserts the privilege of opening the specific URL lucent.com. However when the
applet tries to make a direct call to open( ) it fails, because it does not have privilege to
access any sockets.