Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FAT File System — In-Memory Simulator

A from-scratch C++ implementation of a FAT (File Allocation Table) file system running entirely in shared memory. The project simulates a 64 MB virtual disk with 1 KB blocks and exposes a Unix-like shell (foosh) for navigating directories, copying files between the host and virtual disk, and inspecting metadata — all without touching real disk I/O.

Built as part of an Operating Systems course at IIT Kharagpur. See Problem Statement.pdf for the original specification.

Architecture

The system is split into three layers:

  • foosh.cpp — Interactive shell (REPL) supporting cd, ls, mkdir, cp, prn
  • diskutils.hpp / diskutils.cpp — Core FAT, bitmap, and directory logic, path resolution, three-way file copy (host→VD, VD→host, VD→VD)
  • diskmanager.cpp — Creates and destroys the 64 MB SysV shared memory segment

Virtual disk layout (65,536 blocks × 1 KB):

Region Blocks Purpose
Superblock 0 Total blocks, free count, root dir pointer
Bitmap 1–8 One bit per block (free/allocated)
FAT 9–264 Linked-list chain pointers (4 bytes/block)
Data 265+ Root directory starts at block 265

Each directory entry is a packed 32-byte metadata struct: 1-byte type flag, 23-byte name, 4-byte size, 4-byte first-block pointer.

Building & Running

Prerequisites: Linux with SysV shared memory support, g++ with C++17.

make                       # builds diskmanager and foosh

./diskmanager -create      # allocate & format the 64 MB virtual disk in SHM
./foosh                    # launch the shell

# inside foosh:
md docs                   # create a directory
cp `README.md docs        # copy host file → virtual disk (backtick = host path)
ls docs                   # list directory contents
prn docs/README.md        # print file contents
cp docs/README.md `out.md # copy virtual disk → host
exit

./diskmanager -remove      # free the shared memory segment

Shell Commands

Command Description
cd <path> Change directory (supports ., .., absolute & relative paths)
md <path> Create a new directory
ls [path] Detailed listing (type, name, size, first block)
dir Names-only listing of current directory
cp <src> <dst> Copy file — prefix with ` for host paths
prn <file> Print file contents to stdout
exit Quit the shell

Key Concepts

  • FAT data structure — block chaining via a file allocation table, the same scheme behind FAT12/16/32
  • Bitmap block allocation — free-block tracking with a bit vector and randomized allocation
  • SysV shared memory IPC — persistent in-memory disk image across process invocations using shmget/shmat/shmdt
  • Path resolution — recursive traversal of absolute/relative paths through chained directory blocks
  • Packed structs & raw memory — direct memcpy serialization with #pragma pack, no abstraction layers

License

MIT

About

In-memory FAT file system simulator with a Unix-like shell, built in C++ using SysV shared memory

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages