18CSC205J Operating Systems-Unit-5
18CSC205J Operating Systems-Unit-5
1
Course Learning Rationale and Course Learning Outcomes
2
Contents
• STORAGE MANAGEMENT :
• UNDERSTANDING THE BASICS IN STORAGE MANAGEMENT
• DISK SCHEDULING
• UNDERSTANDING THE VARIOUS SCHEDULING WITH RESPECT TO
THE DISK
• FILE SYSTEM INTERFACE:
• FILE CONCEPT
• FILE ACCESS METHODS
• UNDERSTANDING THE FILE BASICS
• FILE SHARING AND PROTECTION
• EMPHASIS THE NEED FOR THE FILE SHARING AND ITS
PROTECTION
• FILE SYSTEM IMPLEMENTATION :
• BASIC FILE SYSTEM STRUCTURE
• FILE SYSTEM IMPLEMENTATION
3
Mass-Storage Systems
• Overview of Mass Storage Structure
– Hard disk
– Magnetic tape
– Storage Array
– Storage Area Networks
– Network Attached Storage
4
Objectives
• To describe the physical structure of secondary storage devices and its effects
on the uses of the devices
• To explain the performance characteristics of mass-storage devices
• To evaluate disk scheduling algorithms
5
Overview of Mass Storage Structure
• Magnetic disks provide bulk of secondary storage of modern computers
– Drives rotate at 60 to 250 times per second
– Transfer rate is rate at which data flow between drive and computer
– Positioning time (random-access time) is time to move disk arm to desired cylinder
(seek time) and time for desired sector to rotate under the disk head (rotational latency)
– Head crash results from disk head making contact with the disk surface -- That’s bad
6
Moving-head Disk Mechanism
7
Hard Disks
• Platters range from .85” to 14” (historically)
– Commonly 3.5”, 2.5”, and 1.8”
8
Hard Disks
• Platters range from .85” to 14” (historically)
– Commonly 3.5”, 2.5”, and 1.8”
9
Terms to be considered for calculating Hard Disk Performance
• 1. Seek time- Seek time is the time taken to locate the disk arm to a specified
track where the data is to be read or write. So the disk scheduling algorithm that
gives minimum average seek time is better.
• 2. Rotational Latency: Rotational Latency is the time taken by the desired
sector of disk to rotate into a position so that it can access the read/write heads.
So the disk scheduling algorithm that gives minimum rotational latency is better.
• 3. Transfer Time: Transfer time is the time to transfer the data. It depends on
the rotating speed of the disk and number of bytes to be transferred.
• 4. Disk Access Time: Disk Access = Seek time + Rotational latency + Transfer
time
10
Hard Disk Performance(contd…)
• To transfer a 4KB block on a 7200 RPM disk with a 5ms average seek time, 1Gb/sec transfer rate with a .1ms
controller overhead calculate average I/O time or Disk access time of 4KB block.
11
The First Commercial Disk Drive
• 1956
• IBM RAMDAC computer included
the IBM Model 350 disk storage
system
• 5M (7 bit) characters
• 50 x 24” platters
• Access time = < 1 second
12
Solid-State Disks
• Nonvolatile memory used like a hard drive
– Many technology variations
13
Magnetic Tape
• Was early secondary-storage medium
– Evolved from open spools to cartridges
• Mainly used for backup, storage of infrequently-used data, transfer medium between systems
14
Disk Structure
• Disk drives are addressed as large 1-dimensional arrays of logical blocks,
where the logical block is the smallest unit of transfer
– Low-level formatting creates logical blocks on physical media
• The 1-dimensional array of logical blocks is mapped into the sectors of the
disk sequentially
– Sector 0 is the first sector of the first track on the outermost cylinder
– Mapping proceeds in order through that track, then the rest of the tracks in that cylinder,
and then through the rest of the cylinders from outermost to innermost
– Logical to physical address should be easy
– Except for bad sectors
– Non-constant # of sectors per track via constant angular velocity
15
Disk Attachment
• Host-attached storage accessed through I/O ports talking to I/O busses
• SCSI itself is a bus, up to 16 devices on one cable, SCSI initiator requests
operation and SCSI targets perform tasks
– Each target can have up to 8 logical units (disks attached to device controller)
16
Storage Array
• Can just attach disks, or arrays of disks
• Storage Array has controller(s), provides features to attached host(s)
– Ports to connect hosts to array
– Memory, controlling software (sometimes NVRAM, etc)
– A few to thousands of disks
– RAID, hot spares, hot swap (discussed later)
– Shared storage -> more efficiency
– Features found in some file systems
– Snaphots, clones, thin provisioning, replication, deduplication, etc
17
Storage Area Network
• Common in large storage environments
• Multiple hosts attached to multiple storage arrays - flexible
18
Storage Area Network (Cont.)
• SAN is one or more storage arrays
– Connected to one or more Fibre
Channel switches
19
Network-Attached Storage
• Network-attached storage (NAS) is storage
made available over a network rather than over
a local connection (such as a bus)
– Remotely attaching to file systems
20
Difference between SAN Vs NAS
21
• Disk Scheduling
– Introduction to Disk Scheduling
– Why Disk Scheduling is Important
– Disk Scheduling Algorithms
– FCFS
– SSTF
– SCAN
– C-SCAN
– LOOK
– C-LOOK
- Disk Management
22
Disk Scheduling
What is Disk Scheduling?
Disk scheduling is done by operating systems to schedule I/O requests arriving for the disk. Disk
scheduling is also known as I/O scheduling.
•The operating system is responsible for using hardware efficiently — for the disk drives, this
means having a fast access time and disk bandwidth
•Minimize seek time
•Seek time seek distance
•Disk bandwidth is the total number of bytes transferred, divided by the total time between the
first request for service and the completion of the last transfer
•There are many sources of disk I/O request
–OS
–System processes
–Users processes
•I/O request includes input or output mode, disk address, memory address, number of sectors to
transfer
•OS maintains queue of requests, per disk or device
23
•Idle disk can immediately work on I/O request, busy disk means work must queue
Why Disk Scheduling is Important?
• Disk scheduling is important because:
• Multiple I/O requests may arrive by different processes and only one I/O
request can be served at a time by the disk controller. Thus other I/O requests
need to wait in the waiting queue and need to be scheduled.
• Two or more request may be far from each other so can result in greater disk
arm movement.
• Hard drives are one of the slowest parts of the computer system and thus need
to be accessed in an efficient manner.
24
Disk Scheduling (Cont.)
• Note that drive controllers have small buffers and can manage a queue of
I/O requests (of varying “depth”)
• Several algorithms exist to schedule the servicing of disk I/O requests
• The analysis is true for one or many platters
25
Disk Scheduling Algorithms
– Disk Scheduling Algorithms
– FCFS
– SSTF
– SCAN
– C-SCAN
– LOOK
– C-LOOK
26
Disk Scheduling Algorithm - Example
• Consider a disk queue with requests for I/O to blocks on cylinders 98, 183, 41,
122, 14, 124, 65, 67. The FCFS,SSTF,SCAN,C-SCAN,LOOK, and C-LOOK
scheduling algorithm is used. The head is initially at cylinder number 53. The
cylinders are numbered from 0 to 199. The total head movement (in number
of cylinders) incurred while servicing these requests is _______.
27
1. FCFS(First Come First Serve)
• FCFS is the simplest of all the Disk Scheduling Algorithms. In FCFS, the requests are addressed in the order they arrive
in the disk queue.
• head is initially at cylinder number 53. The cylinders are numbered from 0 to 199.
1. (98-53)=45
2. (183-98)=85
3. (183-41)=142
4. (122-41)=81
5. 122-14=108
6. 124-14-110
7. 124-65=59
8.67-65=2
28
FCFS(contd..)
• Total head movements using FCFS= [(98 – 53) + (183 – 98) + (183 – 41) + (122 – 41) +
(122 – 14) + (124 – 14) + (124 – 65) + (67 – 65)]
• = 45 + 85 + 142 + 81 + 108 + 110 + 59 + 2
• =632
Advantages:
• Every request gets a fair chance
• No indefinite postponement
Disadvantages:
• Does not try to optimize seek time
• May not provide the best possible service
29
2. SSTF(Shortest Seek Time First)
• Shortest Seek Time First (SSTF) selects the request with the minimum seek time from the current head
position
• SSTF scheduling is a form of SJF scheduling; may cause starvation of some requests
• As a result, the request near the disk arm will get executed first. SSTF is certainly an improvement over
FCFS as it decreases the average response time and increases the throughput of system.
Advantages:
• Average Response Time decreases
• Throughput increases
Disadvantages:
• Overhead to calculate seek time in advance
• Can cause Starvation for a request if it has higher seek time as compared to incoming requests
• High variance of response time as SSTF favours only some requests
30
SSTF(contd…)
• head is initially at cylinder number 53. The cylinders are numbered from 0 to 199.
[98, 183, 41, 122, 14, 124, 65, 67 ]
• 98, 183, 41, 122, 14, 124, 65, 67
32
SCAN or Elevator((1 Solution) st
• head is initially at cylinder number 53. The cylinders are numbered from 0 to 199.
[ 98, 183, 41, 122, 14, 124, 65, 67 ]
35
C-SCAN(contd…)
• head is initially at cylinder number 53. The cylinders are numbered from 0 to 199.
[ 98, 183, 41, 122, 14, 124, 65, 67 ]
37
LOOK(Contd…)
• head is initially at cylinder number 53. The cylinders are numbered from 0 to 199.
[ 98, 183, 41, 122, 14, 124, 65, 67 ]
39
C- LOOK(contd…)
• head is initially at cylinder number 53. The cylinders are numbered from 0 to 199.
41
Selection of a Disk-Scheduling Algorithm
• SSTF is common and has a natural appeal
• SCAN and C-SCAN perform better for systems that place a heavy load on the disk
– Less starvation
• The disk-scheduling algorithm should be written as a separate module of the operating system, allowing it to be
replaced with a different algorithm if necessary
• To use a disk to hold files, the operating system still needs to record its own data structures on the disk
– Partition the disk into one or more groups of cylinders, each treated as a logical disk
– Logical formatting or “making a file system”
– To increase efficiency most file systems group blocks into clusters
– Disk I/O done in blocks
– File I/O done in clusters
43
Disk Management (Cont.)
• Raw disk access for apps that want to do their own block management, keep OS
out of the way (databases for example)
• Boot block initializes system
– The bootstrap is stored in ROM
– Bootstrap loader program stored in boot blocks of boot partition
44
File System Interface
• File Concept
• File Access Methods
• File Sharing and Protection
45
Objective of File Interface
• To explain the function of file systems
• To describe the interfaces to file systems
• To discuss file-system design tradeoffs, including access methods, file
sharing, file locking, and structures
46
File Concept
47
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.
• Files are the most important mechanism for storing data permanently on mass-storage
devices. Permanently means that the data is not lost when the machine is switched off. Files can
contain:
• data in a format that can be interpreted by programs, but not easily by humans (binary files);
• alphanumeric characters, codified in a standard way (e.g., using ASCII or Unicode), and directly
readable by a human user (text files). Text files are normally organized in a sequence of lines, each
containing a sequence of characters and ending with a special character (usually the newline
character). Consider, for example, a Java program stored in a file on the hard-disk. In this unit we
will deal only with text files.
• Each file is characterized by a name and a directory in which the file is placed (one may consider
the whole path that allows one to find the file on the hard-disk as part of the name of the file).
48
File Attributes
• 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
49
File Operations
1.Create
•Creation of the file is the most important operation on the file. Different types of files are created
by different methods for example text editors are used to create a text file, word processors are
used to create a word file and Image editors are used to create the image files.
2.Write
•Writing the file is different from creating the file. The OS maintains a write pointer for every file
which points to the position in the file from which, the data needs to be written.
3.Read
•Every file is opened in three different modes : Read, Write and append. A Read pointer is
maintained by the OS, pointing to the position up to which, the data has been read.
4.Re-position
•Re-positioning is simply moving the file pointers forward or backward depending upon the user's
requirement. It is also called as seeking.
5.Delete
•Deleting the file will not only delete all the data stored inside the file, It also deletes all the
attributes of the file. The space which is allocated to the file will now become available and can be
allocated to the other files.
6.Truncate
•Truncating is simply deleting the file except deleting attributes. The file is not completely deleted
although the information stored inside the file get replaced. 50
File Types – Names,Extension
51
File Structure
52
File Structure
File Structure
classification
Simple Record
None- Structure – Lines, Complex Structure –
Sequence of Fixed and Variable Formatted Document,
words,bytes Length Relocatable load file
53
File Access Methods
File Access
Methods
54
File Access Methods
1. Sequential Access Method: – Sequential Access Method is one of the simplest file
access methods. Most of the OS (operating system) uses a sequential access method to
access the file. In this method, word by word, the operating system read the file, and
we have a pointer that points the file’s base address. If we need to read the file’s first
word, then there is a pointer that offers the word which we want to read and
increment the value of the word by 1, and till the end of the file, this process will
continue.
• The Modern world system offers the facility of index access and direct access to file.
But the sequential access method is one of the most used methods because more files
like text files, audio files, and the video files require to be sequentially accessed.
• Key Points:
1. Sequential Access Method is reasonable for tape.
2. In the sequential access method, if we use read command, then the pointer is moved
ahead by 1.
3. If the write command is used, then the memory will be allocated, and at the end of the
file, a pointer will be moved. 55
File Access Methods
2. Direct Access Method: – Direct Access Method is also called the Relative
access method. In the Database System, we mostly use the Direct Access
Method. In most of the situations, there is a need for information in the filtered
form from the database. And in that case, the speed of sequential access may
be low and not efficient.
• Let us assume that each storage block stores 4 records, and we already know
that the block which we require is stored in the 10 th block. In this situation,
the sequential access method is not suitable. Since if we use this, then to
access the record which is needed, this method will traverse all the blocks.
• So, in this situation, the Direct access method gives a more satisfying result,
else the OS (operating system) needs to perform a few complex jobs like
defining the block number, which is required. It is mostly implemented in the
application of the database.
56
File Access Methods
3. Index Access Method: – Index Access Method is another essential method
of file, accessing. In this method, for a file an index is created, and the index is
just like an index which is at the back of the book. The index includes the
pointer to the different blocks. If we want to find a record in the file, then first,
we search in the index, and after that, with the help of the pointer, we can
directly access the file.
• In the Index Access method, we can search fast in the large database, and
also easy. But in this, the method need some additional space to store the
value of the index in the memory.
• Key Points:
1. On top of the sequential access method, the index access method is built.
2. The Index access method can control the pointer with the help of the index.
57
File Sharing
Objective of File sharing
• For multiple users-File sharing, file naming and file protection is a challenging and
important task.
• In order to handle this, file access control and protection need to be done.
• If a user wants to share a file with other user, proper protection schemes need to be
followed.
• Whenever a file is shared for various users on distributed systems , it must be shared
across distributed systems.
• In order to share and distribute files, Network File System (NFS) is used.
• For single user system ,the system need to maintain many files and directory
attributes.
File sharing-Multiple Users
• Many file systems evolved with the concept of file (or directory) owner (or
user) and group.
• The owner is the user who can change attributes and grant access and who has
the most control over the file.
• The group attribute defines a subset of users who can share access to the file.
• For example, the owner of a file on a UNIX system can issue all operations on
a file, while members of the file’s group can execute one subset of those
operations, and all other users can execute another subset of operations.
Exactly which operations can be executed by group members and other users
is definable by the file’s owner
File sharing-Remote File Systems
• The communication among remote computers uses the concept called Networking
that allows the sharing of resources spread across a campus or even around the world.
• The first implemented method for file sharing involves manually transferring files
between machines via programs like ftp.
• The second major method for file sharing uses a distributed file system (DFS) in
which remote directories are visible from a local machine.
• The third method for file sharing , uses WorldWide Web, is a reversion to the first.
• A browser is needed to gain access to the remote files, and separate operations
(essentially a wrapper for ftp) are used to transfer files.
• Increasingly, cloud computing is being used for file sharing as well.
File sharing-Remote File Systems
• ftp is used for both anonymous and authenticated access.
• Anonymous access allows a user to transfer files without having an account
on the remote system.
• TheWorldWideWeb uses anonymous file exchange almost exclusively.
• DFS involves a much tighter integration between the machine that is
accessing the remote files and the machine providing the files.
File sharing-Remote File Systems
Distributed
Client –Server Model Information Systems Failure Modes
File sharing-Remote File Systems-
Client Server Model
• The machine containing the files is the server, and the machine seeking
access to the files is the client.
• The server can serve multiple clients, and a client can use multiple servers,
depending on the implementation details of a given client–server facility.
• Example:
– NFS is standard UNIX client-server file sharing protocol
– CIFS is standard Windows protocol
– Standard operating system file calls are translated into remote calls
File sharing -Distributed Information
Systems
• Distributed Information Systems (distributed naming services) such as LDAP,
DNS, NIS, Active Directory implement unified access to information needed for
remote computing
• Examples:
• Other distributed information systems provide user name/password/user
ID/group ID space for a distributed facility.
• UNIX systems have employed a wide variety of distributed information
methods.
• Sun Microsystems introduced yellow pages (since renamed network
information service, or NIS), and most of the industry adopted its use.
File Sharing -Failure Modes
• All file systems have failure modes
– For example corruption of directory structures or other non-user data, called metadata
• Remote file systems add new failure modes, due to network failure, server
failure
• Recovery from failure can involve state information about status of each
remote request
• Stateless protocols such as NFS v3 include all information in each request,
allowing easy recovery but less security
File Sharing-Consistency Semantics
• Consistency semantics represent an important criterion for evaluating any
file system that supports file sharing.
• These semantics specify how multiple users of a system are to access a shared
file simultaneously.
• In particular, they specify when modifications of data by one user will be
observable by other users.
• These semantics are typically implemented as code with the file system.
• Consistency semantics are directly related to the process synchronization
algorithms
File sharing - Consistency Semantics
Consistency Semantics
• The first column represents different access modes, i.e., the permission associated with a file or a
directory.
• The permissions are broken into groups of threes, and each position in the group denotes a specific
permission, in this order: read (r), write (w), execute (x) −
• The first three characters (2-4) represent the permissions for the file's owner. For example, -rwxr-
xr-- represents that the owner has read (r), write (w) and execute (x) permission.
• The second group of three characters (5-7) consists of the permissions for the group to which the
file belongs. For example, -rwxr-xr-- represents that the group has read (r) and execute (x)
permission, but no write permission.
• The last group of three characters (8-10) represents the permissions for everyone else. For
example, -rwxr-xr-- represents that there is read (r) only permission.
File System
Implementation
78
File System Implementation
- File System Structure
- Directory Implementation
- File Allocation Methods
- Swap Space Management
79
Objectives of File System Implementation
• It helps to understand the file system structure
• It helps to apprehend about how the files and folders are organized in the
directory structure and its classification
• To describe the implementation of remote file systems
• To discuss block allocation and free-block algorithms and trade-offs
• To describe the details of implementing local file systems and directory
structures
80
File-System Structure
• File structure
– Logical storage unit
– Collection of related information
• The logical file system contains the Meta data information of the file and
directory structure and provides protection also. It translates file name into file
number, file handle, location by maintaining file control blocks (inodes in UNIX)
• The basic file system - issues the commands to I/O control in order to fetch those
blocks. Basic file system given command like “retrieve block 123” translates to
device driver.
• I/O controls contain the codes by using which it can access hard disk.
• These codes are known as device driversGiven commands like “read drive1,
cylinder 72, track 2, sector 10, into memory location 1060” outputs low-level
hardware specific commands to hardware controller
File System Implementation
• on-disk and in-memory structures
• On Disk Data Structures
• Boot Control Block - Boot Control Block contains all the information which is needed to
boot an operating system from that volume. It is called boot block in UNIX file system. In
NTFS, it is called the partition boot sector.
• Volume Control Block - Volume control block all the information regarding that volume such
as number of blocks, size of each block, partition table, pointers to free blocks and free FCB
blocks. In UNIX file system, it is known as super block. In NTFS, this information is stored
inside master file table.
• Directory Structure (per file system) -A directory structure (per file system) contains file File control Block
names and pointers to corresponding FCBs.
• File Control Block - File Control block contains all the details about the file such as
ownership details, permission details, file size,etc. In UFS, this detail is stored in inode.
In-Memory File System Structures
• The in-memory data structures are used for file system management as well as
performance improvement via caching. This information is loaded on the
mount time and discarded on ejection.
Virtual File Systems
Virtual File Systems, VFS, provide a common
interface to multiple different filesystem types. In
addition, it provides for a unique identifier ( vnode )
for files across the entire space, including across all
filesystems of different types. ( UNIX inodes are
unique only across a single filesystem, and certainly
do not carry across networked file systems. )
The VFS in Linux is based upon four key object
types:
o The inode object, representing an individual file
o The file object, representing an open file.
o The superblock object, representing a filesystem.
o The dentry object, representing a directory entry.
Directory Implementation
Directories need to be fast to search, insert, and delete, with a minimum of wasted disk space.
Linear List
• A linear list is the simplest and easiest directory structure to set up, but it does have some drawbacks.
• Finding a file ( or verifying one does not already exist upon creation ) requires a linear search.
• Deletions can be done by moving all entries, flagging an entry as deleted, or by moving the last entry into the newly
vacant position.
• Sorting the list makes searches faster, at the expense of more complex insertions and deletions.
• A linked list makes insertions and deletions into a sorted list easier, with overhead for the links.
• More complex data structures, such as B-trees, could also be considered.
Hash Table
• A hash table can also be used to speed up searches.
• Hash tables are generally implemented in addition to a linear or other structure
Directory Structure
• A directory is a container that is used to contain folders and file. It organizes files
and folders into a hierarchical manner.
Directory Structure(Contd…)
• There are several logical structures of a directory, these are given below.
1. Single-level directory
2. Two-level directory
3. Tree-structured directory
4. Acyclic graph directory
5. General graph directory structure
88
1. Single level Directory Structure
• 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.
89
Single level Directory Structure(Contd…)
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.
90
2. Two-level directory
• 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.
91
Two-level directory (contd…)
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
92
3. 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
93
Tree-structured directory(contd…)
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:
1. Very generalize, since full path name can be given.
2. Very scalable, the probability of name collision is less.
3. Searching becomes very easy, we can use both absolute path as well as relative
Disadvantages:
4. Every file does not fit into the hierarchical model, files may be saved into multiple directories.
5. We can not share files.
6. It is inefficient, because accessing a file may go under multiple directories.
94
4. 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.
95
Acyclic graph directory(contd…)
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.
96
5. 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
97
General graph directory structure(contd…)
Advantages:
• It allows cycles.
• It is more flexible than other directories structure.
Disadvantages:
• It is more costly than others.
• It needs garbage collection.
98
Allocation Methods
• An allocation method refers to how disk blocks are allocated for files:
• Contiguous allocation
• Linked allocation
• Indexed allocation
99
Contiguous Allocation
• Each file occupies a set of contiguous blocks on the disk
• Simple – only starting location (block #) and length (number of blocks) are required
• Random access
100
Contiguous Allocation
• Mapping from logical to physical
– Block to be accessed = ! + starting address
– Displacement into block = R
Q
LA/512
R
101
Contiguous Allocation of Disk Space
102
Extent-Based Systems
• Many newer file systems (I.e. Veritas File System) use a modified contiguous
allocation scheme
103
Linked Allocation
Each file is a linked list of disk blocks: blocks may be scattered anywhere on the
disk.
block = pointer
104
Linked Allocation (Cont.)
• Simple – need only starting address
• Free-space management system – no waste of space
• No random access
• Mapping
Block to be accessed is the Qth block in the linked chain of blocks representing the file.
Displacement into block = R + 1
File-allocation table (FAT) – disk-space allocation used by MS-DOS and OS/2.
Q
LA/511
R
105
Linked Allocation
106
File-Allocation Table
107
Indexed Allocation
• Brings all pointers together into the index block
• Logical view
index table
108
Example of Indexed Allocation
109
Indexed Allocation (Cont.)
• Need index table
• Random access
• Dynamic access without external fragmentation, but have overhead of index
block
• Mapping from logical to physical in a file of maximum size of 256K words
and block size of 512 words. We need only 1 block for index table
Q = displacement into index table Q
LA/512
R = displacement into block R
110
Indexed Allocation – Mapping (Cont.)
• Mapping from logical to physical in a file of unbounded length (block size of
512 words)
• Linked scheme – Link blocks of index table (no limit on size)
Q1
Q1 = block of index table
LA / (512 x 511)
R1 is used as follows:
R1
R2
111
Indexed Allocation – Mapping (Cont.)
• Two-level index (maximum file size is 5123)
Q1 = displacement into outer-index Q1
LA / (512 x 512)
R1 is used as follows: R1
R2
112
Indexed Allocation – Mapping (Cont.)
outer-index
113
Worksheet
Problem:1
Consider a file currently consisting of 100 blocks. Assume that the file-control block (and the index
block, in the case of indexed allocation)is already in memory. Calculate how many disk I/O
operations are required for contiguous, linked, and indexed (single-level) allocation strategies, if, for
one block, the following conditions hold. In the contiguous-allocation case, assume that there is no
room to grow at the beginning but there is room to grow at the end. Also assume that the block
information to be added is stored in memory.
0 block[i] free
bit[i] =
1 block[i] occupied
118
Free-Space Management (Cont.)
• Bit map requires extra space
– Example:
• Grouping
• Counting
119
Free-Space Management (Cont.)
• Need to protect:
– Pointer to free list
– Bit map
– Must be kept on disk
– Copy in memory and disk may differ
– Cannot allow for block[i] to have a situation where bit[i] = 1 in memory and bit[i] = 0 on disk
– Solution:
– Set bit[i] = 1 in disk
– Allocate block[i]
– Set bit[i] = 1 in memory
120
Directory Implementation
• Linear list of file names with pointer to the data blocks
– simple to program
– time-consuming to execute
121
Linked Free Space List on Disk
122
Efficiency and Performance
• Efficiency dependent on:
– disk allocation and directory algorithms
– types of data kept in file’s directory entry
• Performance
– disk cache – separate section of main memory for frequently used blocks
– free-behind and read-ahead – techniques to optimize sequential access
– improve PC performance by dedicating section of memory as virtual disk, or RAM disk
123
Free Space Management
Objectives :
• Operating system maintains a list of free disk spaces to keep track of all disk
blocks which are not being used by any file.
• Whenever a file has to be created, the list of free disk space is searched for
and then allocated to the new file.
• 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.
• Hence there is need for understanding the methods available for managing
free space in the disk
124
Understanding the methods available for maintaining the free
spaces in the disk
The system keeps tracks of the free disk blocks for allocating space to
files when they are created.
Also, to reuse the space released from deleting the files, free space
management becomes crucial.
The system maintains a free space list which keeps track of the disk
blocks that are not allocated to some file or directory.
• The free space list can be implemented mainly as:
1.Bitmap or Bit vector
• A Bitmap or Bit Vector is series or collection of bits where each bit corresponds to a
disk block.
• The bit can take two values: 0 and 1: 0 indicates that the block is allocated and 1
indicates a free block.
• The given instance of disk blocks on the disk in Figure 1 (where green blocks are
allocated) can be represented by a bitmap of 16 bits as: 0000111000000110.
Bitmap or Bit vector
•For the Figure-1, we scan the bitmap sequentially for the first non-zero word.
•The first group of 8 bits (00001110) constitute a non-zero word since all bits are not 0.
•
•After the non-0 word is found, we look for the first 1 bit. This is the 5th bit of the non-
zero word. So, offset = 5.
138