]> Zhao Yanbai Git Server - kernel.git/commitdiff
authorzhaoyanbai <zhaoyanbai@126.com>
Fri, 4 Dec 2026 05:13:01 +0000 (13:13 +0800)
committerzhaoyanbai <zhaoyanbai@126.com>
Fri, 4 Dec 2026 05:13:01 +0000 (13:13 +0800)
Makefile
fs/fs.c
fs/mount.c
fs/mount.h
fs/path.c
fs/ramfs.c
fs/super.c
fs/vfs.c
fs/vfs.h
include/fs.h
test_list.c [deleted file]

index 1e52334..362086b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -48,7 +48,7 @@ CFLAGS        += -DNR_TTYS=3
 CFLAGS += -DENABLE_BOOT_WAIT=0
 CFLAGS += -DENABLE_CLOCK_IRQ_WAIT=0
 
-SYSTEMMAP      := System.map
+SYSTEMMAP      := /tmp/System.map
 KERNELBIN      := KERNEL.ELF
 LINKSCRIPT     := scripts/link.ld
 
@@ -83,7 +83,7 @@ print_flags:
 ${KERNELBIN}: print_flags ${OBJS}
        @echo 'LD ${KERNELBIN}'
        @${LD} ${LDFLAGS} $(OBJS) -o $@ > $(SYSTEMMAP)
-       @nm -a $@ > kernel.sym
+       @nm -a $@ > /tmp/kernel.sym
        rm kernel/setup.c.o
 
 %.S.o: %.S ${HEADER_FILES}
diff --git a/fs/fs.c b/fs/fs.c
index e4fa3f3..cb9244f 100644 (file)
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -33,7 +33,7 @@ unsigned int namei(const char* path) {
     return ext2_search_inpath(path);
 }
 
-vfsmount_t rootfs_vfsmount;
+mount_t rootfs_mount;
 
 dentry_t rootfs_root_dentry;
 
index 09716ba..66edb72 100644 (file)
 #include "system.h"
 #include "task.h"
 
-kmem_cache_t* vfsmount_kmem_cache = 0;
+kmem_cache_t* mount_kmem_cache = 0;
 
 // 通过挂载点目录的 path_t 也就是 {mount, dentry}计算hash
-// 就可以得到所有挂载在该目录上的挂载描述符 vfsmount
-vfsmount_t** vfsmount_hash_table = 0;
-int vfsmount_hash_table_size = 0;
+// 就可以得到所有挂载在该目录上的挂载描述符 mount
+mount_t** mount_hash_table = 0;
+int mount_hash_table_size = 0;
 
