Contiguous Allocation
Contiguous Allocation
Contiguous Allocation
length of the first block. If the file is n blocks long, and starts at
The directory entry for each file indicates the address of the starting
block and the length of the area allocated for this file
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.
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.
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
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
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
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.
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.