SimpleKernel 1.17.0
Loading...
Searching...
No Matches
mount.hpp
Go to the documentation of this file.
1
5#pragma once
6
7#include "filesystem.hpp"
8
9namespace vfs {
10
15struct MountPoint {
17 const char* mount_path{nullptr};
25 Inode* root_inode{nullptr};
29 bool active{false};
30};
35 public:
37 static constexpr size_t kMaxMounts = 16;
38
41 MountTable() = default;
42 MountTable(const MountTable&) = delete;
44 auto operator=(const MountTable&) -> MountTable& = delete;
45 auto operator=(MountTable&&) -> MountTable& = delete;
46 ~MountTable() = default;
48
58 [[nodiscard]] auto Mount(const char* path, FileSystem* fs,
59 BlockDevice* device) -> Expected<void>;
60
66 [[nodiscard]] auto Unmount(const char* path) -> Expected<void>;
67
73 [[nodiscard]] auto Lookup(const char* path) -> MountPoint*;
74
80 [[nodiscard]] auto GetRootDentry(MountPoint* mp) -> Dentry*;
81
87 [[nodiscard]] auto FindByMountDentry(const Dentry* dentry) -> MountPoint*;
88
95 [[nodiscard]] auto IsMountPoint(const char* path) -> bool;
96
101 [[nodiscard]] auto GetRootMount() -> MountPoint*;
102
103 private:
105 size_t mount_count_{0};
107};
108
113[[nodiscard]] auto GetMountTable() -> MountTable&;
114
115} // namespace vfs
块设备抽象基类
文件系统类型基类
挂载表管理器
Definition mount.hpp:34
auto FindByMountDentry(const Dentry *dentry) -> MountPoint *
根据 dentry 查找挂载在其上的文件系统
Definition mount.cpp:203
auto Unmount(const char *path) -> Expected< void >
卸载指定路径的文件系统
Definition mount.cpp:108
~MountTable()=default
size_t mount_count_
Definition mount.hpp:105
auto GetRootMount() -> MountPoint *
获取根挂载点
Definition mount.cpp:232
auto operator=(MountTable &&) -> MountTable &=delete
static constexpr size_t kMaxMounts
最大挂载点数
Definition mount.hpp:37
MountTable(const MountTable &)=delete
MountTable()=default
auto IsMountPoint(const char *path) -> bool
检查路径是否是挂载点
Definition mount.cpp:217
auto operator=(const MountTable &) -> MountTable &=delete
MountPoint mounts_[kMaxMounts]
Definition mount.hpp:104
auto Mount(const char *path, FileSystem *fs, BlockDevice *device) -> Expected< void >
挂载文件系统到指定路径
Definition mount.cpp:16
auto Lookup(const char *path) -> MountPoint *
根据路径查找对应的挂载点
Definition mount.cpp:158
MountTable(MountTable &&)=delete
MountPoint * root_mount_
Definition mount.hpp:106
std::expected< T, Error > Expected
std::expected 别名模板
Definition expected.hpp:365
auto GetRootDentry() -> Dentry *
获取根目录 dentry
Definition vfs.cpp:96
auto GetMountTable() -> MountTable &
获取全局挂载表实例
Definition mount.cpp:234
Dentry — 目录项缓存(路径名 ↔ Inode 的映射)
Definition vfs.hpp:41
Inode — 文件元数据(独立于路径名)
Definition vfs.hpp:16
挂载点
Definition mount.hpp:15
Dentry * root_dentry
该文件系统的根 dentry
Definition mount.hpp:27
BlockDevice * device
关联的块设备(可为 nullptr)
Definition mount.hpp:23
Dentry * mount_dentry
挂载点在父文件系统中的 dentry
Definition mount.hpp:19
const char * mount_path
挂载路径(如 "/mnt/disk")
Definition mount.hpp:17
bool active
是否处于活动状态
Definition mount.hpp:29
Inode * root_inode
该文件系统的根 inode
Definition mount.hpp:25