Table of contents
1.
Introduction
2.
Specifications of File systems
2.1.
Fragmentation in the File Systems
3.
Components of File Systems
3.1.
Directory
3.2.
Types of Directory     
3.3.
File System Allocation
3.4.
Free space management
4.
Frequently Asked Questions
4.1.
Why is a file system required?
4.2.
What is a bit vector?
4.3.
What is Flash memory?
5.
Conclusion
Last Updated: Mar 27, 2024

File Systems

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?
Operating Systems

Introduction

The file system keeps the essential aspect of an operating system. It provides the mechanism for online storage of and approach to both data and programs of the operating system and all the users of the computer system. It consists of two distinct parts: a collection of files, storing related data, and a directory structure, which arranges and provides information about all the files in the system.

Must Recommended Topic, Internal and External Fragmentation, Multiprogramming vs Multitasking"

Specifications of File systems

There are many organizational methods when designing a file system. It is appropriate to measure quantitative and qualitative parameters as design decisions. We can calculate the effectiveness of a file system by:- 

  • Maximizing the size of the file 
  • Maximizing the number of files
  • Determining the speed to read data at a random position in the file 
  • Speed to read data in a sequential fashion 
  • Rate of writing data into the files

Also see, UNIX File Systems

Fragmentation in the File Systems

We classify the fragmentation into two types:

  • Internal fragmentation: Internal fragmentation is storage allocated for the convenience of the operating system but contains no information. This space is wasted. This space is often wasted to improve speed or provide a more straightforward implementation. The fragmentation is called "internal" because the wasted storage is inside the allocated region. 
  • External fragmentation: External fragmentation exists when the most prominent memory block allocated is less than the total amount of free space in a heap. External fragmentation occurs in simple memory managers because memory is allocated in contiguous blocks. It happens over time as free storage becomes divided into many small pieces. It is a particular problem when an application gives and deallocates blocks of storage of varying sizes. Even though free storage is available, it is effectively not recommended since it is divided into two small parts to satisfy the application's demands. The term "external" refers to the fact that the unusable storage is outside the allocated regions.

 

You can also read about the Multilevel Feedback Queue Scheduling.

Components of File Systems

Directory

Directory structure

The file systems of computers can be substantial. Some designs have storage on terabytes of disk. We need to organize them to manage all these data.

  • Search for a file

     To find the presence of a  particular file, We need to search a directory structure.

  • Delete a file

     We want to discard files from the directory if it's no longer needed.

  • List a directory

     We have to arrange the files in a directory and the directory entry data for all.

  • Rename a file 
    Since the name of a file represents its contents to its users, we must be able to change the title when the contents or use of the file changes. 
  • Traverse the file system:
    In the directory structure for accessing every directory and file in and for reliability, it becomes essential to store the data and design of the entire file system at regular intervals.

Types of Directory     

  • Single-Level Directory

The files are in the same directory to make it more straightforward, supportive, and understandable. However, a single-level guide has significant limitations when the number of files increases or the system has more than one user. They must have unique names because of multiple files in the same directory.

Illustration Image

 

  • Two-Level Directory

Each user has their user file directory (UFD) in the two-level directory. The UFD's have similar structures, but each lists only the files of a single user. When a user job starts or logs in, the system's master file directory, MFD, is searched. The indexing of the MFD is done by user name or account number, and each entry points to the UFD for that user. Only her own UFD is searched when a user refers to a particular file. Therefore, different users may have files with the same name, as long as all the file names within each UFD are unique.

Illustration Image

  

  • Tree-Structured Directories:

A directory (or subdirectory) has a list of files or subdirectories. A directory is usually another file, but it is treated uniquely. All directories have the same internal format. Each directory entry exhibits a file (0) or a subdirectory (1).

Illustration Image

Also see, Structures of Directory

File System Allocation

  • Contiguous allocation 

The contiguous-allocation method needed for each file to contain a set of continuous blocks over the container and Disk addresses states a linear arrangement on the disk. With this ordering, realize that only one job is accessing the disk; accessing block b + 1 after block b typically requires no head movement. It is easy to access a file that has been allocated contiguously. For continuous access, the file system remembers the disk address of the last block referenced and, when required, accesses the next container. We can immediately access block b + 1 for direct access to the block of a file that starts at block b. Thus, both continuous and immediate entry can be supported by contiguous allocation. The below figure shows the Contiguous allocation of disk space. One difficulty with a contiguous allocation is finding space for a new file.

