diff options
Diffstat (limited to 'include/fs')
| -rw-r--r-- | include/fs/fat32.h | 10 | ||||
| -rw-r--r-- | include/fs/file.h | 39 | ||||
| -rw-r--r-- | include/fs/fs.h | 4 |
3 files changed, 50 insertions, 3 deletions
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; diff --git a/include/fs/file.h b/include/fs/file.h index 2f23176..a92d8f8 100644 --- a/include/fs/file.h +++ b/include/fs/file.h @@ -10,6 +10,8 @@ enum FileType FD_PIPE }; +class Pipe; + struct file { enum FileType type; @@ -17,11 +19,46 @@ struct file char readable; char writable; - struct pipe *pipe; // pipeline pointer + Pipe *pipe; // pipeline pointer Inode *ip; // VFS Inode uint32 off; // Current Offset }; +class Pipe +{ +public: + static constexpr uint32_t SIZE = 512; + + Pipe() : nread(0), nwrite(0), read_open(true), write_open(true) + { + lock.init("pipe"); + } + + // forbid copy + Pipe(const Pipe &) = delete; + Pipe &operator=(const Pipe &) = delete; + + ~Pipe() + { + // + } + + // creates a pair of connected file objects + static int create_pair(struct file **f0, struct file **f1); + + int read(uint64_t addr, int n); + int write(uint64_t addr, int n); + void close(bool is_writer); + +private: + Spinlock lock; + char data[SIZE]; + uint32_t nread; // read + uint32_t nwrite; // write + bool read_open; + bool write_open; +}; + namespace FileTable { void init(); diff --git a/include/fs/fs.h b/include/fs/fs.h index f40bc0c..235ec80 100644 --- a/include/fs/fs.h +++ b/include/fs/fs.h @@ -57,6 +57,8 @@ public: virtual void getattr(struct kstat *st); // Truncate file (set size to 0, release all data blocks) virtual void truncate() = 0; + // Delete the file named 'name' from the directory (Unlink) + virtual int unlink(const char *name) = 0; }; // File System Abstraction (SuperBlock) @@ -90,4 +92,6 @@ namespace VFS Inode *get_root(); // Path Analysis Inode *namei(const char *path); + // Find the parent directory inode of the path, and copy the last part of the path (the file name) into the name buffer + Inode *nameiparent(const char *path, char *name); } // namespace VFS |
