This GitHub repository is an implementation of a virtual file system, the ext2 file system in the xv6 operating system, forked from https://github.com/mit-pdos/xv6-public.
The goal is to provide a basic understanding of file system concepts and demonstrate how to integrate a file system into an existing operating system.
The Virtual File System (VFS) is an abstraction layer that provides a unified interface for file system operations in an operating system. It allows applications and system components to interact with various file systems without being aware of the underlying implementation details.
VFS enables the operating system to support multiple file systems simultaneously. This flexibility allows users to choose different file systems based on their specific needs, such as performance, reliability, or special features.
VFS provides a standardized interface for operations like file creation, deletion, opening, reading, and writing. It also handles directory operations, such as creating, removing, and listing directories.
The Extended File System 2 (ext2) is a widely used file system in Linux systems. It was introduced as an improvement over the original ext file system, providing enhanced performance, reliability, and support for larger file systems.
Some key features of the ext2 file system include:
Inode-based Structure: The ext2 file system organizes files and directories using inodes. Each file or directory is represented by an inode, which stores metadata like permissions, timestamps, and pointers to data blocks.
Block Grouping: The file system divides the disk into block groups, with each group containing a set of inodes and data blocks. This grouping improves performance by reducing disk seek times.
Hierarchical Directory Structure: The ext2 file system supports a hierarchical directory structure, allowing files and directories to be organized in a tree-like format.
File and Directory Permissions: Permissions in ext2 determine the access rights for users and groups, enabling fine-grained control over file system security.
Journaling: While the original ext2 file system did not include journaling, later versions (ext3 and ext4) introduced journaling capabilities to enhance data consistency in the event of system crashes or power failures.
The ext2 file system provides a reliable and efficient solution for storing and managing files in Linux-based operating systems. Its design principles and features have influenced subsequent file systems, making it an essential component of the Linux ecosystem.
The xv6 operating system, based on the Sixth Edition of Unix, is a simple educational operating system. Integrating the ext2 file system into xv6 involves implementing the ext2 file system operations, modifying the file system interface, system calls, and user commands.
The integration process requires mapping the concepts and structures of the ext2 file system to the appropriate components in xv6. This includes managing disk blocks, inodes, directory entries, file permissions, and implementing operations like file creation, deletion, opening, reading, and writing.
Implementing ext2 in xv6 enables users to experiment with file system operations, explore the interactions between the file system and the rest of the operating system, and gain a deeper understanding of how file systems impact overall system performance and functionality.
To get started with the xv6-ext2 project, follow these steps:
git clone https://github.com/TanmayPatil105/xv6-ext2
mkdir /tmp/1
Now build the xv6 os by using the following command
make clean qemu
If it asks for a sudo password while building, provide it with your sudo password! :)
Read test (also done using recursive directory traversal)
cat /mnt/file1
cat /mnt/dir1/dir2/dir3/file
This commands prints the already mounted files from /etc/passwd
Explore xv6: Run the modified xv6 operating system with the above command. Test the file system operations and verify their correctness. by running the ext2fstest
ext2.img:
dd if=/dev/zero of=ext2.img count=20000
mkfs.ext2 -b 1024 ext2.img
We will be mounting our ext2 image virtually on /mnt
directory. Every recursive call reaching /mnt
will be redirected to the ext2 FS functions.
Added disk driver code to detect ext2 image disk.
struct inode_operations {
int (*dirlink)(struct inode*, char*, uint);
struct inode* (*dirlookup)(struct inode*, char*, uint*);
struct inode* (*ialloc)(uint, short);
void (*iinit)(int dev);
void (*ilock)(struct inode*);
void (*iput)(struct inode*);
void (*iunlock)(struct inode*);
void (*iunlockput)(struct inode*);
void (*iupdate)(struct inode*);
int (*readi)(struct inode*, char*, uint, uint);
void (*stati)(struct inode*, struct stat*);
int (*writei)(struct inode*, char*, uint, uint);
};
struct inode {
uint dev; // Device number
uint inum; // Inode number
int ref; // Reference count
struct sleeplock lock; // protects everything below here
int valid; // inode has been read from disk?
+ struct inode_operations *iops; // pointer to inode_operations
short type; // copy of disk inode
short major;
short minor;
short nlink;
uint size;
void *addrs;
};
Added ext2 file system manipulating functions