Skip to content

Shan533/C-File-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

C++ File System Implementation

A complete implementation of a simple, Unix-like file system on a simulated disk.

πŸš€ Features

βœ… Fully Implemented Commands

  • mkdir <directory> - Create empty subdirectory
  • ls - List directory contents (directories show with /)
  • cd <directory> - Change to specified subdirectory
  • home - Switch to root directory
  • rmdir <directory> - Remove empty subdirectory
  • create <filename> - Create empty file
  • append <filename> <data> - Append data to file
  • stat <name> - Display file/directory statistics
  • cat <filename> - Print file contents
  • tail <filename> <n> - Print last n bytes of file
  • rm <filename> - Remove file

πŸ”§ Advanced Features

  • Multi-block file support - Files can span multiple 128-byte blocks
  • Smart block allocation - Fills last block before allocating new ones
  • Data persistence - File system state persists across sessions
  • Comprehensive error handling - All required error messages implemented
  • Efficient resource management - Proper cleanup and block reclamation

πŸ—οΈ Architecture

The project follows a layered architecture:

Shell (CLI) β†’ FileSys (Commands) β†’ BasicFileSys (Low-level) β†’ Disk (Storage)

Block Structure

  • Block Size: 128 bytes
  • Total Blocks: 1,024 (0-1023)
  • Block Types:
    • Block 0: Superblock (bitmap)
    • Block 1: Root directory
    • Other blocks: Dynamic allocation

Data Structures

  • Directory Block: Magic number + entry count + name/block pairs
  • Inode Block: Magic number + file size + data block pointers
  • Data Block: Raw file data (128 bytes)

πŸ“‹ Requirements

  • Compiler: C++ compatible compiler (g++, clang++)
  • Make: GNU Make
  • Platform: Linux/Unix

πŸš€ Quick Start

1. Clone the Repository

git clone https://github.com/Shan533/C-File-System.git
cd C-File-System

2. Navigate to Source Directory

cd "file system skeleton code"

3. Build the Project

make

4. Run the File System

# Interactive mode
./filesys

# Script mode
./filesys -s test_script.txt

πŸ“– Usage Examples

Basic Operations

# Create and navigate directories
mkdir testdir
cd testdir
ls
home

# Create and manipulate files
create myfile
append myfile "Hello, World!"
cat myfile
stat myfile
tail myfile 5

# Clean up
rm myfile
cd ..
rmdir testdir

Multi-block File Example

# Create a large file that spans multiple blocks
create bigfile
append bigfile "This is a long string that will exceed 128 bytes and require multiple blocks to store properly in our file system implementation."
stat bigfile
cat bigfile

πŸ§ͺ Testing

The project includes comprehensive test scripts:

  • test_script.txt - Basic functionality test
  • test_large_files.txt - Multi-block file testing
  • test_edge_cases.txt - Edge case testing
  • test_persistence1.txt - Persistence testing
  • test_newline.txt - Special character handling

Run Tests

# Run basic test
./filesys -s test_script.txt

# Run large file test
./filesys -s test_large_files.txt

# Run edge case test
./filesys -s test_edge_cases.txt

About

πŸ—‚οΈ Unix-like file system implementation in C++ with 21 commands, multi-block file support, and CLI interface. Features core operations plus advanced commands like find, tree, cp, mv, and help system.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors