Welcome to the File System Project! We encourage you to try using the
loadcommand in the cli.cpp to load thedisk.binfile located in thedatadirectory. We have prepared some surprises for you!
This project implements a simple file system on top of a simulated I/O system. The file system supports basic operations such as creating, destroying, opening, closing, reading, writing files, and listing the directory contents. The I/O system simulates a disk using an array of logical blocks.
- File Operations: Create, destroy, open, close, read, write, seek.
- Directory Management: List all files in the directory.
- Disk Simulation: Simulate disk operations with logical blocks.
- Bitmap Management: Manage block allocation and deallocation using a bitmap.
- File Descriptor Management: Handle file descriptors for files and directories.
.
├── data
| └── disk.bin
├── include
│ ├── BitmapManager.h
│ ├── DirectoryOperator.h
│ ├── Disk.h
│ ├── FdManager.h
│ ├── FileOperator.h
│ ├── FileSystem.h
│ └── OpenFileTable.h
├── src
│ ├── BitmapManager.cpp
│ ├── DirectoryOperator.cpp
│ ├── Disk.cpp
│ ├── FdManager.cpp
│ ├── FileOperator.cpp
│ ├── FileSystem.cpp
│ └── OpenFileTable.cpp
├── example
│ ├── test.cpp
│ └── cli.cpp
├── CMakeLists.txt
├── build.sh
└── README.md
- C++20 compiler
- CMake 3.10 or higher
- Make
-
Run the build script:
./build.sh [Release|Debug]The default build type is
Release. You can specifyDebugto build the project in debug mode. -
The executables will be located in the
build/bindirectory.
This example runs a predefined set of file system operations to demonstrate the functionality.
./build/bin/testThis example provides an interactive command-line interface for the file system. You can enter commands to perform various file system operations.
./build/bin/cliIn the CLI example, the following commands are supported:
help: Show the list of commands.create <filename>: Create a new file.destroy <filename>: Destroy a file.open <filename>: Open a file.close <file_id>: Close a file.write <file_id> <data>: Write data to a file.read <file_id> <count>: Read data from a file.lseek <file_id> <position>: Seek to a position in a file.directory: List all files.exit: Exit the program.
File System CLI. Type 'help' for a list of commands.
> help
Commands:
help : Show this help message
format : Format the disk
load : Load disk content
dump : Dump disk content
create <filename> : Create a new file
destroy <filename> : Destroy a file
open <filename> : Open a file
close <file_id> : Close a file
write <file_id> <data> : Write data to a file
read <file_id> <count> : Read data from a file
lseek <file_id> <position> : Seek to a position in a file
directory : List all files
exit : Exit the program
> create myfile.txt
File created: myfile.txt
> open myfile.txt
File opened: myfile.txt with id 0
> write 0 Hello, World!
Bytes written: 13
> lseek 0 0
Seeked to position 0 in file with id 0
> read 0 13
Bytes read: 13
Data read: Hello, World!
> close 0
File closed with id 0
> directory
File myfile.txt 13 bytes
> destroy myfile.txt
File destroyed: myfile.txt
> directory
Directory is empty
> exit- Disk.h and Disk.cpp: Simulates the disk with an array of logical blocks. Provides methods to read and write blocks.
- BitmapManager.h and BitmapManager.cpp: Manages block allocation and deallocation using a bitmap. Reads and writes the bitmap to the disk.
- FdManager.h and FdManager.cpp: Manages file descriptors for files and directories. Allocates and frees file descriptors.
- DirectoryOperator.h and DirectoryOperator.cpp: Manages directory entries. Provides methods to create, delete, find, and list directory entries.
- FileOperator.h and FileOperator.cpp: Manages file operations such as reading, writing, and seeking within a file. Handles loading and saving file blocks.
- OpenFileTable.h and OpenFileTable.cpp: Manages the table of open files. Provides methods to open, close, read, write, and seek files.
- FileSystem.h and FileSystem.cpp: Main interface for the file system. Implements high-level file operations and manages the overall file system state.
- test.cpp: Contains a set of predefined file system operations to demonstrate the functionality.
- cli.cpp: Provides a command-line interface to interact with the file system.
- Inspired by educational projects and file system examples.