Practice
Data Structures and Algorithms
Machine Coding Round (LLD)
System Design & Architecture (HLD)
Frontend UI Machine Coding
Resources
Career Advice and Roadmaps
Data Structures and Algorithms
Machine Coding Round (LLD)
System Design & Architecture (HLD)
Backend Development
Frontend Development
Project Ideas for Software Developers
Core Computer Science
Companies
SDE Jobs & Internships
Interview Questions
Compare Companies
IDE
Online IDE
Collaborative IDE

File Systems in Operating System (OS) | Core Computer Science

Ujjwal Abhishek
Ujjwal Abhishek

What is File System?

The File System is a method or data structure that helps in storing the data or files in the system so that it can be fetched easily when required. The files can be stored without the File System but it would be very difficult to fetch the correct file when required. 

The File System stores all the information or properties about a file logically which helps in fetching the required data efficiently.

What is a File?

A collection of related information and data under a single name is called a File. There may be different types of files that store different types of information. All the information stored in a system is stored in a file. Examples of different types of files are Text Files, Program Files, etc.

File Attributes 

The information about a particular file is called File Attributes. It is also called the properties of a File.

There are various attributes of a file like

  1. Name - It is the name of the file according to the stored data for identification.
  2. Extension - It denotes the type of data stored in a file. Like .txt extension is used for Text Files.
  3. Size - It is the size of that file.
  4. Location - It shows the location of the file where it is stored in the system.
  5. Date - It shows when the last changes were done in the file.
  6. Protection - It shows who has permission to access a particular file.

File Directories

The File Directory is itself a file that contains information about the files. The File directory is the collection of files. It contains a lot of information about the files like name, type, location, protection, etc.

Different types of operations can be performed on a File Directory.

  1. Create a File
  2. Search a File
  3. Delete a File
  4. Rename a File

There are various types of File Directories.

  1. Single Level Directory
  2. Two Level Directory
  3. Tree-Structured Directory

Allocation of Files

Files are allocated or stored in disks in different ways. The different methods of File Allocation are explained below.

Contiguous Allocation - In the Contiguous Allocation method, the blocks of files are stored in a contiguous manner in the disk. This means by knowing about the starting block's location of the file and the location of any other block of the file can be predicted because they all are allocated contiguously. 

Advantages of Contiguous Allocation.
  • This is simple to implement.
  • The retrieval of any block is easy.
Disadvantages of Contiguous Allocation.
  • External Fragmentation occurs.
  • The size of the file should be known before allocation.

Linked List Allocation - In the Linked List Allocation method, it is not necessary to store the blocks of files in a contiguous manner. The first block stores the pointer to the second block and the second block to the third and similarly thereafter. It is not necessary to predefine the size of a file in this method. It also removes external fragmentation as blocks can be stored at random positions.

Advantages of Linked List Allocation.
  • It removes external fragmentation.
  • The File Size can be increased anytime.
Disadvantages of Linked List Allocation.
  • The blocks of files can be accessed only in a sequential manner.
  • Internal Fragmentation Occurs.

Indexed File Allocation - In this method, the addresses of all blocks of a file are stored in a separate block. All the blocks of a file are accessed using the data stored in the index block. It also removes the problem of external fragmentation as blocks can be stored at non-contiguous positions. Any block can be accessed directly in this method, unlike Linked List Allocation.

Advantages of Indexed Allocation.
  • It removes external fragmentation.
  • Data can be accessed directly.
Disadvantages of Indexed Allocation.
  • There can be multilevel indexing which makes it a little complex.

 

Ujjwal Abhishek
Ujjwal Abhishek
Ujjwal is final-year CSE Undergraduate, a competitive coder, and a web developer passionate about problem-solving and data structures and algorithms.
SDE Bootcamp - Become a software engineer at a product-based company
Practice Data Structures & Algorithms
Learning Resources
Interview Prep Resources
Blog
  • Career Advice and Roadmaps
  • Data Structures & Algorithms
  • Machine Coding Round (LLD)
  • System Design & Architecture
  • Backend Development
  • Frontend Development
  • Awesome Project Ideas
  • Core Computer Science
Practice Questions
  • Machine Coding (LLD) Questions
  • System Design (HLD) Questions
  • Topic-wise DSA Questions
  • Company-wise DSA Questions
  • DSA Sheets (Curated Lists)
  • JavaScript Interview Questions
  • Frontend UI Machine Coding Questions
Online Compilers (IDE)
  • Online Java Compiler
  • Online C++ Compiler
  • Online C Compiler
  • Online Python Compiler
  • Online JavaScript Compiler
Topic-wise Problems
  • Dynamic Programming Interview Questions
  • Linked List Interview Questions
  • Graph Interview Questions
  • Backtracking Interview Questions
  • Arrays Interview Questions
  • Trees Interview Questions
Company-wise Problems
  • Amazon Interview Questions
  • Microsoft Interview Questions
  • Google Interview Questions
  • Flipkart Interview Questions
  • Adobe Interview Questions
  • Facebook Interview Questions
DSA Sheets (Curated Lists)
  • Top Interview Questions
  • FAANG Interview Questions
  • Most Asked Interview Questions
  • 6 month DSA Practice Sheet
  • 3 month DSA Practice Sheet
  • Last minute DSA Practice Sheet