This project simulates a file system using fundamental data structures like linked lists, queues, and arrays, modeling how real-world operating systems manage file storage using Linked File Allocation. This system mimics storing and retrieving file data block-by-block from a simulated hard drive and with a simple terminal interface and no folder hierarchy (just one giant "flat" directory).
stupidOS (the dummy operating system) needs a basic file system to manage file data using linked data blocks. Each file is split into blocks and the location of these blocks is tracked using a custom LinkedList class. Free memory blocks are managed by a Queue. Files are added, removed, or read through a FileManager class that handles all internal logic and memory simulation.
- A generic singly linked list class to store data elements like integers (for file block locations) or custom objects (
File). - Supports sorted insertions to maintain file names in alphabetical order.
- A templated queue structure for managing free memory blocks (indexes of available space in the hard drive array).
- Implements typical
enqueue,dequeue,isEmpty, andfrontoperations.
- Represents a single file.
- Stores:
Filename: stringindexList:LinkedList<int>of indexes on the hard drive where characters are stored.
- Key methods:
addBlock(index)fileSize()getFileBlocks()
- Simulates the file system and manages:
- The
hardDrive(a dynamic character array) blocksAvailable(Queue of free block indexes)files(LinkedList ofFileobjects sorted by filename)
- The
- Core functionalities:
addFile(name, contents)deleteFile(name)readFile(name)getFileNames()findFileByName(name)(helper function)
+-------------------------------+
| FileManager |
+-------------------------------+
| - hardDrive: char* |
| - blocksAvailable: Queue<int> |
| - files: LinkedList<File> |
+-------------------------------+
| | ^
| v |
| +-------------------+ |
+---> | File |----+
+-------------------+
| - Filename |
| - indexList: |
| LinkedList<int> |
+-------------------+
Queue<int> stores free blocks
LinkedList<File> keeps all files sorted
When a user adds a file, the FileManager:
- Pulls free block indexes from
Queue. - Stores characters at these indexes in
hardDrive. - Creates a
Fileobject and adds it tofiles.
To read or delete a file:
- The linked list of block indexes is used to reconstruct or free the file data.
.
├── LinkedList_srinivasgowda.hpp # Custom Linked List implementation
├── Queue_srinivasgowda.hpp # Custom Queue for free block tracking
├── FileSystem_srinivasgowda.h # Class declarations for File and FileManager
├── FileSystem_srinivasgowda.cpp # Method definitions for File and FileManager
├── stupidOS_srinivasgowda.exe # Compiled executable (for Windows)
├── Makefile # Compiles all source files into 'stupidos'
Compile the program using the provided Makefile:
makeRun with the following options:
-
Set hard drive size
./stupidos -s 200
-
Load initial files from a file
./stupidos -s 200 -f init.txt
1 – Show files on hard drive
2 – Add a file
3 – Delete a file
4 – Output a file
0 – Exit simulation
Each character of file content occupies one block on the simulated hard drive. The block indexes are maintained in a linked list for each file.
- Data Abstraction: Files are abstracted using classes and encapsulated block indexes.
- Dynamic Memory Management: Avoids contiguous storage constraints.
- Linked File Allocation: Mimics how many file systems manage non-contiguous data.
- Templated Programming: Reusable generic structures (
LinkedList,Queue).