MCPcopy Create free account
hub / github.com/Simple-XX/SimpleKernel / FileSystem

Class FileSystem

src/filesystem/vfs/include/filesystem.hpp:17–70  ·  view source on GitHub ↗

* @brief 文件系统类型基类 * @details 每种文件系统(ramfs/fat32/ext2 等)注册一个 FileSystem 实例。 * VFS 通过此接口挂载/卸载文件系统。 */

Source from the content-addressed store, hash-verified

15 * VFS 通过此接口挂载/卸载文件系统。
16 */
17class FileSystem {
18 public:
19 virtual ~FileSystem() = default;
20
21 /**
22 * @brief 获取文件系统类型名(如 "ramfs", "fat32"
23 * @return 文件系统类型名
24 */
25 [[nodiscard]] virtual auto GetName() const -> const char* = 0;
26
27 /**
28 * @brief 挂载文件系统
29 * @param device 块设备指针(ramfs 等内存文件系统传 nullptr)
30 * @return Expected<Inode*> 根目录 inode
31 * @post 返回的 inode->type == FileType::kDirectory
32 */
33 [[nodiscard]] virtual auto Mount(BlockDevice* device) -> Expected<Inode*> = 0;
34
35 /**
36 * @brief 卸载文件系统
37 * @return Expected<void> 成功或错误
38 * @pre 没有打开的文件引用此文件系统
39 */
40 [[nodiscard]] virtual auto Unmount() -> Expected<void> = 0;
41
42 /**
43 * @brief 将缓存数据刷写到磁盘
44 * @return Expected<void> 成功或错误
45 */
46 [[nodiscard]] virtual auto Sync() -> Expected<void> = 0;
47
48 /**
49 * @brief 分配新 inode
50 * @return Expected<Inode*> 新分配的 inode 或错误
51 * @note 由具体文件系统实现 inode 分配策略
52 */
53 [[nodiscard]] virtual auto AllocateInode() -> Expected<Inode*> = 0;
54
55 /**
56 * @brief 释放 inode
57 * @param inode 要释放的 inode
58 * @return Expected<void> 成功或错误
59 * @pre inode != nullptr
60 * @pre inode->link_count == 0
61 */
62 [[nodiscard]] virtual auto FreeInode(Inode* inode) -> Expected<void> = 0;
63
64 /**
65 * @brief 获取文件系统的文件操作接口
66 * @return FileOps* 文件操作接口指针
67 * @note 用于创建 File 对象时设置 ops
68 */
69 [[nodiscard]] virtual auto GetFileOps() -> FileOps* = 0;
70};
71
72} // namespace vfs

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected