File System in OS: File Concept, Organization, Access Methods & Directories

OPERATING SYSTEM - CHAPTER 30

File System in OS: File Concept, Organization, Access Methods & Directories

Whenever you save a photo, create a document, install an application, download a PDF or open a folder, the operating system must know where that data is stored and how to find it again.

The part of an Operating System that manages files, directories, names, locations, permissions and storage organization is called the File System.

Quick Answer:

A File System is the method used by an operating system to create, store, organize, locate, access, protect and manage files on storage devices.

A file is a named collection of related data.
Files can be accessed using Sequential Access, Direct Access and Indexed Access.
Directories organize files into structures such as Single-Level, Two-Level, Tree-Structured, Acyclic-Graph and General-Graph directories.

Why Do We Need a File System?

File System in OS: File Concept, Organization, Access Methods & Directories

A storage device contains a huge number of bytes. Without a file system, those bytes would simply look like a large collection of raw storage blocks.

The operating system needs a proper structure so that users can say:

Open notes.pdf

instead of saying:

Go to storage block 48520, read the next 64 blocks, combine them and show my document.

The file system hides this low-level complexity.

IDENTIFICATION Naming Files get meaningful names.
STORAGE Organization Data is arranged into files and folders.
SECURITY Protection Users receive controlled access.
LOCATION Mapping Logical files are mapped to physical storage blocks.

Simple File System View

File Explorer
Documents
Downloads
Pictures
Videos
Projects
OS Notes
assignment.pdf
marks.xlsx
program.c

What Is a File System in Operating System?

Definition:
A File System is the operating-system mechanism used to organize, store, name, locate, access, protect and manage files and directories on secondary storage.

Common storage devices include:

  • Hard Disk Drives
  • SSDs
  • USB drives
  • Memory cards
  • Optical media

What Is a File?

A file is a named collection of related information stored on secondary storage.

The operating system treats the file as one logical unit.

A file may contain:

  • Text
  • Program code
  • Images
  • Audio
  • Video
  • Database records
  • Executable instructions

Logical File vs Physical Storage

When a user opens:

User View
Documents/Operating-System/file-system-notes.pdf

The user sees one normal file.

But internally, the operating system may store that file in one or many storage blocks.

User sees → File Name

Operating System sees → Metadata + Directory Entry + Storage Blocks

File Attributes in Operating System

A file contains data, but the operating system also stores information about the file.

This information is called File Metadata or file attributes.

notes.pdf

Example File

Name notes.pdf
Identifier Unique internal file identifier
Type PDF document
Location Pointer to storage information
Size File length
Protection Read / Write / Execute permissions
Time & Date Created / Modified / Accessed
Owner User or account associated with file

File Operations in Operating System

The operating system provides several operations that programs can perform on files.

COMMON FILE OPERATIONS
1 Create Make a new file and directory entry.
2 Open Prepare an existing file for use.
3 Read Transfer file data into memory.
4 Write Store new information in a file.
5 Reposition Change current file position.
6 Close Finish using the open file.
7 Delete Remove file entry and release storage.
8 Truncate Remove file contents while keeping the file entry.

What Happens When a File Is Opened?

  1. Program requests the file by name or path.
  2. Operating system searches the directory.
  3. File permissions are checked.
  4. File metadata is located.
  5. Information about the open file is placed in an open-file table.
  6. The process receives a file descriptor or file handle.
  7. Future read or write operations use that open-file reference.
In Unix-like systems, a process commonly refers to an open file using a file descriptor.

Types of Files in Operating System

TYPE Regular File Text, executable, image, program data and similar content.
TYPE Directory File Stores information used to organize names of files and subdirectories.
TYPE Device File Represents devices in some operating systems.
TYPE Special File Pipes, sockets, links and other OS-specific objects may appear as file-like objects.

What Is a File Extension?

A file extension is a suffix added after the file name.

File Extension Common Meaning
notes.txt .txt Text file
report.pdf .pdf PDF document
photo.jpg .jpg Image
program.c .c C source file
app.exe .exe Windows executable
Extensions are useful, but operating systems do not all depend on extensions in exactly the same way.

