What is a file system in OS?

In any operating system, the file system decides how to store the content in the storage medium like primary or secondary memory. Every file system is different in terms of its implementation or use cases, but it's essential for the efficient functioning of any operating system.

File system

The file system is the pre-defined feature provided by the OS that decides how to organize the whole content of storage mediums. The storage medium can be:

  • Secondary memory (hard drive)

  • Main memory (RAM, ROM)

  • Any external drive

The content of the storage medium can be any file or directory. The file system formats the content, and it helps to separate the data into smaller segments. Let's look at the illustration below:

A basic preview of thr file storage system

Note: The file system also provides a way to store file-related data such as its name, extension or permission type, and many more.

File structure

Before we learn the file structure, it's important to know the file first.

File

A file is the smallest component file system and collection of related data stored on a storage medium. We can also call it a logical unit of information. Also, the file is a minor component of the secondary storage. When a file is created, a name is assigned to it. And when this process is terminated file remains accessible to other processes. The file name is divided into the following two parts:

Filename segmentation

Types of files

This is the ability of any OS to distinguish between different types of files, for example, source files, binary files, text files, and so on. Generally, OS has the following types of files:

Character special file

This file contains the data about hardware. This file reads or writes the data character by characters from I/O devices like keyboards, mouse, printers, and more.

Ordinary files

These are general files that store user information, maybe text, databases, or executable files, and users can perform different operations on them like modifying, etc. Some sub-categories of ordinary files are as follows:

  • Media: It stores media data like images, audio, video, and many more.

  • Programs: It stores code, commands, and scripts and is an executable file.

  • Operating system level: These files store OS-relevant data for its use.

  • Document: These are used to manage office programs like documents, spreadsheets, and so on.

  • Miscellaneous: All other generic files except the one mentioned above, like canvas files and so on.

Ordinary file of type pdf

Directory files

The directory files contain the information related to all other files. It's like a folder that holds and organizes multiple files and points the path to every file.

Special files

The special files are also known as device files. These files record the information about physical devices like disks, networks, drives, and many more.

File access mechanism

It's a method to access and read the files from memory. Most OS support single access methods, whereas others also support multiple access methods. The Three file access methods are as follows:

  • Sequential access: We can access the records in a specific pre-defined sequence. Information stored in files is also accessed one by one.

  • Direct random access: We can access the record directly without following any order. Each record can be directly accessed through its address to read or write it.

  • Index sequential access: It's like simple sequential access, where an index is built for every file with a pointer directly pointing to different memory blocks. We can access the file through a pointer, where its index is searched sequentially.

File directories

The single file directory can contain multiple files, but they must all be stored in a single directory. It can also have sub-directories inside the parent directory to point to various files.

Example of single level directory

Note: File directory maintained information like name, location, size, file type, etc.

Space allocation mechanism

As files are stored in the storage mediums, they always require the allocation of disk spaces. The OS provides the following three methods of space allocation:

  • Linked allocation

  • Indexed allocation

  • Contiguous allocation

Linked allocation

The linked allocation is a complex type of allocation, where every file includes a list of links. The file directory contains the pointer to the file in the first block of the file. Linked access is not ideal for direct random access but widely used with sequential access.

Note: In this allocation, there's no external fragmentationExternal fragmentation happens when a dynamic memory allocation method allocates some memory but leaves a small amount of memory unusable..

Indexed allocation

In indexed allocation, OS maintained a set of pointers in an index table. This index table is stored in multiple index blocks. In each index block, every entry holds the disk address of the respective file block.

Contiguous allocation

In contiguous allocation, every file takes a set of consecutive addresses on the storage medium. Each entry from the directory contains the total number of blocks, the starting address of the first block, and the filename. If the file size is expandable during writing, the extra space is left, or the file is copied elsewhere, leaving no additional space behind.

Free Resources

HowDev By Educative. Copyright ©2025 Educative, Inc. All rights reserved