-vfsmount_t* alloc_vfsmount(const char* name) {
-    vfsmount_t* mnt = 0;
+mount_t* alloc_mount(const char* name) {
+    mount_t* mnt = 0;
 
-    mnt = (vfsmount_t*)kmem_cache_zalloc(vfsmount_kmem_cache, 0);
+    mnt = (mount_t*)kmem_cache_zalloc(mount_kmem_cache, 0);
 
     if (0 == mnt) {
-        panic("no mem alloc for vfsmount: %s", name);
+        panic("no mem alloc for mount: %s", name);
         return 0;
     }
 
@@ -40,13 +40,13 @@ vfsmount_t* alloc_vfsmount(const char* name) {
     return mnt;
 }
 
-vfsmount_t* vfs_kernel_mount(fs_type_t* type, int flags, const char* name, void* data) {
+mount_t* vfs_kernel_mount(fs_type_t* type, int flags, const char* name, void* data) {
     int ret = 0;
-    vfsmount_t* mnt = 0;
+    mount_t* mnt = 0;
 
     assert(0 != type);
 
-    mnt = alloc_vfsmount(name);
+    mnt = alloc_mount(name);
 
     ret = type->read_super(type, flags, name, data, mnt);
     assert(ret == 0);
@@ -63,21 +63,21 @@ vfsmount_t* vfs_kernel_mount(fs_type_t* type, int flags, const char* name, void*
     return mnt;
 }
 
-unsigned long vfsmount_table_hash(vfsmount_t* mnt, dentry_t* dentry) {
+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 & (vfsmount_hash_table_size - 1);
+    return h & (mount_hash_table_size - 1);
 }
 
-void add_vfsmount_to_hash_table(vfsmount_t* mnt) {
-    unsigned long hash = vfsmount_table_hash(mnt->mnt_parent, mnt->mnt_point);
+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);
 
-    vfsmount_t** p = vfsmount_hash_table + hash;
+    mount_t** p = mount_hash_table + hash;
 
     mnt->hash_next = *p;
 
@@ -87,22 +87,22 @@ void add_vfsmount_to_hash_table(vfsmount_t* mnt) {
 }
 
 void init_mount() {
-    vfsmount_kmem_cache = kmem_cache_create("vfsmount", sizeof(vfsmount_t), 4);
-    if (0 == vfsmount_kmem_cache) {
-        panic("create vfsmount kmem cache failed");
+    mount_kmem_cache = kmem_cache_create("mount", sizeof(mount_t), 4);
+    if (0 == mount_kmem_cache) {
+        panic("create mount kmem cache failed");
     }
 
-    vfsmount_hash_table = (vfsmount_t**)page2va(alloc_one_page(0));
-    memset(vfsmount_hash_table, 0, PAGE_SIZE);
+    mount_hash_table = (mount_t**)page2va(alloc_one_page(0));
+    memset(mount_hash_table, 0, PAGE_SIZE);
 
-    vfsmount_hash_table_size = PAGE_SIZE / sizeof(vfsmount_t*);
+    mount_hash_table_size = PAGE_SIZE / sizeof(mount_t*);
 
-    assert(vfsmount_hash_table_size != 0);
+    assert(mount_hash_table_size != 0);
 
-    // vfsmount_hash_table_size 应该是2的n次方的数
+    // mount_hash_table_size 应该是2的n次方的数
     int bit1_cnt = 0;
-    for (int i = 0; i < sizeof(vfsmount_hash_table_size) * 8; i++) {
-        if (vfsmount_hash_table_size & (1 << i)) {
+    for (int i = 0; i < sizeof(mount_hash_table_size) * 8; i++) {
+        if (mount_hash_table_size & (1 << i)) {
             bit1_cnt++;
         }
     }
@@ -113,7 +113,7 @@ void mount_root() {
     fs_type_t* type = vfs_find_filesystem("ramfs");
     assert(type != NULL);
 
-    vfsmount_t* mnt = vfs_kernel_mount(type, 0, "ramfs", NULL);
+    mount_t* mnt = vfs_kernel_mount(type, 0, "ramfs", NULL);
     assert(mnt != NULL);
 
     assert(mnt->mnt_root != NULL);
index 375c6e1..2e894e0 100644 (file)
@@ -11,4 +11,4 @@
 
 #include "vfs.h"
 
-vfsmount_t* vfs_kernel_mount(fs_type_t* type, int flags, const char* name, void* data);
+mount_t* vfs_kernel_mount(fs_type_t* type, int flags, const char* name, void* data);
index bd0c8c0..9cb87c1 100644 (file)
--- a/fs/path.c
+++ b/fs/path.c
@@ -43,7 +43,7 @@ void follow_dotdot(namei_t* ni) {
 #else
     while (1) {
         dentry_t* dentry = NULL;
-        vfsmount_t* parent = NULL;
+        mount_t* parent = NULL;
 
         // 如果当前目录已经是根目录
         if (ni->dentry == current->dentry_root) {
@@ -60,16 +60,16 @@ void follow_dotdot(namei_t* ni) {
         }
 
         // 当前目录是挂载的根目录,这就需要找到挂载点的上一层目录
-        // 所以先找到挂载点的父挂载点vfsmount
+        // 所以先找到挂载点的父挂载点mount
         parent = ni->mnt->mnt_parent;
 
-        // 如果当前挂载点已经是最开始的挂载点vfsmount了
+        // 如果当前挂载点已经是最开始的挂载点mount了
         if (ni->mnt == parent) {
             return;
         }
 
         // 如果当前挂载点有父挂载点
-        // 就记录当前挂载点的dentry和它所在的挂载vfsmount
+        // 就记录当前挂载点的dentry和它所在的挂载mount
         dentry = ni->mnt->mnt_point;
         ni->dentry = dentry;
         ni->mnt = parent;
@@ -117,13 +117,13 @@ uint64_t compute_qstr_hash(qstr_t* q) {
     return q->hash;
 }
 
-int follow_down(dentry_t** dentry, vfsmount_t** vfsmnt) {
+int follow_down(dentry_t** dentry, mount_t** vfsmnt) {
     // assert(*dentry != NULL);
     // assert(*vfsmnt != NULL);
 
     // list_head_t *pos;
     // list_for_each(pos, &((*dentry)->d_vfsmnt)) {
-    //     vfsmount_t *tmp_mnt = list_entry(pos, vfsmount_t, mnt_clash);
+    //     mount_t *tmp_mnt = list_entry(pos, mount_t, mnt_clash);
     //     if (*vfsmnt == tmp_mnt->mnt_parent) {
     //         *vfsmnt = vfsmnt_get(tmp_mnt);
     //         vfsmnt_put(tmp_mnt->mnt_parent);
index 665a535..1f8ad2a 100644 (file)
@@ -160,7 +160,7 @@ int ramfs_fill_super_cb(superblock_t* sb, void* data) {
     return err;
 }
 
-int ramfs_read_super(fs_type_t* type, int flags, const char* name, void* data, vfsmount_t* mnt) {
+int ramfs_read_super(fs_type_t* type, int flags, const char* name, void* data, mount_t* mnt) {
     int ret = 0;
 
     ret = read_super_for_nodev(type, flags, data, ramfs_fill_super_cb, mnt);
index 862e470..e6b633a 100644 (file)
@@ -39,7 +39,7 @@ int set_anonymous_super(superblock_t* s, void* data) {
     return 0;
 }
 
-int read_super_for_nodev(fs_type_t* type, int flags, void* data, fill_super_cb_t fill_super, vfsmount_t* mnt) {
+int read_super_for_nodev(fs_type_t* type, int flags, void* data, fill_super_cb_t fill_super, mount_t* mnt) {
     int err = 0;
     superblock_t* s = 0;
 
index 93f8e34..0d53b13 100644 (file)
--- a/fs/vfs.c
+++ b/fs/vfs.c
@@ -77,15 +77,6 @@ fs_type_t* vfs_find_filesystem(const char* name) {
 //     // superblock_t *sb = fs->read_super(NULL, NULL);
 // }
 
-/////////
-vfsmount_t* vfsmnt_get(vfsmount_t* m) {
-    panic("todo");
-    return NULL;
-}
-void vfsmnt_put(vfsmount_t* m) {
-    //
-    panic("todo");
-}
 
 int vfs_create(inode_t* dir, dentry_t* dentry, int mode, namei_t* ni) {
     int ret = 0;
index 88fdb69..824c695 100644 (file)
--- a/fs/vfs.h
+++ b/fs/vfs.h
@@ -28,7 +28,7 @@ typedef struct sb_operations sb_operations_t;
 typedef struct file_operations file_operations_t;
 typedef struct inode_operations inode_operations_t;
 typedef struct dentry_operations dentry_operations_t;
-typedef struct vfsmount vfsmount_t;
+typedef struct mount mount_t;
 typedef struct path path_t;
 
 typedef struct address_space_operations address_space_operations_t;
@@ -36,7 +36,7 @@ typedef struct address_space address_space_t;
 
 struct path {
     dentry_t* dentry;
-    vfsmount_t* mnt;
+    mount_t* mnt;
 };
 
 #define PATH_LOOKUP_PARENT /*    */ 0x00000001
@@ -180,7 +180,7 @@ struct dentry {
 
     // 需要一个标记自己已经成为挂载点的标志?
     // uint32_t d_flags;
-    // 也可以用一个指向vfsmount的指针,非0表示挂载?
+    // 也可以用一个指向mount的指针,非0表示挂载?
     // 貌似应该搞个链表,因为一个点可以重复挂N次,N个文件系统
     list_head_t d_vfsmnt;  // 所有挂载到这个目录的挂载点
 
@@ -234,28 +234,28 @@ struct dentry_operations {
     //
 };
 
-// 每当将一个存储设备安装到现有文件系统中的某个节点时,内核就要为之建立一个vfsmount结构
+// 每当将一个存储设备安装到现有文件系统中的某个节点时,内核就要为之建立一个mount结构
 // 这个结构中即包含着该设备的有关信息,也包含了安装点的信息
 // 系统中的每个文件系统,包括根设备的根文件系统,都要经过安装
 //
 // 在安装文件系统时内核主要做如下的事情
-// 创建一个vfsmount
+// 创建一个mount
 // 为被安装的设备创建一个superblock,并由该设备对应的文件系统来设置这个superblock
 // 为被安装的设备的根目录创建一个dentry
 // 为被安装的设备的根目录创建一个inode,由sb->sb_ops->read_inode来实现
 // 将superblock与被安装设备根目录的dentry关联
-// 将vfsmount与被安装设备的根目录dentry关联
+// 将mount与被安装设备的根目录dentry关联
 #define MAX_VFSMNT_NAME_LEN 32
-struct vfsmount {
+struct mount {
     dentry_t* mnt_point;          // 挂载点 dentry
     dentry_t* mnt_root;           // 设备根目录 dentry
     superblock_t* mnt_sb;         // 被安装的设备的superblock
-    struct vfsmount* mnt_parent;  // 如果多个设备挂载到同一个目录,则每个vfsmount的parent都指向同一个vfsmount
+    struct mount* mnt_parent;  // 如果多个设备挂载到同一个目录,则每个mount的parent都指向同一个mount
     // sb->sb_ops->read_inode得到被安装设备根目录的inode
 
-    list_head_t mnt_list;  // vfsmount 链表
+    list_head_t mnt_list;  // mount 链表
 
-    vfsmount_t* hash_next;
+    mount_t* hash_next;
 
     char mnt_devname[MAX_VFSMNT_NAME_LEN];
 
@@ -271,7 +271,9 @@ typedef struct fs_type fs_type_t;
 struct fs_type {
     const char* name;
     // superblock_t *(*read_super)(superblock_t *, void *);
-    int (*read_super)(fs_type_t* type, int flags, const char* name, void* data, vfsmount_t* mnt);
+    // TODO REMOVE read_super
+    int (*read_super)(fs_type_t* type, int flags, const char* name, void* data, mount_t* mnt);
+
     int flags;  // FS_REQUIRES_DEV or NODEV
     struct fs_type* next;
     // 同属于这个文件系统的所有超级块链表
@@ -308,8 +310,8 @@ dentry_t* dentry_alloc(dentry_t* parent, const qstr_t* s);
 void dentry_add(dentry_t* dentry, inode_t* inode);
 void dentry_attach_inode(dentry_t* dentry, inode_t* inode);
 
-vfsmount_t* vfsmnt_get(vfsmount_t* m);
-void vfsmnt_put(vfsmount_t* m);
+mount_t* vfsmnt_get(mount_t* m);
+void vfsmnt_put(mount_t* m);
 
 dentry_t* dentry_get(dentry_t* dentry);
 void dentry_get_locked(dentry_t* dentry);
index f13099e..d0bae2d 100644 (file)
@@ -57,7 +57,7 @@ enum { CHRDEV_CNSL, CHRDEV_SIZE };
 extern chrdev_t* chrdev[];
 
 typedef int (*fill_super_cb_t)(superblock_t* sb, void* data);
-int read_super_for_nodev(fs_type_t* type, int flags, void* data, fill_super_cb_t fill_super, vfsmount_t* mnt);
+int read_super_for_nodev(fs_type_t* type, int flags, void* data, fill_super_cb_t fill_super, mount_t* mnt);
 
 int sget(fs_type_t* type,                    //
          int (*test)(superblock_t*, void*),  //
diff --git a/test_list.c b/test_list.c
deleted file mode 100644 (file)
index 36d9a98..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-/* Allmost Copy From Linux */
-typedef struct list_head {
-    struct list_head *prev, *next;
-} list_head_t;
-
-#define LIST_HEAD_INIT(name) {&(name), &(name)}
-#define LIST_HEAD(name) list_head_t name = LIST_HEAD_INIT(name)
-
-#define INIT_LIST_HEAD(ptr)  \
-    do {                     \
-        (ptr)->next = (ptr); \
-        (ptr)->prev = (ptr); \
-    } while (0)
-
-#define list_entry(ptr, type, member) ((type*)((char*)(ptr) - (unsigned long)(&((type*)0)->member)))
-
-#define list_first_entry(ptr, type, member) list_entry((ptr)->next, type, member)
-
-#define list_for_each(pos, head) for (pos = (head)->next; pos != (head); pos = pos->next)
-
-#define list_for_each_safe(pos, tmp, head) \
-    for (pos = (head)->next, tmp = pos->next; pos != (head); pos = tmp, tmp = pos->next)
-
-#define list_for_each_entry_safe(pos, tmp, head, member)          \
-    for (pos = list_entry((head)->next, typeof(*pos), member),    \
-        tmp = list_entry(pos->member.next, typeof(*pos), member); \
-         &pos->member != (head); pos = tmp, tmp = list_entry(tmp->member.next, typeof(*tmp), member))
-
-static inline void _list_add(list_head_t* pnew, list_head_t* prev, list_head_t* next) {
-    next->prev = pnew;
-    pnew->next = next;
-    pnew->prev = prev;
-    prev->next = pnew;
-}
-
-static inline void list_add(list_head_t* pnew, list_head_t* head) {
-    _list_add(pnew, head, head->next);
-}
-
-static inline void list_add_tail(list_head_t* pnew, list_head_t* head) {
-    _list_add(pnew, head->prev, head);
-}
-
-static inline void _list_del(list_head_t* prev, list_head_t* next) {
-    next->prev = prev;
-    prev->next = next;
-}
-
-static inline void list_del(list_head_t* entry) {
-    _list_del(entry->prev, entry->next);
-    entry->prev = NULL;
-    entry->next = NULL;
-}
-
-static inline void list_del_init(list_head_t* entry) {
-    _list_del(entry->prev, entry->next);
-    INIT_LIST_HEAD(entry);
-}
-
-static inline int list_empty(list_head_t* head) {
-    return head->next == head;
-}
-
-typedef struct node {
-    int id;
-    list_head_t list;
-    list_head_t pend;
-} node_t;
-
-LIST_HEAD(allH);
-LIST_HEAD(pendH);
-
-int main() {
-    INIT_LIST_HEAD(&allH);
-    INIT_LIST_HEAD(&pendH);
-
-    for (int i = 0; i < 10; i++) {
-        node_t* n = (node_t*)malloc(sizeof(node_t));
-        n->id = i;
-        list_add(&n->list, &allH);
-        if (n->id % 3 == 0) {
-            list_add(&n->pend, &pendH);
-        }
-    }
-
-    list_head_t* pos;
-    list_head_t* tmp;
-    node_t *p, *p1;
-    list_for_each_safe(pos, tmp, &allH) {
-        p = list_entry(pos, node_t, list);
-        printf("allH: %d\n", p->id);
-    }
-
-    printf("-----\n");
-    list_for_each_safe(pos, tmp, &pendH) {
-        p = list_entry(pos, node_t, pend);
-        printf("pendH: %d\n", p->id);
-    }
-
-    // list_for_each_safe(pos, tmp, &allH) {
-
-    //    p = list_entry(pos, node_t, list);
-    list_for_each_entry_safe(p, p1, &pendH, pend) {
-        // printf("%d\n", p->id);
-        if (p->id == 3) {
-            list_del(&p->pend);
-        }
-    }
-
-    printf("-----\n");
-
-    list_for_each_safe(pos, tmp, &allH) {
-        p = list_entry(pos, node_t, list);
-        printf("allH: %d\n", p->id);
-    }
-
-    printf("-----\n");
-    list_for_each_safe(pos, tmp, &pendH) {
-        p = list_entry(pos, node_t, pend);
-        printf("pendH: %d\n", p->id);
-    }
-}