File Structure

A file can be viewed in different logical forms.

STRUCTURE 1 Byte Sequence File is simply a sequence of bytes. Many modern general-purpose operating systems provide this simple model.
STRUCTURE 2 Record Sequence File consists of logical records. This idea is common in database and record-processing concepts.
STRUCTURE 3 Complex Structured File Applications can interpret bytes as images, documents, executables or other structured formats.

File Access Methods in Operating System

File Access Method means: How does a program reach the required data inside a file?

METHOD 1

Sequential Access

Records or bytes are processed one after another in order.

Best idea: Start → Next → Next → Next
METHOD 2

Direct Access

Program can move directly to a required position or block.

Best idea: Jump directly to needed location.
METHOD 3

Indexed Access

An index helps locate the required record or block.

Best idea: Search index → find location.

1. Sequential Access Method

Sequential access reads or writes data in a fixed order.

Sequential Reading
1
2
3
4
5
6

To reach Record 5, the program usually processes the earlier records in sequence.

Sequential access is simple and useful for:

Text processing
Log files
Audio/video streams
Batch processing

2. Direct or Random Access Method

Direct access allows a program to move directly to a particular block, byte offset or record location.

Direct Access Example
1
2
3
4
5
6
Need Record 5?

Direct Access → Go directly to Record 5.

Direct access is useful for applications where information must be reached quickly, such as databases and large random-access files.

3. Indexed Access Method

Indexed access maintains an index containing keys or entries that point to the location of data.

Indexed Access
Key A → 4
Key B → 9
Key C → 15
Search Key → Index → Data Location → Record

Sequential vs Direct vs Indexed Access

Basis Sequential Direct Indexed
Access Pattern One after another Jump directly to location Use index to locate data
Speed for Random Record Usually slower Fast Fast when index is efficient
Extra Structure Minimal Requires addressable positions Requires index
Example Log file Database file block Indexed database record

What Is a Directory in Operating System?

A directory is a special file-system structure used to organize file names and references to files or subdirectories.

A directory helps users arrange data logically.

Example Directory Tree
Root
├── Documents
│ ├── notes.pdf
│ └── assignment.docx
├── Pictures
│ └── photo.jpg
└── Projects
    └── OS
       └── filesystem.html

Common Directory Operations

  • Search for a file
  • Create a file
  • Delete a file
  • List directory contents
  • Rename a file
  • Create a subdirectory
  • Delete a directory
  • Traverse the file system

Types of Directory Structures

TYPE 1 Single-Level Directory All files are stored in one common directory.
TYPE 2 Two-Level Directory Each user can have a separate directory.
TYPE 3 Tree-Structured Directory Directories can contain files and subdirectories.
TYPE 4 Acyclic-Graph Directory Sharing is possible without cycles.
TYPE 5 General-Graph Directory Links may create cycles.

Single-Level Directory

All files exist inside one directory.

Directory
├── a.txt
├── b.txt
├── photo.jpg
└── program.c
Advantage: very simple.
Problems:

File-name conflicts
Poor organization
Difficult for many users

Two-Level Directory

Every user has a separate user directory.

Master Directory
├── User A
│ ├── notes.txt
│ └── photo.jpg
└── User B
    ├── notes.txt
    └── data.csv
Different users can have files with the same name because the files exist inside different user directories.

Tree-Structured Directory

Tree structure is one of the most common directory models.

It has a root directory at the top. Every directory can contain files and more subdirectories.

Root → Folder → Subfolder → File
Advantages:

Good organization
Easy grouping
Supports hierarchical paths
Easy navigation

Acyclic-Graph Directory

An acyclic-graph directory allows a file or subdirectory to be shared by more than one directory.

However, cycles are not allowed.

Two users may reference the same shared file.

The system must carefully manage links and deletion.

General-Graph Directory

General-graph directories allow links that may create cycles.

For example:

Folder A → Folder B → Folder C → Folder A
Cycles make traversal and deletion more difficult. The operating system may need cycle detection or garbage-collection-like techniques.

Path Names in File System

A path describes where a file or directory is located.

Absolute Path

An absolute path starts from the root of the file system.

Unix-like Example
/home/student/Documents/os-notes.pdf
Windows Example
C:\Users\Student\Documents\os-notes.pdf

Relative Path

A relative path is interpreted from the current working directory.

Documents/os-notes.pdf

Current Working Directory

The current working directory is the directory from which relative paths are interpreted.

Current Directory:
/home/student

Relative Path:
Documents/report.pdf

Final Location:
/home/student/Documents/report.pdf

Links in File Systems

Some file systems allow multiple names or references to point to the same file.

Link Type Main Idea
Hard Link Another directory entry referring to the same underlying file object in supported file systems.
Symbolic Link A separate file-like object that stores a path to another file or directory.
Exact link behaviour depends on the operating system and file system.

What Is File Organization?

File organization describes how information is logically arranged and physically placed so that it can be stored and accessed efficiently.

Two important views are:

VIEW 1 Logical Organization Files, records, directories, names and paths.
VIEW 2 Physical Organization How file blocks are placed on the storage device.

File Allocation Methods

File allocation tells the operating system how the blocks belonging to a file are placed on storage.

Contiguous Allocation File blocks are stored next to each other.
20 21 22 23
Linked Allocation Each block points to the next block.
7 31 14 52
Indexed Allocation An index block stores addresses of the file's data blocks.
Index 8 26 41

Contiguous Allocation

In contiguous allocation, all blocks of a file are placed in consecutive storage locations.

File A:

Block 20 → 21 → 22 → 23
Advantages:

Simple
Fast sequential access
Fast direct access
Problems can include:

External fragmentation
Difficulty growing a file when the next blocks are already occupied

Linked Allocation

In linked allocation, file blocks can exist anywhere on the disk. Each block contains a link to the next block.

Block 7 → Block 31 → Block 14 → Block 52
Advantages:

No need for contiguous free space
Easy file growth
Disadvantages:

Poor direct access
Pointer overhead
Damage to a pointer can affect the chain

File Allocation Table (FAT) Idea

FAT improves the linked-allocation idea by keeping block-link information in a table.

Block Next Block
7 31
31 14
14 52
52 EOF

Indexed Allocation

Indexed allocation gives each file an index structure containing addresses of its data blocks.

Index Block:

8
26
41
67

These entries point to file data blocks.
Indexed allocation supports direct access without requiring all file blocks to be contiguous.
The index itself uses storage space.

What Is an Inode?

In Unix-like file systems, an inode stores metadata about a file and information needed to locate its data.

Simplified inode idea:

File Type
Permissions
Owner
Size
Timestamps
Data Block References
The file name is normally stored in the directory entry, while the inode stores the underlying file metadata.

Free-Space Management

The operating system must know which disk blocks are free and which blocks are already in use.

This is called Free-Space Management.

METHOD 1 Bit Map / Bit Vector Each block is represented using a bit showing free or allocated status.
METHOD 2 Free List Free blocks are connected or listed together.
METHOD 3 Grouping / Counting Free-space information is stored in grouped or counted form.

Bitmap Example

Suppose:

1 = Free 0 = Allocated Bitmap: 0 0 1 0 1 1 0 1

In this example, Blocks 2, 4, 5 and 7 are marked free, if indexing begins from Block 0.

What Is File System Mounting?

Mounting means attaching a file system to the operating system's directory structure so that its files become accessible.

Storage Device → File System → Mount Point → Accessible Files

In Unix-like systems, a file system may be mounted at a directory such as:

/mnt/usb

Partition vs File System

Basis Partition File System
Meaning Logical division of a storage device Method used to organize files within storage
Purpose Separate storage regions Manage files and directories
Example Disk partition NTFS, ext4, FAT32

Examples of File Systems

File System Common Association General Note
NTFS Windows Supports permissions, journaling and large files.
FAT32 USB / compatibility Simple and widely supported, but has important size limitations.
exFAT Flash storage Designed for large files and removable media compatibility.
ext4 Linux Widely used journaling file system.
APFS Apple platforms Modern Apple file system.

