This project implements a simple user-space file system simulator in C. It mimics the behavior of a real file system, including mounting disks, creating files and directories, reading/writing data, and managing storage space. The file system operates on a virtual 128KB disk file.
- Flat File System Structure: Supports up to 126 files/directories.
- Directory Hierarchy: Supports nested directories.
- File Operations: Create, delete, read, write.
- Defragmentation: Includes a utility to defragment the disk and consolidate free space.
- Consistency Checks: Validates filesystem integrity upon mounting.
Use the provided Makefile to compile the project:
makeThis produces the fs executable.
To clean up build artifacts:
make cleanBefore running the simulator, you need a virtual disk. Use the create_fs utility:
./create_fs <disk_name>Example:
./create_fs disk0The simulator reads commands from an input file.
./fs <command_file>Where <command_file> is a text file containing a list of filesystem commands (see below).
The input file should contain one command per line. Arguments are space-separated.
| Command | Syntax | Description |
|---|---|---|
| Mount | M <disk_name> |
Mounts the specified virtual disk. Must be the first operation. |
| Create | C <name> <size> |
Creates a file or directory. <size> denotes the number of blocks (0 for directory). |
| Delete | D <name> |
Deletes a file or directory in the current working directory. |
| Read | R <name> <block_index> |
Reads the specified block of a file into the internal buffer. |
| Write | W <name> <block_index> |
Writes the content of the internal buffer to the specified block of a file. |
| Buffer | B <string> |
Loads <string> into the internal buffer. |
| List | L |
Lists files and directories in the current directory (matches ls -la style). |
| Defrag | O |
Optimizes/Defragments the disk to consolidate free blocks. |
| Change Dir | Y <name> |
Changes the current working directory. Use .. for parent. |
M disk0
C dir1 0
Y dir1
C file1 2
B HelloWorld
W file1 0
L
- Disk Size: 128 KB (128 blocks * 1024 bytes).
- Block Size: 1024 bytes.
- Superblock: Occupies Block 0. Contains the free block bitmap and inode table.
- Inode Table: Capacity for 126 inodes.
- Addressing: Uses a simple contiguous allocation logic (or linked list depending on specific implementation nuances).
- Constraints:
- Filenames are limited to 5 characters.
- Maximum of 127 blocks addressable.
A Python test script test.py was used to run integration tests against expected outputs.
To run the tests:
python3 test.pyThis script executes the test cases located in the tests/ directory.
The simulator prints error messages to stderr for various conditions, such as:
- Command syntax errors
- Filesystem inconsistency errors (during mount)
- File not found / Disk full errors