diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-01-04 14:05:49 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-01-04 14:05:49 +0800 |
| commit | d3cf3f08d1343d6b265516d5a79ce2d197b59d26 (patch) | |
| tree | a4bbae6cff94fa69eea30db865267b211eb4c86b /include/fs/file.h | |
| parent | 210025560c80b48af4875af199f183ad709e3bf0 (diff) | |
| download | lume-d3cf3f08d1343d6b265516d5a79ce2d197b59d26.tar.gz lume-d3cf3f08d1343d6b265516d5a79ce2d197b59d26.tar.xz | |
feat(file-system): implement read and write FAT32 File System and basic shell
Diffstat (limited to 'include/fs/file.h')
| -rw-r--r-- | include/fs/file.h | 39 |
1 files changed, 38 insertions, 1 deletions
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(); |
