Assignment 08: File Systems: Allocation and Organization

I. Objective & Theoretical Framework

A file is a logical entity that divides data into meaningful groups, but as a physical entity, it must be carefully organized and allocated on a storage disk. The term “file organization” refers to the way data is stored and the methods by which it can be accessed.

In this laboratory, you will simulate two critical aspects of file system design:

1. File Allocation Strategies:

2. Directory Organization Techniques:

II. Prerequisite Knowledge & Resources

III. Starter Code & Partial Implementations

The following skeleton code provides a clean data structure for simulating Sequential File Allocation. You can expand upon this basic array-of-structures model to handle Two-Level directories.

#include <stdio.h>
#include <string.h>

// Structure to simulate a file entry in a directory table
struct fileTable {
    char name[20];
    int start_block; // Used for Sequential Allocation
    int num_blocks;  // Length of the file in blocks
} ft[30];

int main() {
    int i, j, n;
    char search_name[20];

    printf("Enter number of files to allocate: ");
    scanf("%d", &n);

    for(i = 0; i < n; i++) {
        printf("\nEnter file %d name: ", i + 1);
        scanf("%s", ft[i].name);
        printf("Enter starting block of file %d: ", i + 1);
        scanf("%d", &ft[i].start_block);
        printf("Enter number of blocks in file %d: ", i + 1);
        scanf("%d", &ft[i].num_blocks);
    }

    printf("\nEnter the file name to be searched: ");
    scanf("%s", search_name);

    // [Insert Linear Search Logic using strcmp() here]

    // [Insert Output Logic: Print File Name, Start Block, and all occupied blocks]

    return 0;
}

IV. Step-by-Step Task List

  1. Allocation Simulation: Complete the starter code to simulate Sequential Allocation. Next, create separate C programs to simulate Linked and Indexed allocation. For Linked Allocation, use a struct containing a block number and a next pointer. For Indexed Allocation, use an array within your file table struct to store the specific blocks.

  2. Single & Two-Level Directories: Write a program with a switch menu to simulate a Single-Level Directory allowing users to Create, Delete, and Search for files. Expand this into a new program for a Two-Level Directory by upgrading your struct to include an array of directories, each containing its own array of files.

  3. Hierarchical Directory Structure: Simulate a Tree directory structure. Create a node struct that contains a character array for the name, a flag indicating if it is a file or a directory, and an array of pointers linking to its children (subdirectories or files).

V. Common Pitfalls & Debugging Strategies

VI. Real-World Case Study

These exact allocation strategies form the backbone of the file systems you use daily. The FAT32 file system (commonly used on USB flash drives) is a highly optimized version of Linked Allocation, utilizing a File Allocation Table to link clusters together. The ext4 file system (the default for most Linux distributions) and NTFS (Windows) utilize highly advanced versions of Indexed Allocation using structures called “inodes” and “Master File Tables” respectively, combined with hierarchical B-Trees to ensure extremely fast file retrieval even with millions of stored files.

VII. Advanced Variant Tasks


VIII. Resources & Further Reading

SDB Watermark