Illustration Image
  • Linked allocation

All the problems of contiguous allocation are quickly resolved by Linked allocation. Here every file is a linked list of disk blocks, and the disk blocks may be distributed on the disk randomly—the directory stores a pointer to the first and last blocks of the file. For example, a file of 6 blocks might start at block 10, continue at block 17, then block 2, block 11, and finally block 26. Each block stores a pointer to the succeeding block. The user cant access these pointers. Thus, if each block is 512 bytes, and a disk address requires 4 bytes, the user sees blocks of 508 bytes.

Illustration Image

One difficulty with a contiguous allocation is finding space for a new file. The linked allocation has no external fragmentation, and any free block on the unoccupied space list can be used to satisfy a request. The major problem with a linked allocation is that it can be used for sequential-access data. We must start at the beginning and follow the pointers until we get to the ith block to find a file's ith block.

  • Indexed allocation

Indexed allocation solves the problem of linked allocation by bringing all the pointers together into one location: the index block. Each file has its index block, an array of disk block addresses. The directory stores the location of the index block. For reading the ith block, we use the pointer in the ith index block entry to find and read the desired block. We set all pointers in the index block to null when creating the file. When we write the ith block, a block is obtained from the free-space manager, and its address is put in the ith index-block entry.

Illustration Image

Several index files may be linked together to allow for large files. The linked representation uses a first-level index block to point to a set of second-level index blocks, which point to the file blocks. To retrieve a block, the operating system uses the first-level index to find a second-level index block and that block to find the required data container. This method could be continued to a third or fourth level depending on the desired maximum file size.

Free space management

As the disk space is limited, we need to reuse the space from deleted files for new files, if possible. The system maintains a free-space list to keep track of free disk space—the free-space list stores all free disk blocks not occupied to particular files or directories. For creating a file, we search the free-space inventory for the required space and give that space to the new file. Now we can remove the spaces from the free-space container. When a file is removed, its disk space is added to the free-space list. The free space list, despite its name, might not be implemented as a list, as we shall discuss. 

Illustration Image

When a file requests a sector, it is unlinked from the free space and linked to the file. When we delete the file, all sectors are connected to the free space again.

You can also read about the Multilevel Queue Scheduling.

Frequently Asked Questions

Why is a file system required?

Every time you open a file on your computer or smart device, your operating system uses its file system internally to load it from the storage device. The most important use of a file system is to operate user information which involves primary operations like storing, retrieving, and updating the data.

What is a bit vector?

Frequently, we implement the free-space list as a bit map or bit vector, where we represent each block by 1 bit. If the block is vacant, the bit is 1; if the block is occupied, the bit is 0. For example, consider a disk that contains the blocks as 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 17, 18,25, 26, 27 are vacant, and the remaining blocks are occupied. The free-space bit map would be 001111001111110001100000011100000...The main benefits of this method are its relative simplicity and efficiency in finding the first free block or consecutive free blocks on the disk.

What is Flash memory?

Flash memory is also known as electronically removable programmable read-only memory (EEPROM) because which piece of code like programming can be written and erased electrically.
There are two types of Flash memory: volatile and Non-volatile.
When memory loses its data when power is removed and restored, it is known as volatile, while in Nonvolatile, it sustains its data when power is removed and restored.

Conclusion

In this article, we learned about File system management. We elaborated on the specifications and fragmentation of the file systems and their types, i.e., internal and external fragmentation. We also briefly discussed the different types of components in the File systems. We explained the directory structure and its various types, i.e., Single-Level Directory, Two-Level Directory, and Tree-Structured Directories. We discussed the file system allocations with their different types, i.e., contiguous allocation, linked allocation, indexed allocation, and at last, we discussed the free space management in the file systems.

Recommended Reading:

Do check out The Interview guide for Product Based Companies as well as some of the Popular Interview Problems from Top companies like Amazon, Adobe, Google, Uber, Microsoft, etc. on Coding Ninjas Studio.

Also check out some of the Guided Paths on topics such as Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, DBMS, System Design, etc. as well as some Contests, Test Series, Interview Bundles, and some Interview Experiences curated by top Industry Experts only on Coding Ninjas Studio.

Cheers!

Live masterclass