From d3cf3f08d1343d6b265516d5a79ce2d197b59d26 Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Sun, 4 Jan 2026 14:05:49 +0800 Subject: feat(file-system): implement read and write FAT32 File System and basic shell --- include/fs/fat32.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'include/fs/fat32.h') diff --git a/include/fs/fat32.h b/include/fs/fat32.h index c794bd7..1bd60ef 100644 --- a/include/fs/fat32.h +++ b/include/fs/fat32.h @@ -74,6 +74,8 @@ public: uint32 first_clus; // The starting cluster number of the file uint32 parent_clus; // Starting cluster number of the parent directory uint32 dir_offset; // The byte offset of this directory entry in the parent directory + uint32 ent_sec; // Sector number of the directory entry + uint32 ent_off; // Offset of the directory entry within the sector FAT32Inode() : fs(nullptr), first_clus(0) {} // Implement VFS Interface @@ -83,6 +85,7 @@ public: Inode *lookup(const char *name) override; Inode *create(const char *name, short type, short major, short minor) override; void truncate() override; + int unlink(const char *name) override; }; class FAT32FileSystem : public FileSystem @@ -93,17 +96,20 @@ public: uint32 root_cluster; uint32 sectors_per_cluster; uint32 bytes_per_cluster; + uint32 fat_sz; // Size of the FAT table (number of sectors) void init() override; Inode* root() override; // Helper functions - uint32 next_cluster(uint32 cluster); // Check the FAT table for the next cluster - uint32 alloc_cluster(); // Assign a new cluster + uint32 next_cluster(uint32 cluster); // Check the FAT table for the next cluster + uint32 alloc_cluster(); // Assign a new cluster uint32 cluster_to_sector(uint32 cluster); // directory entry parsing void read_dir_ent(struct FAT32_DirEnt *de, char *filename); + // Release the entire cluster chain starting from the cluster + void free_cluster_chain(uint32 cluster); }; extern FAT32FileSystem fat32_fs; -- cgit v1.2.3