Operating System File Management: Structure, Implementation, and Operations

File System Structure Fundamentals

A file system is the component of the operating system (OS) that manages the creation, storage, organization, and access of files on storage devices (e.g., hard disks, SSDs, pen drives). The file system structure defines how files are arranged, how directories are organized, and how the OS locates and stores data.

Main Components of File System Structure

1. Files

A file is a collection of related information stored together—such as a text file, image, or video.

Each file is defined by several attributes:

  • Name
  • Type (extension)
  • Location (on disk)
  • Size
  • Permissions (read, write, execute)

2. Directories (Folders)

Directories help organize files. They can also contain other directories (called subdirectories), forming a tree-like structure.

3. File System Layers

LayerFunction
Application LayerPrograms (like Word, Notepad) interact with files.
Logical File SystemHandles metadata, file names, and access permissions.
File Organization ModuleManages directory and file structure.
Basic File SystemReads and writes physical blocks to the disk.
I/O Control LayerControls hardware devices and device drivers.
Physical LayerData is stored on hard disk sectors and tracks.

Directory Structures (Types)

  1. Single-level Directory: All files are stored in one directory. Simple, but inefficient for large systems.
  2. Two-level Directory: A separate directory is maintained for each user. Provides better organization.
  3. Tree-structured Directory: Features a main directory with subdirectories. Most commonly used (e.g., in Windows or Linux).
  4. Acyclic Graph Directory: Allows sharing of files and directories using links.

Advantages and Disadvantages of File Structure

Advantages

  • Easy to organize and search files.
  • Supports security and access control.
  • Allows file sharing and management.

Disadvantages

  • Corruption in the file system may affect the entire data set.
  • Complex file systems can be harder to manage manually.

File System Implementation Details

File system implementation refers to how the operating system physically stores files on the disk, tracks their location, and enables users to access or modify them. This involves all the internal structures and methods used to organize files and directories on storage devices (HDD, SSD, etc.).

Key Components in File System Implementation

1. File Control Block (FCB)

The FCB is a structure that stores critical information about a file, such as:

  • File name
  • File size
  • File location on disk
  • Access permissions

Each file in the system has its own unique FCB.

2. Directory Structure

Maintains a list of all files and their corresponding FCBs, aiding in file organization and fast searching.

3. Disk Block Allocation Methods

To store file data on the disk, the OS utilizes different allocation methods:

a) Contiguous Allocation
  • All file blocks are stored together in sequence.
  • Advantage: Fast access.
  • Disadvantage: External fragmentation is a problem.
b) Linked Allocation
  • Each block contains a pointer to the next block.
  • Advantage: No external fragmentation.
  • Disadvantage: Slow access, poor for random access.
c) Indexed Allocation
  • The OS creates an index block that stores the addresses of all file blocks.
  • Advantage: Fast random access.
  • Disadvantage: Requires extra space for the index block.

4. Free Space Management

The OS must track which blocks are free and available for storing new files. Common methods include:

  • Bit Map: Uses a bit array where 1 = used, 0 = free.
  • Free Block List: A list of available blocks.

5. I/O Control & Drivers

Handles communication with storage hardware and converts file system operations into device-specific instructions.

Implementation Flow Diagram

[ File Name ] → [ Directory Entry ] → [ File Control Block ]
                                                ↓
                                     [ Disk Block Addresses ]

Implementation Advantages and Disadvantages

Advantages

  • Organizes files efficiently.
  • Supports fast file access.
  • Helps in error detection and recovery.

Disadvantages

  • Complex design.
  • Corruption in the file system may cause data loss.

Essential File Operations

File operations are the actions that an operating system allows users or programs to perform on files. These operations are fundamental for creating, using, managing, and deleting files stored within the computer system.

Common File Operations

  1. Create: A new empty file is created. The OS allocates space and creates an entry in the directory. Example: Creating a new file notes.txt.
  2. Open: Used to access an existing file. The OS loads file information into memory and returns a file handle (ID). Example: Double-clicking a file to open it in MS Word.
  3. Read: Data is read from the file. The read pointer moves forward after reading. Example: Reading content from data.txt using a program.
  4. Write: Used to add or update content in a file. The write pointer moves forward after writing. Example: Writing marks into result.txt.
  5. Reposition (Seek): Moves the file pointer to a specific location in the file. This enables random access (reading/writing from a specific position). Example: Jumping to line 10 in a file to edit it.
  6. Close: Closes the file after use. This saves changes and releases memory resources. Example: Pressing “Save and Close” in Notepad.
  7. Delete: Removes a file from the directory and frees the allocated memory space. Example: Deleting a photo from your PC.

Other Useful File Operations

  • Rename: Changes the file name (e.g., abc.txt to marks.txt).
  • Copy: Duplicates the contents of one file into another.
  • Append: Adds data to the end of a file without removing the existing content.
  • Truncate: Removes all content from a file but keeps the file itself (zeroing out the size).

Types of Files in Operating Systems

A file is a collection of related data stored on a storage device. The operating system supports various file types depending on their use, format, and content.

Main Categories of Files

  1. Text Files:
    • Contain readable characters (letters, numbers, symbols).
    • Created by text editors like Notepad.
    • Extensions: .txt, .csv, .log. Example: notes.txt.
  2. Binary Files:
    • Contain non-readable data (0s and 1s).
    • Created by compilers or programs; more compact and faster to process than text files.
    • Extensions: .bin, .dat. Example: image.bin.
  3. Executable Files:
    • Files that contain machine code instructions and can be run (executed) by the computer.
    • Extensions: .exe, .bat, .com. Example: setup.exe.
  4. Source Code Files:
    • Contain programming code written by developers; must be compiled to run.
    • Extensions: .c, .cpp, .py, .java. Example: main.cpp.
  5. Object Files:
    • The output of a compiler; contains machine code but is not yet fully linked.
    • Extensions: .obj, .o. Example: module.o.
  6. Multimedia Files:
    • Used for audio, video, and images; handled by media players and editors.
    • Extensions: .mp3, .mp4, .jpg, .png. Example: song.mp3.

File Access Methods

Access TypeDescriptionExample
Sequential AccessData is accessed strictly in order, from beginning to end.Tape files
Direct AccessAllows jumping immediately to any specific location in the file.Executable files (.exe)
Indexed AccessUses an index structure to facilitate faster random access.Database Management Systems (DBMS) files