Skip to content

BoapSoap/FileSystem

Repository files navigation

Basic File System — Custom C Implementation

Overview

This project is a custom-built file system implemented in C, designed to simulate core operating system–level file management functionality. The system operates on a virtual volume file and implements low-level block-based storage using Logical Block Addressing (LBA).

The file system supports directory structures, file operations, free space management, buffering, and persistent storage — all built from scratch in a Linux environment.


System Design Goals

  • Block-based storage abstraction
  • Custom free space allocation and release management
  • Directory hierarchy management
  • Persistent file metadata tracking
  • Buffered read/write operations
  • Emulation of Unix-like file and directory interfaces

Technical Architecture

Volume & Block Management

  • Volume size: configurable (500,000 – 10,000,000 bytes)
  • Block size: 512 bytes per sector
  • LBA-based read/write operations
  • Persistent storage maintained within a virtual volume file

Low-level I/O operations are handled through:

uint64_t LBAwrite (void * buffer, uint64_t lbaCount, uint64_t lbaPosition);
uint64_t LBAread  (void * buffer, uint64_t lbaCount, uint64_t lbaPosition);

These functions operate directly on block-level storage, requiring explicit buffer management and block calculations.


Free Space Management

  • Tracks available and allocated blocks
  • Handles allocation during file creation and write operations
  • Releases space during file deletion
  • Ensures consistency between directory entries and storage layout

Directory System

  • Hierarchical directory structure
  • Root directory initialization during volume formatting
  • Custom directory entry tracking
  • Support for directory iteration and traversal

Supported directory interfaces:

int fs_mkdir(const char *pathname, mode_t mode);
int fs_rmdir(const char *pathname);
fdDir * fs_opendir(const char *pathname);
struct fs_diriteminfo *fs_readdir(fdDir *dirp);
int fs_closedir(fdDir *dirp);

char * fs_getcwd(char *pathbuffer, size_t size);
int fs_setcwd(char * pathname);
int fs_isFile(char * filename);
int fs_isDir(char * pathname);
int fs_delete(char* filename);

File Operations

The system implements custom file descriptors and file positioning logic.

b_io_fd b_open (char * filename, int flags);
int b_read (b_io_fd fd, char * buffer, int count);
int b_write (b_io_fd fd, char * buffer, int count);
int b_seek (b_io_fd fd, off_t offset, int whence);
int b_close (b_io_fd fd);

Supported flags:

  • O_CREAT
  • O_TRUNC
  • O_APPEND
  • O_RDONLY
  • O_WRONLY
  • O_RDWR

File metadata includes size tracking, block allocation mapping, and timestamp management.


File Metadata (Stat Interface)

int fs_stat(const char *filename, struct fs_stat *buf);

Tracked attributes include:

  • File size (bytes)
  • Block size
  • Allocated blocks
  • Access time
  • Modification time
  • Creation time

Shell Interface

A custom interactive shell (fsshell.c) is included to demonstrate file system functionality.

Supported commands:

  • ls — List directory contents
  • cp — Copy files within the file system
  • mv — Move files
  • md — Create directory
  • rm — Remove file or directory
  • touch — Create file
  • cat — Display file contents
  • cp2l — Copy from custom file system to Linux file system
  • cp2fs — Copy from Linux file system into custom file system
  • cd — Change directory
  • pwd — Print working directory
  • history — Show command history

Build Instructions

This project is built using make.

make

To run the interactive shell:

make run

The system must be executed in a Linux environment.


Engineering Challenges

  • Designing block allocation without fragmentation corruption
  • Mapping file logical offsets to physical LBA blocks
  • Maintaining directory consistency during file deletion
  • Managing file seek operations with custom descriptors
  • Implementing buffered read/write logic over raw block storage
  • Handling persistent metadata updates safely

What This Project Demonstrates

  • Low-level systems programming in C
  • File system architecture design
  • Block-level storage abstraction
  • Manual memory management
  • OS-style file and directory interfaces
  • Persistent data structure design
  • Multi-phase systems implementation

Future Improvements

  • Journaling for crash recovery
  • Defragmentation logic
  • Permission management system
  • Indirect block expansion
  • Improved caching strategy
  • Performance benchmarking

Environment

  • Language: C
  • Platform: Ubuntu Linux
  • Block size: 512 bytes
  • Volume size: configurable up to 10MB

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors