Contiguous Allocation

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Contiguous Allocation

The contiguous allocation method requires each file to occupy a set of

contiguous address on the disk.

Disk addresses define a linear ordering on the disk.

With this ordering, accessing block b+1 after block b normally

requires no head movement.

Contiguous allocation of a file is defined by the disk address and the

length of the first block. If the file is n blocks long, and starts at

location b, then it occupies blocks b, b+1, b+2, …, b+n-1.

The directory entry for each file indicates the address of the starting

block and the length of the area allocated for this file

Advantages of Contiguous File Allocation Method:

1.Supports both sequential and direct access methods.

2.Contiguous allocation is the best form of allocation for sequential files. Multiple blocks can be
brought in at a time to improve I/O performance for sequential processing.

3. It is also easy to retrieve a single block from a file. For example, if a file starts at block ‘n’ and the
ith block of the file is wanted, its location on secondary storage is simply n + i.

4. Reading all blocks belonging to each file is very fast.

5. Provides good performance.

Disadvantages of Contiguous File Allocation Method:

1. Suffers from external fragmentation.


2. Very difficult to find contiguous blocks of space for new files.

3. Also with pre-allocation, it is necessary to declare the size of the file at the time of creation which
many a times is difficult to estimate.

4. Compaction may be required and it can be very expensive.

linked Allocation:
 In this method, each file occupies disk blocks scattered anywhere on
the disk.
 It is a linked list of allocated blocks.
 When space has to be allocated to the file, any free block can be used
from the disk and system makes an entry in directory.
 Directory entry for allocated file contains file name, a pointer to the
first allocated block and last allocated block of the file.
 The file pointer is initialized to nil value to indicate empty file.
 A write to a file, causes search of free block.
 After getting free block data is written to the file and that block is linked
to the end of the file.
 To read the file, read blocks by following the pointers from block to
block starting with block address specified in the directory entry.
 For example, a file of five blocks starting with block 9 and continue with
block 16,then block 1,then block 10 an finally block 25.each allocated
block contains a pointer to the next block.

Indexed Allocation:
 In this method, each file has its own index block.
 This index block is an array of disk block addresses.
 When a file is created, an index block and other disk blocks according
to the file size are allocated to that file.
 Pointer to each allocated block is stored in the index block of that file.
 Directory entry contains file name and address of index block.
 When any block is allocated to the file, its address is updated in the
index block.
 Any free disk block can be allocated to the file. Each ith entry in the
index block points to the ith block of the file. To find and read the ith
block, we use the pointer in the ith index block entry

Explain single level directory structure.

It is the simplest form of directory system is having one directory containing all the files, and each

file must have a unique name. Sometimes it is called the root directory.

A single-level directory has significant limitations, however, when the number of files increases or

when there is more than one user.

Software design is simple.

Easy to support and understand. The advantages of this scheme are its simplicity and the ability to

locate files quickly - there is only one place to look, after all.

Since all files are in the same directory, they must have unique names. If there are two users who

call their data file "test", then the unique-name rule is violated. Even with a single-user, as the

number of files increases, it becomes difficult to remember the names of all the files in order to

create only files with unique names

Two-level directory:-
In the two level structures, each user has its own user file directory (UFD).the UFD lists only files of a
single user. System contains a master file directory (MFD) which is indexed by user name or account
number. Each entry in MFD points to the UFD for that user. When a user refers to a particular file,
only his own UFD is searched. Different users can have files with the same name, as long as all the
file names within each UFD are unique. When we create a file for a user, operating system searches
only that user"s UFD same name file already present in the directory. For deleting a file again
operating system checks the file name in the user" UFD only

Advantages:-
 It solves the problem of name-collision.
 It provides security to each user's data.
Sequential Access Method:

The simplest access method is sequential access. Information in the file is processed in order, one
record after the other. This mode of access is by far the beginning current position most common;
for example, editors and compilers usually access files in this fashion. Reads and writes make up the
bulk of the operations on a file. A read operation read next reads the next portion of the
file and automatically advances a file pointer, which tracks the I/O location. 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).

To read a piece of data that is stored at the end of the file, one has to read all of the data that comes
before it-you cannot jump directly to the desired data. This is similar to the way cassette tape
players work. If one wants to listen to the last song on a cassette tape, he has to either fast-forward
over all of the songs that come before it or listen to them. There is no way to jump directly to
a specific song.

Direct Access Method:


A file is made up of fixed-length logical records that allow programs to read and write records rapidly
in no particular order. 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. The direct-access
method is based on a disk model of a file, since disks allow random access to any file block. Direct
access files are of great use for immediate access to large amounts of information. Databases are
often of this type. For the direct-access method, the file operations must be modified to include the
block number as a parameter. The block number provided by the user to the OS is normally a
relative block number. A relative block number is an index relative to the beginning of the file. Thus,
the first relative block of the file is 0, the next is 1, and so on, even though the actual absolute disk
address of the block may be 14703 for the first block and 3192 for the second. The use of relative
block numbers allows the OS to decide where the file should be placed (called the allocation
problem) and helps to prevent the user from accessing portions of the file system that may
not be part of her file.
When you work with a direct access file (which is also known as a random access file), you can jump
directly to any piece of data in the file without reading the data that comes before it. This is similar
to the way a CD player or an MP3 player works. You can jump directly to any song that you want to
listen to. Sequential access files are easy to work with, and you can use them to gain
an understanding of basic file operations.

Definition of file: A file is named collection of related information that is recorded on secondary
storage. It is a sequence of bits, bytes, lines or records representing data. Data can be stored on
secondary storage only when it is place inside the file. File represents programs and data. Data
files may be numeric, alphabetic, alphanumeric or binary. Files are mapped by the operating
system onto physical devices.
Attributes of file
Name. It is a string of characters which is in human readable form.

Identifier. This unique tag, usually a number, identifies the file within the file system; it is the
non-human-readable name for the file.
Type. This is the information used by the system to support different types of the files.
Location. This information is a pointer to a device and to the location of the file on that device.
Size. The current size of the file (in bytes, words, or blocks) and possibly the maximum allowed
size are included in this attribute.
Protection. Access-control information determines who can do reading, writing, executing, and
so on.
Time, date, and user identification. This information may be kept for creation, last
modification, and last use.

You might also like