This project is an in-depth simulation of the Ext2 filesystem, meticulously crafted in C. It's designed to mimic essential filesystem functionalities such as creating, reading, writing, deleting files and directories, alongside advanced operations like linking and symbolic linking of files. This simulator serves as an excellent resource for understanding the underlying mechanisms of filesystems in a Unix/Linux environment, focusing on inode and block management through a user-space implementation.
- File Operations: Comprehensive support for file operations including creation, deletion, reading, and writing.
- Directory Management: Functionalities to create, delete, navigate, and list directories, providing a hands-on experience with directory hierarchy management.
- Symbolic and Hard Links: Implements both symbolic and hard linking of files, offering insights into file sharing and inode usage.
- Path Resolution: Efficient resolution of both absolute and relative paths, enabling intricate filesystem navigation.
- Virtual Disk Storage: Utilizes a virtual disk for storage operations, simulating real-world filesystem behavior with block allocation and deallocation.
- Inode Management: Detailed simulation of inode operations, including allocation, deallocation, and manipulation, to closely understand file metadata handling.
- Basic Commands: Implements fundamental Unix commands such as
ls,cd,mkdir,rmdir,creat, andrmfor file and directory operations. - Utility Functions: A rich set of utility functions in
util.cfor block I/O, inode management, directory searches, and path resolution. - Linking Functionalities: Features in
link_unlink.candsymlink.cfor creating and managing hard links and symbolic links, enriching the filesystem simulation with advanced file operations.
- Defines various data types and structures used across the filesystem code, including
MINODE,PROC,MTABLE,OFT, along with the standard EXT2 FS structures likeINODE,GD(group descriptor),SUPER(superblock), etc. MINODErepresents an in-memory inode,PROCrepresents a process,MTABLErepresents a mount table, andOFTrepresents an open file table entry.
- Provide utility functions such as
get_block(),put_block(),tokenize(),iget(),iput(),search(),getino(), and more. These are fundamental operations for block I/O, inode management, directory search, and path resolution.
- Implement the
cd,ls, andpwdcommands. Functions likecd()change the current working directory,ls()lists directory contents, andpwd()prints the current working directory path.
- Handle directory creation and file creation with functions like
make_dir(),mymkdir(),creat_file(), andmycreat().
- Implement directory and file removal functionalities with functions such as
rm_dir()andrm_child().
- Serves as the entry point for the filesystem application. It initializes the system and processes commands from the user.
- At startup,
main.ccallsmount_root()to load the root inode into memory usingiget()fromutil.c.
- For filesystem commands entered by the user,
main.cparses these commands and calls the appropriate functions fromcd_ls_pwd.c,mkdir_creat.c, orrmdir_rm.c. For example, if the user enters thecdcommand,main.cinvokescd()fromcd_ls_pwd.c.
- When creating a directory,
make_dir()inmkdir_creat.cuses several utility functions fromutil.c, such asiget()to load inodes into memory,iput()to release inodes, andgetino()to find the inode number of a given path.
- Functions like
cd(),ls(), andrm_dir()rely ongetino()fromutil.cto resolve paths to inode numbers. They also useiget()andiput()for managing in-memory inodes.
This overview captures the essence of how functions and data structures are defined and utilized across your filesystem implementation. Each .c file typically includes its corresponding .h file for function prototypes and global variable declarations, ensuring modularity and reusability of code.