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/file.h | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'include/fs/file.h') 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(); -- cgit v1.2.3