Skip to content

Cipherxzc/BJTU-OS-Filesystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

File System Project

Welcome to the File System Project! We encourage you to try using the load command in the cli.cpp to load the disk.bin file located in the data directory. We have prepared some surprises for you!

Overview

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.

Features

  • 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.

Directory Structure

.
├── 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

Getting Started

Prerequisites

  • C++20 compiler
  • CMake 3.10 or higher
  • Make

Building the Project

  1. Run the build script:

    ./build.sh [Release|Debug]

    The default build type is Release. You can specify Debug to build the project in debug mode.

  2. The executables will be located in the build/bin directory.

Running the Examples

Test Example

This example runs a predefined set of file system operations to demonstrate the functionality.

./build/bin/test

CLI Example

This example provides an interactive command-line interface for the file system. You can enter commands to perform various file system operations.

./build/bin/cli

Commands

In 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.

Example Usage

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

Source Code Overview

Disk

  • Disk.h and Disk.cpp: Simulates the disk with an array of logical blocks. Provides methods to read and write blocks.

BitmapManager

  • BitmapManager.h and BitmapManager.cpp: Manages block allocation and deallocation using a bitmap. Reads and writes the bitmap to the disk.

FdManager

  • FdManager.h and FdManager.cpp: Manages file descriptors for files and directories. Allocates and frees file descriptors.

DirectoryOperator

  • DirectoryOperator.h and DirectoryOperator.cpp: Manages directory entries. Provides methods to create, delete, find, and list directory entries.

FileOperator

  • FileOperator.h and FileOperator.cpp: Manages file operations such as reading, writing, and seeking within a file. Handles loading and saving file blocks.

OpenFileTable

  • OpenFileTable.h and OpenFileTable.cpp: Manages the table of open files. Provides methods to open, close, read, write, and seek files.

FileSystem

  • FileSystem.h and FileSystem.cpp: Main interface for the file system. Implements high-level file operations and manages the overall file system state.

Example Programs

  • 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.

Acknowledgments

  • Inspired by educational projects and file system examples.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors