File System (1)
File System (1)
File-System Interface
Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013
Chapter 11: File-System Interface
File Concept
Access Methods
File-System Mounting
File Sharing
Protection
Operating System Concepts – 9th Edition 11.2 Silberschatz, Galvin and Gagne ©2013
Objectives
Operating System Concepts – 9th Edition 11.3 Silberschatz, Galvin and Gagne ©2013
File Concept
secondary storage.
Operating System Concepts – 9th Edition 11.4 Silberschatz, Galvin and Gagne ©2013
File Concept
Commonly, files represent Types:
• Data
o numeric
o Alphabetic
o Alphanumeric
o binary
• Program (both source and object forms)
The information in a file is defined by its creator.
Many different types of information may be stored in a file—source or executable
programs, numeric or text data, photos, music, video, and so on.
Operating System Concepts – 9th Edition 11.5 Silberschatz, Galvin and Gagne ©2013
File Concept
An executable file is a series of code sections that the loader can bring
Operating System Concepts – 9th Edition 11.6 Silberschatz, Galvin and Gagne ©2013
File Attributes
Name – only information kept in human-readable form
Time, date, and user identification – data for protection, security, and usage monitoring.
Information about files are kept in the directory structure, which is maintained on the disk Many
variations, including extended file attributes such as file checksum.
Operating System Concepts – 9th Edition 11.7 Silberschatz, Galvin and Gagne ©2013
File Attributes
a.txt
b.doc
c.mp3
Operating System Concepts – 9th Edition 11.8 Silberschatz, Galvin and Gagne ©2013
File info Window on Mac OS X
Operating System Concepts – 9th Edition 11.9 Silberschatz, Galvin and Gagne ©2013
File Attributes
The information about all files is kept in the directory structure, which
Operating System Concepts – 9th Edition 11.10 Silberschatz, Galvin and Gagne ©2013
File Operations
File is an abstract data type. The operating system can provide system calls to
•Create
•Write – at write pointer location
•Read – at read pointer location
•Reposition within file - seek
•Delete
•Truncate
•Other Operations : appending, renaming, create copy
•Open(Fi)
•Close (Fi) .
Operating System Concepts – 9th Edition 11.11 Silberschatz, Galvin and Gagne ©2013
File Operations
A file is an abstract data type. To define a file properly, we need to consider the
operation performed on the file.
Operating System can provide system calls to create, write, read, reposition,
delete and truncate files.
1. Creating a File: Creation of a file is the first operation. For creating a file two
steps are necessary.
• Required space must be allocated.
• An entry for new file must be made in the directory.
• The directory entry records the name of the file and the location in the file
system.
Operating System Concepts – 9th Edition 11.12 Silberschatz, Galvin and Gagne ©2013
File Operations
2. Writing a File:
For file writing operation, we make a system call specifying both the name
of a file and the information to be written into the file.
System searches the entire directory structure to find the location of the
specified file.
System keeps a write pointer that keeps track of writing at the location in the
file.
The system updates write pointer each time whenever a file write operation
occurs.
Operating System Concepts – 9th Edition 11.13 Silberschatz, Galvin and Gagne ©2013
File Operations
3. Reading a File:
To perform file read operation, we use a system call that specifies name of
the file and the block of the file to read from it.
Again the directory is searched for the specified file.
System keeps a read pointer that keeps track of reading location in the file.
The system updates read pointer each time whenever a file read operation
occurs
4. Repositioning Within a File
• Repositioning within a file operation does not involve any actual input
output.
• The directory is searched for the appropriate entry and the current file
position is set to a given value.
• It is also known as files seek operation.
Operating System Concepts – 9th Edition 11.14 Silberschatz, Galvin and Gagne ©2013
File Operations
5. Deleting a File:
File deletion operation also requires searching of a specified file entry
within the directory structure.
As soon as the file is deleted, space allocated to that file becomes available
for further use.
6. Truncating a File
In some cases the user may want to erase the file contents but keep its
attributes as it is. This operation is called truncating a file.
Instead of delete a file and recreating it with same attributes, this function
allows all attributes to remain unchanged except the file content.
File length attribute is reset to a length zero and its file space is released.
Operating System Concepts – 9th Edition 11.15 Silberschatz, Galvin and Gagne ©2013
Open Files
The OS keeps a small table, called the open-file table, containing information
about all open files.
When a file operation is requested, the file is specified via an index into
this table, so no searching is required.
When the file is no longer being actively used, it is closed by the process,
and the OS removes its entry from the open-file table.
Most systems require that the programmer open a file explicitly with
the open() system call before that file can be used.
The open() operation takes a file name and searches the directory, copying the
directory entry into the open-file table.
Operating System Concepts – 9th Edition 11.16 Silberschatz, Galvin and Gagne ©2013
File Attributes
a.txt
a.txt
b.doc
c.mp3
Open File Table
Operating System Concepts – 9th Edition 11.17 Silberschatz, Galvin and Gagne ©2013
Open Files
Several processes may open the file where several processes may open the file
simultaneously.
Typically, the operating system uses two levels of internal tables: a per-process
table and a system-wide table.
System-wide table: stores process-independent information, such as the
location of the file on disk, access dates, and file size.
Per-process table: tracks all files that a process has open, Store information
regarding the process’s use of the file Example: the current file pointer for each file
is found here, Access rights to the file and accounting, information.
Each entry in the per-process table in turn points to a system-wide open-file
table
Operating System Concepts – 9th Edition 11.18 Silberschatz, Galvin and Gagne ©2013
File Attributes
a.txt
b.doc
Operating System Concepts – 9th Edition 11.19 Silberschatz, Galvin and Gagne ©2013
Open Files
Once a file has been opened by one process, the system-wide table includes an
entry for the file. When another process executes an open() call, a new entry is
simply added to the process’s open-file table pointing to the appropriate entry
in the system-wide table.
Open count: Typically, the open-file table also has an open count associated
with each file to indicate how many processes have the file open. Each close()
decreases this open count, and when the open count reaches zero, the file is no
longer in use, and the file’s entry is removed from the open-file table.
Operating System Concepts – 9th Edition 11.20 Silberschatz, Galvin and Gagne ©2013
Open Files
File Pointer: Track the last read–write location per process that has the file
open
Operating System Concepts – 9th Edition 11.21 Silberschatz, Galvin and Gagne ©2013
Open File Locking
File locks are provided by some operating systems and file systems allow one process to lock
a file and prevent other processes from gaining access to it.
Shared lock similar to reader lock – several processes can acquire concurrently
Mandatory – access is denied depending on locks held and requested, the operating
system ensures locking integrity.
Operating System Concepts – 9th Edition 11.22 Silberschatz, Galvin and Gagne ©2013
File Locking Example – Java API
import java.io.*;
import java.nio.channels.*;
public class LockingExample {
public static final boolean EXCLUSIVE = false;
public static final boolean SHARED = true;
public static void main(String arsg[]) throws IOException {
FileLock sharedLock = null;
FileLock exclusiveLock = null;
try {
RandomAccessFile raf = new RandomAccessFile("file.txt", "rw");
// get the channel for the file
FileChannel ch = raf.getChannel();
// this locks the first half of the file - exclusive
exclusiveLock = ch.lock(0, raf.length()/2, EXCLUSIVE);
/** Now modify the data . . . */
// release the lock
exclusiveLock.release();
Operating System Concepts – 9th Edition 11.23 Silberschatz, Galvin and Gagne ©2013
File Locking Example – Java API (Cont.)
Operating System Concepts – 9th Edition 11.24 Silberschatz, Galvin and Gagne ©2013
File Types – Name, Extension
• The name is split into two parts—a name and an extension. Examples include
resume.docx, server.c, and ReaderThread.cpp.
Operating System Concepts – 9th Edition 11.25 Silberschatz, Galvin and Gagne ©2013
File Structure
File types also can be used to indicate the internal structure of the file. Files have
structures that match the expectations of the programs that read them.
Further, certain files must conform to a required structure that is understood by the
operating system.
Some operating systems extend this idea into a set of system-supported file structures,
with sets of special operations for manipulating files with those structures.
File structure is the organization of the data in secondary storage in such a way that it
can minimize the access time and storage space.
Operating System Concepts – 9th Edition 11.26 Silberschatz, Galvin and Gagne ©2013
File Structure
Disadvantages of having the operating system support multiple file structures:
In addition, it may be necessary to define every file as one of the file types supported
by the operating system. When new applications require information structured in
ways not supported by the operating system, severe problems may result.
Ex: For example, assume that a system supports two types of files: text files and
executable binary files. Now, if we (as users) want to define an encrypted file we may
find neither file type to be appropriate.
Operating System Concepts – 9th Edition 11.27 Silberschatz, Galvin and Gagne ©2013
File Structure
A file have different kind of structure
Operating System Concepts – 9th Edition 11.28 Silberschatz, Galvin and Gagne ©2013
File Access Methods
File access mechanism refers to the manner in which the records of a file may be
accessed. There are several ways to access files −
1. Sequential access
2. Direct/Random access
Operating System Concepts – 9th Edition 11.29 Silberschatz, Galvin and Gagne ©2013
File Access Methods
1. Sequential Access: With sequential access, the device must move through all information up to the location where
it is attempting to read or write. Based on Tape model.
Similarly, the write operation—write next()—appends to the end of the file and advances to the end of the newly
written material (the new end of file)..
This mode of access is by far the most common; for example, editors and compilers usually access files in this
fashion.
A file can be reset to the beginning, and on some systems, a program may be able to skip forward or
backward n records for some integer n—perhaps only for n = 1. Sequential access.
Operating System Concepts – 9th Edition 11.30 Silberschatz, Galvin and Gagne ©2013
Sequential-access File
Operating System Concepts – 9th Edition 11.31 Silberschatz, Galvin and Gagne ©2013
File Access Methods
2. Direct Access Methods: Another method is direct access (or relative access).
The direct-access method is based on a disk model of a file, since disks allow 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.
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, rather than read next(), and write(n) rather than write
next().
Operating System Concepts – 9th Edition 11.32 Silberschatz, Galvin and Gagne ©2013
File Access Methods
3. Other Access Methods
These methods generally involve the construction of an index for the file. The index, like
an index in the back of a book, contains pointers to the various blocks.
To find a record in the file, we first search the index and then use the pointer to access the
file directly and to find the desired record.
For example, IBM’s indexed sequential-access method (ISAM) uses a small master index
that points to disk blocks of a secondary index
Operating System Concepts – 9th Edition 11.33 Silberschatz, Galvin and Gagne ©2013
File Access Methods
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. In this way, any record
can
Operating System Concepts – 9th Edition 11.34 Silberschatz, Galvin and Gagne ©2013
File Access Methods
Sequential Access
read next
write next
reset
no read after last write
(rewrite)
Direct Access – file is fixed length logical records
read n
write n
position to n
read next
write next
rewrite n
n = relative block number
Operating System Concepts – 9th Edition 11.35 Silberschatz, Galvin and Gagne ©2013
Simulation of Sequential Access on Direct-access File
Operating System Concepts – 9th Edition 11.36 Silberschatz, Galvin and Gagne ©2013
Other Access Methods
Can be built on top of base methods
Keep index in memory for fast determination of location of data to be operated on (consider UPC
code plus record of data about that item)
VMS operating system provides index and relative files as another example (see next slide)
Operating System Concepts – 9th Edition 11.37 Silberschatz, Galvin and Gagne ©2013
Example of Index and Relative Files
Operating System Concepts – 9th Edition 11.38 Silberschatz, Galvin and Gagne ©2013
Directory Structure
A collection of nodes containing information about all files
Directory
Files
F1 F2 F4
F3
Fn
Operating System Concepts – 9th Edition 11.39 Silberschatz, Galvin and Gagne ©2013
Disk Structure
• Files are stored on random-access storage devices, including hard disks, optical
disk can be partitioned and each partition can hold a separate file system.
• Storage devices can also be collected together into RAID (Redundant Arrays of
Independent Disks) sets that provide protection from the failure of a single disk.
• Partitioning is useful:
• Limiting the sizes of individual file systems
• Putting multiple file-system types on the same device
• Leaving part of the device available for other uses, such as swap space or
unformatted (raw) disk space.
Operating System Concepts – 9th Edition 11.40 Silberschatz, Galvin and Gagne ©2013
Disk Structure
Operating System Concepts – 9th Edition 11.41 Silberschatz, Galvin and Gagne ©2013
Disk Structure
Operating System Concepts – 9th Edition 11.42 Silberschatz, Galvin and Gagne ©2013
Disk Structure
Operating System Concepts – 9th Edition 11.43 Silberschatz, Galvin and Gagne ©2013
Disk Structure
Operating System Concepts – 9th Edition 11.44 Silberschatz, Galvin and Gagne ©2013
Disk Structure
Operating System Concepts – 9th Edition 11.45 Silberschatz, Galvin and Gagne ©2013
Disk Structure
Operating System Concepts – 9th Edition 11.46 Silberschatz, Galvin and Gagne ©2013
Directory and Disk Structure
Volumes can also store multiple operating systems, allowing a system to boot and
information—such as name, location, size, and type—for all files on that volume.
Operating System Concepts – 9th Edition 11.47 Silberschatz, Galvin and Gagne ©2013
A Typical File-system Organization
Operating System Concepts – 9th Edition 11.48 Silberschatz, Galvin and Gagne ©2013
Typical File-system ON Windows
systems.
Operating System Concepts – 9th Edition 11.49 Silberschatz, Galvin and Gagne ©2013
Types of File Systems
We mostly talk of general-purpose file systems, But systems frequently have many file
systems, some general- and some special- purpose
• objfs – Interface into kernel memory to get kernel symbols for debugging.
Operating System Concepts – 9th Edition 11.50 Silberschatz, Galvin and Gagne ©2013
Directory Structure
A directory is a container that is used to contain folders and files. It organizes files
Operating System Concepts – 9th Edition 11.51 Silberschatz, Galvin and Gagne ©2013
Directory Structure
• In a directory structure, we can store the complete file attributes and with
the help of the directory, we can maintain the information related to the
files.
Operating System Concepts – 9th Edition 11.52 Silberschatz, Galvin and Gagne ©2013
Operations Performed on Directory
Create a file
Delete a file
List a directory
Rename a file
Operating System Concepts – 9th Edition 11.53 Silberschatz, Galvin and Gagne ©2013
Directory Organization
Grouping – Logical grouping of files by properties, (e.g. all Java programs, all
games, …).
Operating System Concepts – 9th Edition 11.54 Silberschatz, Galvin and Gagne ©2013
Single-Level Directory
This is the simplest directory structure to implement. All files are contained in the
same directory.
Limitation of single level directory structure is that when number of files increase
or when the system has more than one user, it becomes unmanageable.
Since all files are in this same directory, the name must be unique.
Can’t create subdirectories, Ex: the directory called data can have no of files but
can not create more subdirectories.
Operating System Concepts – 9th Edition 11.55 Silberschatz, Galvin and Gagne ©2013
Single-Level Directory
Advantages:
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 (High Overhead).
This can not group the same type of files together (Grouping Problem).
Choosing the unique name for every file is a bit complex and limits the number of files in the system because most of the
Operating System limits the number of characters used to construct the file name (Scalability).
Operating System Concepts – 9th Edition 11.56 Silberschatz, Galvin and Gagne ©2013
Two-Level Directory
In two level directory systems, There is one master directory which contains a separate directory for each user.
The system doesn't let a user to enter in the other user's directory without permission.
Operating System Concepts – 9th Edition 11.57 Silberschatz, Galvin and Gagne ©2013
Two-Level Directory
Advantages:
Different users can have the same directory as well as the file name.
Disadvantages:
Still, it not very scalable, two files of the same type cannot be grouped together in the same user.
Operating System Concepts – 9th Edition 11.58 Silberschatz, Galvin and Gagne ©2013
Tree-Structured Directories
or sub directory.
The similar kind of files can now be grouped in one directory.
Operating System Concepts – 9th Edition 11.59 Silberschatz, Galvin and Gagne ©2013
Tree-Structured Directories
Operating System Concepts – 9th Edition 11.60 Silberschatz, Galvin and Gagne ©2013
Tree-Structured Directories
Operating System Concepts – 9th Edition 11.61 Silberschatz, Galvin and Gagne ©2013
Tree-Structured Directories (Cont.)
Advantages:
Searching becomes very easy, we can use both absolute paths as well as relative path.
Disadvantages:
Every file does not fit into the hierarchical model, files may be saved into multiple
directories.
Tree-structure directory is not efficient because, in this, if we want to access a file, then it
Operating System Concepts – 9th Edition 11.62 Silberschatz, Galvin and Gagne ©2013
Tree-Structured Directories (Cont)
Absolute or relative path name
mkdir <dir-name>
mkdir count
Operating System Concepts – 9th Edition 11.63 Silberschatz, Galvin and Gagne ©2013
Acyclic-Graph Directories (Cont.)
Two different names (aliasing)
Solutions:
Entry-hold-count solution
Operating System Concepts – 9th Edition 11.64 Silberschatz, Galvin and Gagne ©2013
Acyclic-Graph Directories (Cont.)
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.
Operating System Concepts – 9th Edition 11.65 Silberschatz, Galvin and Gagne ©2013
Acyclic-Graph Directories (Cont.)
It is used in the situation like when two programmers are working on a joint
project and they need to access files.
These kinds of directory graphs can be made using links or aliases. We can have
multiple paths for a same file.
Operating System Concepts – 9th Edition 11.66 Silberschatz, Galvin and Gagne ©2013
Acyclic-Graph Directories (Cont.)
Operating System Concepts – 9th Edition 11.67 Silberschatz, Galvin and Gagne ©2013
Acyclic-Graph Directories (Cont.)
Advantages:
We can share files.
Searching is easy due to different-different paths.
Disadvantages:
We share the files via linking, in case deleting it may create the problem,
If the link is a soft link then after deleting the file we left with a dangling pointer.
In the case of a hard link, to delete a file we have to delete all the references associated
with it.
Operating System Concepts – 9th Edition 11.68 Silberschatz, Galvin and Gagne ©2013
General Graph Directory (Cont.)
of the directory where we can derive the various directory with the help of
more than one parent directory.
Operating System Concepts – 9th Edition 11.69 Silberschatz, Galvin and Gagne ©2013
General Graph Directory (Cont.)
Operating System Concepts – 9th Edition 11.70 Silberschatz, Galvin and Gagne ©2013
General Graph Directory (Cont.)
Advantages
The advantages of general-graph directory are:
1.The General-Graph directory is more flexible than the other directory structure.
Disadvantages
The disadvantages of general-graph directory are:
1.In general-graph directory, garbage collection is required.
Operating System Concepts – 9th Edition 11.71 Silberschatz, Galvin and Gagne ©2013
General Graph Directory (Cont.)
Garbage collection
Operating System Concepts – 9th Edition 11.72 Silberschatz, Galvin and Gagne ©2013
File Sharing
On distributed systems, files may be shared across a network, Network File System
(NFS) is a common distributed file-sharing method
In a multi-user system
Owner of a file /directory: grant access, has the most control over the file
Group of a file/directory: subset of users who can share access to the file.
Operating System Concepts – 9th Edition 11.73 Silberschatz, Galvin and Gagne ©2013
File Sharing – Remote File Systems
Uses networking to allow communication among remote computers.
The first implemented method is manually sending via programs like FTP
The second major method uses a distributed file system (DFS) in which remote
directories are visible from a local machine.
The third method is the WorldWide Web, is a reversion to the first. A browser is
needed to gain access to the remote files, and separate operations are used to
transfer files. Increasingly, cloud computing is being used for file sharing as well.
Operating System Concepts – 9th Edition 11.74 Silberschatz, Galvin and Gagne ©2013
File Sharing – Client Server Model
The machine containing the files is the server, and the machine seeking access to the files is the
client.
The server declares that a resource is available to clients and specifies exactly which resource
and exactly which clients.
Server can serve multiple clients, client can use multiple servers.
Client identification is more difficult. A client can be specified by a network name or other
identifier, such as an IP address, but these can be spoofed, or imitated.
File operation requests are sent on behalf of the user with id) across the network to the server
via the DFS protocol.
The server then applies the standard access checks to determine access rights. The request is
either allowed or denied. If it is allowed, a file handle is returned to the client application, and
the application then can perform read, write, and other operations on the file.
Operating System Concepts – 9th Edition 11.75 Silberschatz, Galvin and Gagne ©2013
File Sharing – Distributed Information Systems
To make client–server systems easier to manage, distributed information systems, also
known as distributed naming services, provide unified access to the information needed for
remote computing.
Before DNS became widespread, files containing the same information were sent via e-mail
or ftp between all networked hosts.
Operating System Concepts – 9th Edition 11.76 Silberschatz, Galvin and Gagne ©2013
File Sharing – Distributed Information Systems
The machine containing the files is the server, and the machine seeking access to the files is
the client.
The server declares that a resource is available to clients and specifies exactly which
resource and exactly which clients.
Server can serve multiple clients, client can use multiple servers.
Standard operating system file calls are translated into remote calls
Distributed Information Systems (distributed naming services) such as LDAP, DNS, NIS,
Active Directory implement unified access to information needed for remote computing
Operating System Concepts – 9th Edition 11.77 Silberschatz, Galvin and Gagne ©2013
File Sharing – Failure Modes
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
Operating System Concepts – 9th Edition 11.78 Silberschatz, Galvin and Gagne ©2013
File Sharing – Consistency Semantics
Consistency Semantics deals with the consistency between the views of shared files on a
networked system. When one user changes the file, when do other users see the changes?
UNIX Semantics
Writes to an open file are immediately visible to any other user who has the file open.
One implementation uses a shared location pointer, which is adjusted for all sharing
users.
The file is associated with a single exclusive physical resource, which may delay some
accesses.
Operating System Concepts – 9th Edition 11.79 Silberschatz, Galvin and Gagne ©2013
File Sharing – Consistency Semantics
Session Semantics
When a file is closed, any changes made become available only to users who open the file
at a later time.
According to these semantics, a file can be associated with multiple ( possibly different ) views.
AFS file systems may be accessible by systems around the world. Access control is maintained
through ( somewhat ) complicated access control lists, which may grant access to the entire world
( literally ) or to specifically named users accessing the files from specifically named remote
environments.
Operating System Concepts – 9th Edition 11.80 Silberschatz, Galvin and Gagne ©2013
File Sharing – Consistency Semantics
Immutable-Shared-Files Semantics
Under this system, when a file is declared as shared by its creator, it becomes immutable.
Operating System Concepts – 9th Edition 11.81 Silberschatz, Galvin and Gagne ©2013
Protection
Operating System Concepts – 9th Edition 11.82 Silberschatz, Galvin and Gagne ©2013
Access Lists and Groups
Mode of access: read, write, execute
Three classes of users on Unix / Linux
RWX
a) owner access 7 111
RWX
b) group access 6 110
RWX
c) public access 1 001
Ask manager to create a group (unique name), say G, and add some users to the
group.
For a particular file (say game) or subdirectory, define an appropriate access.
Operating System Concepts – 9th Edition 11.83 Silberschatz, Galvin and Gagne ©2013
Windows 7 Access-Control List Management
Operating System Concepts – 9th Edition 11.84 Silberschatz, Galvin and Gagne ©2013
A Sample UNIX Directory Listing
Operating System Concepts – 9th Edition 11.85 Silberschatz, Galvin and Gagne ©2013
Allocation Methods
Allocation method provides a way in which the disk will be utilized and the files will
be accessed.
1 .Contiguous Allocation
2. Non Contiguous Allocation
i. Linked Allocation
ii. Indexed Allocation`
Operating System Concepts – 9th Edition 11.86 Silberschatz, Galvin and Gagne ©2013
Contiguous Allocation
• If the blocks are allocated to the file in such a way that all the logical blocks of the
file get the contiguous physical block in the hard disk then such allocation
scheme is Known as 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.
Operating System Concepts – 9th Edition 11.87 Silberschatz, Galvin and Gagne ©2013
Contiguous Allocation
Operating System Concepts – 9th Edition 11.88 Silberschatz, Galvin and Gagne ©2013
Contiguous Allocation
Advantages
1.Both the Sequential and Direct Accesses are supported by this. For direct access, the
address of the kth block of the file which starts at block b can easily be obtained as (b+k).
2.It is simple to implement.
3.We will get Excellent read performance.
Disadvantages
1.This method suffers from both internal and external fragmentation. This makes it inefficient
in terms of memory utilization.
2.Increasing file size is difficult because it depends on the availability of contiguous memory
at a particular instance.
Operating System Concepts – 9th Edition 11.89 Silberschatz, Galvin and Gagne ©2013
Linked Allocation
Operating System Concepts – 9th Edition 11.90 Silberschatz, Galvin and Gagne ©2013
Linked Allocation
Advantages:
•This is very flexible in terms of file size. File size can be increased easily since the system
needed to access every block individually. This makes linked allocation slower.
•It does not support random or direct access. We can not directly access the blocks of a file. A
block k of a file can be accessed by traversing k blocks sequentially (sequential access ) from
the starting block of the file via block pointers.
•Pointers required in the linked allocation incur some extra overhead.
Operating System Concepts – 9th Edition 11.91 Silberschatz, Galvin and Gagne ©2013
Indexed Allocation
Operating System Concepts – 9th Edition 11.92 Silberschatz, Galvin and Gagne ©2013
Indexed Allocation
Advantages:
This supports direct access to the blocks occupied by the file and therefore provides
Disadvantages:
The pointer overhead for indexed allocation is greater than linked allocation.
Operating System Concepts – 9th Edition 11.93 Silberschatz, Galvin and Gagne ©2013
Inode (Index Node)
Operating System Concepts – 9th Edition 11.95 Silberschatz, Galvin and Gagne ©2013
Inode (Index Node)
Operating System Concepts – 9th Edition 11.96 Silberschatz, Galvin and Gagne ©2013
Inode (Index Node)
Inode
│
├── Direct Pointers (e.g., 0-11)
│ └── Data Blocks
│
├── Single Indirect Pointer
│ └── Block of Pointers to Data Blocks
│ └── Data Blocks
│
├── Double Indirect Pointer
│ └── Block of Pointers to Single Indirect Blocks
│ └── Block of Pointers to Data Blocks
│ └── Data Blocks
│
└── Triple Indirect Pointer
└── Block of Pointers to Double Indirect Blocks
└── Block of Pointers to Single Indirect Blocks
└── Block of Pointers to Data Blocks
└── Data Blocks
Operating System Concepts – 9th Edition 11.97 Silberschatz, Galvin and Gagne ©2013
Inode (Index Node)
The index node (inode) of a Unix-like file system has 12 direct, one
single-indirect and one double-indirect pointer The disk block size is
4 kB and the disk block addresses 32-bits long. The maximum
possible file size is (rounded off to 1 decimal place) __________ GB.
Operating System Concepts – 9th Edition 11.98 Silberschatz, Galvin and Gagne ©2013
Inode (Index Node)
Operating System Concepts – 9th Edition 11.99 Silberschatz, Galvin and Gagne ©2013
Inode (Index Node)
Operating System Concepts – 9th Edition 11.100 Silberschatz, Galvin and Gagne ©2013
End of Chapter 11
Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013