What Is Journaling in a File System?

Journaling helps a file system recover more reliably from unexpected shutdowns or crashes.

Before certain metadata changes are fully committed, information about the intended changes may be recorded in a journal.

SIMPLIFIED JOURNALING IDEA
1 Planned Change OS prepares metadata update.
2 Journal Entry Change information is recorded.
3 Main Update File-system structures are updated.
4 Recovery Journal helps restore consistency after failure.
Exact journaling behaviour depends on the file system.

File Protection in Operating System

Not every user should be allowed to perform every operation on every file.

PERMISSION Read View file contents.
PERMISSION Write Modify file contents.
PERMISSION Execute Run a file as a program when applicable.
CONTROL Ownership File access can depend on user and group identity.

Access Control List (ACL)

An Access Control List stores information about which users or groups are allowed to perform specific operations on a file or directory.

User Read Write Execute
Owner Yes Yes Yes
Student Group Yes No No
Others No No No

File Sharing

Modern operating systems may allow multiple users or processes to access the same file.

The file system must handle:

  • Permissions
  • Concurrent access
  • File locking
  • Sharing rules
  • Consistency

What Is File Locking?

File locking helps coordinate access when multiple processes want to use the same file.

Process A is writing.

Process B may need to wait, depending on the locking mechanism.

Locks may apply to the entire file or only a region of a file.

File System Layers in Operating System

File management can be understood as a set of layers.

Application Programs
Logical File System
File-Organization Module
Basic File System
I/O Control
Storage Device Hardware

How File System Layers Work

1. Logical File System

Manages file names, directories, metadata, protection and logical file operations.

2. File-Organization Module

Maps logical file blocks to physical storage blocks and manages allocation.

3. Basic File System

Sends general block read/write requests.

4. I/O Control

Uses device drivers and interrupt handling to communicate with storage hardware.

What Happens When You Read a File?

FILE READ PIPELINE
1 Application Requests a file.
2 Directory Search OS resolves path and name.
3 Metadata File information and block references are located.
4 Storage Request Required blocks are requested.
5 Device Driver Driver communicates with storage hardware.
6 Data Loaded Data reaches memory.
7 Application Receives Data Program processes file contents.

Simple Path Builder

Use this small example to understand absolute and relative paths.

File Path Learning Tool

Common Student Confusions

File vs Directory

A file mainly stores data. A directory organizes names and references to files and subdirectories.

File System vs File

A file is one data object. A file system is the complete method used to manage many files and directories.

Sequential Access vs Sequential Allocation

These are different concepts.

Sequential Access = How data is read.

Contiguous Allocation = How file blocks are placed on storage.

Directory vs Folder

In everyday usage, folder is the graphical user-interface term commonly used for a directory.

Absolute Path vs Relative Path

Absolute path begins from a root or drive. Relative path starts from the current working directory.

File Extension vs File Type

An extension is part of the file name. Actual file type may also depend on internal format and operating-system interpretation.

Advantages of a File System

  • Easy storage organization
  • Meaningful file names
  • Directory-based grouping
  • Access control and permissions
  • Efficient storage allocation
  • Free-space tracking
  • File sharing
  • Data persistence after program termination
  • Recovery support in modern journaling file systems

Quick File System Comparison Table

Concept Meaning
File Named collection of related information
Directory Structure used to organize files and subdirectories
Metadata Information about a file
Sequential Access Read data in order
Direct Access Jump directly to a required location
Indexed Access Use an index to locate data
Contiguous Allocation File blocks are consecutive
Linked Allocation Each block links to the next
Indexed Allocation Index stores block addresses
Mounting Attach a file system to the directory namespace

One-Minute File System Revision

File System Organizes and manages files on storage.
File Named collection of related information.
Metadata Name, size, permissions, timestamps, owner and location information.
Sequential Access Read in order.
Direct Access Jump to required position.
Indexed Access Index helps locate records.
Directory Organizes files and subdirectories.
Absolute Path Full path from root or drive.
Relative Path Path from current directory.
Contiguous Allocation Consecutive blocks.
Linked Allocation Blocks linked together.
Indexed Allocation Index contains block references.

File System in OS Exam Preparation

2-Mark File Definition

A file is a named collection of related information stored on secondary storage.

2-Mark File System Definition

A File System is the operating-system mechanism used to organize, store, access and manage files and directories on storage devices.

File Attributes

Name, identifier, type, location, size, protection, owner, timestamps.

File Operations

Create, open, read, write, reposition, close, delete and truncate.

Access Methods

Sequential Access, Direct Access and Indexed Access.

Directory Structures

Single-Level, Two-Level, Tree-Structured, Acyclic-Graph and General-Graph directory.

Allocation Methods

Contiguous Allocation, Linked Allocation and Indexed Allocation.

For a 5-Mark Answer

  1. Define file and file system.
  2. Explain file attributes.
  3. Explain file operations.
  4. Explain access methods.
  5. Mention directory structure.

For a 10-Mark Answer

  1. Define File System.
  2. Explain need of File System.
  3. Define file.
  4. File attributes.
  5. File operations.
  6. File types.
  7. Sequential, Direct and Indexed access.
  8. Directory definition.
  9. Directory operations.
  10. Single-Level Directory.
  11. Two-Level Directory.
  12. Tree-Structured Directory.
  13. Acyclic and General Graph directories.
  14. Absolute and Relative paths.
  15. File Allocation Methods.
  16. Free-Space Management.
  17. File Protection.
  18. File-System Layers.

Frequently Asked Questions

What is a File System in Operating System?

A File System is the operating-system mechanism used to organize, store, locate, access, protect and manage files and directories on storage devices.

What is a file in OS?

A file is a named collection of related information stored on secondary storage.

What are file attributes?

File attributes include information such as name, identifier, file type, location, size, owner, permissions and timestamps.

What are the common file operations?

Common file operations include create, open, read, write, reposition, close, delete and truncate.

What are the main file access methods?

The main access methods are Sequential Access, Direct Access and Indexed Access.

What is Sequential Access?

Sequential Access processes data in order from one record or byte sequence to the next.

What is Direct Access?

Direct Access allows a program to move directly to a required record, block or byte position.

What is Indexed Access?

Indexed Access uses an index to locate the required record or data block.

What is a directory?

A directory is a file-system structure used to organize file names and references to files and subdirectories.

What is a Tree-Structured Directory?

A Tree-Structured Directory has a root directory and allows directories to contain files and subdirectories.

What is an absolute path?

An absolute path gives the complete location of a file starting from the root directory or storage drive.

What is a relative path?

A relative path specifies a location starting from the current working directory.

What are the file allocation methods?

The classic file allocation methods are Contiguous Allocation, Linked Allocation and Indexed Allocation.

What is an inode?

An inode is a Unix-like file-system structure that stores file metadata and information used to locate file data blocks.

What is file-system mounting?

Mounting means attaching a file system to a directory location so that its files can be accessed.

What is journaling in a file system?

Journaling records information about file-system changes so the system can recover more reliably after crashes or unexpected shutdowns.

Conclusion

The File System is one of the most important parts of an Operating System.

It converts raw storage blocks into a structure that users can understand as files, folders and paths.

A file is a named collection of related information. File attributes store metadata such as size, location, permissions and timestamps.

The operating system provides operations such as create, open, read, write, close, delete and truncate.

Files can be accessed using Sequential, Direct or Indexed access.

Directories organize files using structures such as Single-Level, Two-Level, Tree, Acyclic-Graph and General-Graph directories.

Internally, files are stored using allocation methods such as Contiguous, Linked and Indexed allocation.

Final Memory Trick:

File = Data

Directory = Organization

Metadata = Information About File

Sequential Access = One by One

Direct Access = Jump Directly

Indexed Access = Use Index

Absolute Path = Full Path

Relative Path = From Current Directory

Contiguous Allocation = Consecutive Blocks

Linked Allocation = Block-to-Block Links

Indexed Allocation = Index Stores Block Addresses

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Join Telegram Exam updates and free resources