Repos / kernel.git / commitdiff
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 23d6cb2)
raw | patch | inline | side by side (parent: 23d6cb2)
| author | zhaoyanbai <zhaoyanbai@126.com> | |
| Sat, 5 Dec 2026 13:51:57 +0000 (21:51 +0800) | ||
| committer | zhaoyanbai <zhaoyanbai@126.com> | |
| Sat, 5 Dec 2026 13:51:57 +0000 (21:51 +0800) |
| fs/mount.c | patch | blob | history | |
| fs/mount.h | patch | blob | history |
diff --git a/fs/mount.c b/fs/mount.c
--- a/fs/mount.c
+++ b/fs/mount.c
kmem_cache_t* mount_kmem_cache = 0;
-// 通过挂载点目录的 path_t 也就是 {mount, dentry}计算hash
-// 就可以得到所有挂载在该目录上的挂载描述符 mount
-mount_t** mount_hash_table = 0;
-int mount_hash_table_size = 0;
+static list_head_t g_mounts = LIST_HEAD_INIT(g_mounts);
mount_t* alloc_mount(const char* name) {
mount_t* mnt = 0;
return mnt;
}
-mount_t* vfs_kernel_mount(fs_type_t* type, int flags, const char* name, void* data) {
+mount_t* vfs_create_mount(fs_type_t* type, int flags, const char* name, void* data) {
int ret = 0;
mount_t* mnt = 0;
@@ -60,63 +57,23 @@ mount_t* vfs_kernel_mount(fs_type_t* type, int flags, const char* name, void* da
mnt->mnt_point = mnt->mnt_root;
mnt->mnt_parent = mnt;
- // if (type->flags & FS_TYPE_NODEV) {
- // }
+ list_add(&mnt->mnt_list, &g_mounts);
return mnt;
}
-unsigned long mount_table_hash(mount_t* mnt, dentry_t* dentry) {
- unsigned long h = (unsigned long)mnt / 5;
- h += 1;
- h += (unsigned long)dentry / 5;
- h = h + (h >> 9);
- return h & (mount_hash_table_size - 1);
-}
-
-void add_mount_to_hash_table(mount_t* mnt) {
- unsigned long hash = mount_table_hash(mnt->mnt_parent, mnt->mnt_point);
-
- uint32_t eflags;
- irq_save(eflags);
-
- mount_t** p = mount_hash_table + hash;
-
- mnt->hash_next = *p;
-
- *p = mnt;
-
- irq_restore(eflags);
-}
-
void init_mount() {
mount_kmem_cache = kmem_cache_create("mount", sizeof(mount_t), 4);
if (0 == mount_kmem_cache) {
panic("create mount kmem cache failed");
}
-
- mount_hash_table = (mount_t**)page2va(alloc_one_page(0));
- memset(mount_hash_table, 0, PAGE_SIZE);
-
- mount_hash_table_size = PAGE_SIZE / sizeof(mount_t*);
-
- assert(mount_hash_table_size != 0);
-
- // mount_hash_table_size 应该是2的n次方的数
- int bit1_cnt = 0;
- for (int i = 0; i < sizeof(mount_hash_table_size) * 8; i++) {
- if (mount_hash_table_size & (1 << i)) {
- bit1_cnt++;
- }
- }
- assert(bit1_cnt == 1);
}
void mount_root() {
fs_type_t* type = vfs_find_filesystem("ramfs");
assert(type != NULL);
- mount_t* mnt = vfs_kernel_mount(type, 0, "ramfs", NULL);
+ mount_t* mnt = vfs_create_mount(type, 0, "ramfs", NULL);
assert(mnt != NULL);
assert(mnt->mnt_root != NULL);
diff --git a/fs/mount.h b/fs/mount.h
--- a/fs/mount.h
+++ b/fs/mount.h
#include "vfs.h"
-mount_t* vfs_kernel_mount(fs_type_t* type, int flags, const char* name, void* data);
+mount_t* vfs_create_mount(fs_type_t* type, int flags, const char* name, void* data);