Unit 4 - File Systems in Operating System
Unit 4 - File Systems in Operating System
The name of the file is divided into two parts as shown below:
• name
• Extension, separated by a period.
1. Continuous 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.
The file ‘mail’ in the following figure starts from the block 19 with length = 6
blocks. Therefore, it occupies 19, 20, 21, 22, 23, 24 blocks.
Advantages:
• 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).
• This is extremely fast since the number of seeks are minimal because of
contiguous allocation of file blocks.
Disadvantages:
• This method suffers from both internal and external fragmentation. This
makes it inefficient in terms of memory utilization.
• Increasing file size is difficult because it depends on the availability of
contiguous memory at a particular instance.
Advantages:
• This is very flexible in terms of file size. File size can be increased easily
since the system does not have to look for a contiguous chunk of
memory.
• This method does not suffer from external fragmentation. This makes it
relatively better in terms of memory utilization.
Disadvantages:
• Because the file blocks are distributed randomly on the disk, a large
number of seeks are needed to access every block individually. This
makes linked allocation slower.
• It does not support random or direct access. We cannot 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.
3. Indexed Allocation
In this scheme, a special block known as the Index block contains the
pointers to all the blocks occupied by a file. Each file has its own index block.
The ith entry in the index block contains the disk address of the ith file block.
The directory entry contains the address of the index block as shown in the
image:
Advantages:
• This supports direct access to the blocks occupied by the file and
therefore provides fast access to the file blocks.
• It overcomes the problem of external fragmentation.
Disadvantages:
• The pointer overhead for indexed allocation is greater than linked
allocation.
• For very small files, say files that expand only 2-3 blocks, the indexed
allocation would keep one entire block (index block) for the pointers which
is inefficient in terms of memory utilization. However, in linked allocation
we lose the space of only 1 pointer per block.
FILE DIRECTORIES
The single-level directory is the simplest directory structure. In it, all files
are contained in the same directory which makes 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 a unique name. If two
users call their dataset test, then the unique name rule violated.
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.
• Logical Organization: Directory structures help to logically organize files
and directories in a hierarchical structure. This provides an easy way to
navigate and manage files, making it easier for users to access the data
they need.
• Increased Efficiency: Directory structures can increase the efficiency of
the file system by reducing the time required to search for files. This is
because directory structures are optimized for fast file access, allowing
users to quickly locate the file they need.
• Improved Security: Directory structures can provide better security for
files by allowing access to be restricted at the directory level. This helps
to prevent unauthorized access to sensitive data and ensures that
important files are protected.
• Facilitates Backup and Recovery: Directory structures make it easier to
backup and recover files in the event of a system failure or data loss. By
storing related files in the same directory, it is easier to locate and backup
all the files that need to be protected.
• Scalability: Directory structures are scalable, making it easy to add new
directories and files as needed. This helps to accommodate growth in the
system and makes it easier to manage large amounts of data.
Disadvantages:
• There may chance of name collision because two files can have the same
name.
• Searching will become time taking if the directory is large.
• This cannot group the same type of files together.
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 their own user files
directory (UFD). The UFDs have similar structures, but each lists only the
files of a single user. System’s master file directory (MFD) is searched
whenever a new user id is created.
Advantages:
• The main advantage is there can be more than two files with same name,
and would be very helpful if there are multiple users.
• A security would be there which would prevent user to access other
user’s files.
• Searching of the files becomes very easy in this directory structure.
Disadvantages:
• As there is advantage of security, there is also disadvantage that the user
cannot share the file with the other users.
• Unlike the advantage users can create their own files, users don’t have
the ability to create subdirectories.
• Scalability is not possible because one use can’t group the same types of
files together.
Advantages:
• This directory structure allows subdirectories inside a directory.
• The searching is easier.
• File sorting of important and unimportant becomes easier.
• This directory is more scalable than the other two directory structures
explained.
Disadvantages:
• As the user isn’t allowed to access other user’s directory, this prevents
the file sharing among users.
• As the user has the capability to make subdirectories, if the number of
subdirectories increase the searching may become complicated.
• Users cannot modify the root directory data.
• If files do not fit in one, they might have to be fit into other directories.
Advantages:
• Sharing of files and directories is allowed between multiple users.
• Searching becomes too easy.
• Flexibility is increased as file sharing and editing access is there for
multiple users.
Disadvantages:
• Because of the complex structure it has, it is difficult to implement this
directory structure.
• The user must be very cautious to edit or even deletion of file as the file is
accessed by multiple users.
• If we need to delete the file, then we need to delete all the references of
the file in order to delete it permanently.
2. Direct Access –
Another method is direct access method also known as relative access
method. A fixed-length logical record that allows the program to read
and write record rapidly. in no particular order. The direct access is
based on the disk model of a file since disk allows random access to
any file block. For direct access, the file is viewed as a numbered
sequence of block or record. Thus, we may read block 14 then block
59, and then we can write block 17. There is no restriction on the order
of reading and writing for a direct access file.
A block number provided by the user to the operating system is
normally a relative block number, the first relative block of the file is 0
and then 1 and so on.
Disk Structure
The actual physical details of a modern hard disk may be quite complicated.
Simply, there are one or more surfaces, each of which contains several tracks,
each of which is divided into sectors.
There is one read/write head for every surface of the disk. Also, the same track
on all surfaces is known as a cylinder, when talking about movement of the
read/write head, the cylinder is a useful concept, because all the heads (one for
each surface), move in and out of the disk together.
We say that the “read/write head is at cylinder #2", when we mean that the
top read/write head is at track #2 of the top surface, the next head is at track
#2 of the next surface, the third head is at track #2 of the third surface, etc.
The unit of information transfer is the sector (though often whole tracks may
be read and written, depending on the hardware). As far as most file-systems
are concerned, though, the sectors are what matter. In fact, we usually talk
about a 'block device'. A block often corresponds to a sector, though it need
not do, several sectors may be aggregated to form a single logical block.