From: acevest Date: Sat, 14 Sep 2024 15:31:43 +0000 (+0800) Subject: 添加了一些vfs_open相关的代码 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=054343d41b59d035a628237dce67731e089ba734;p=kernel.git 添加了一些vfs_open相关的代码 --- diff --git a/fs/open.c b/fs/open.c index 54c57b3..86f9417 100644 --- a/fs/open.c +++ b/fs/open.c @@ -32,15 +32,13 @@ int get_unused_fd() { return -EMFILE; } -file_t *filp_open(const char *path, int flags, mode_t mode) { +file_t *filp_open(const char *path, int flags, int mode) { int ret = 0; - // ret = open_path(path, flags, mode, nd); - return NULL; } -int sysc_open(const char *path, int flags, mode_t mode) { +int sysc_open(const char *path, int flags, int mode) { int fd = 0; fd = get_unused_fd(); diff --git a/fs/path.c b/fs/path.c index 905678f..98f5ec1 100644 --- a/fs/path.c +++ b/fs/path.c @@ -8,8 +8,10 @@ */ #include +#include #include #include +#include #include #include @@ -371,3 +373,61 @@ dentry_t *path_lookup_create(namei_t *ni) { return dentry; } + +int path_open_namei(const char *path, int flags, int mode, namei_t *ni) { + int ret = 0; + dentry_t *dentry = NULL; + dentry_t *dir = NULL; + inode_t *inode = NULL; + + if (flags % O_CREAT == 0) { + path_init(path, flags, ni); + ret = path_walk(path, ni); + if (0 != ret) { + return ret; + } + dentry = ni->path.dentry; + goto ok; + } + + path_init(path, PATH_LOOKUP_PARENT, ni); + ret = path_walk(path, ni); + if (0 != ret) { + return ret; + } + + if (ni->last_type != LAST_NORMAL) { + ret = -EISDIR; + goto end; + } + + dir = ni->path.dentry; + assert(NULL != dir); + + down(&dir->d_inode->i_sem); + + dentry = dentry_cached_lookup(dir, &ni->last); + if (IS_ERR(dentry)) { + ret = PTR_ERR(dentry); + up(&dir->d_inode->i_sem); + goto end; + } + + if (NULL == dentry->d_inode) { + // vfs_create(); + up(&dir->d_inode->i_sem); + dentry_put(ni->path.dentry); + goto ok; + } + +ok: + inode = dentry->d_inode; + if (NULL == inode) { + ret = -ENOENT; + goto end; + } + +end: + + return ret; +} diff --git a/fs/ramfs.c b/fs/ramfs.c index f4b15e4..93a225e 100644 --- a/fs/ramfs.c +++ b/fs/ramfs.c @@ -78,6 +78,9 @@ static int ramfs_mkdir(inode_t *dir, dentry_t *dentry, umode_t mode) { } static dentry_t *ramfs_lookup(inode_t *dir, dentry_t *dentry) { + // 不用上dir去找了,直接用dentry就可以了 + + // dentry对应的inode在ramfs_mkdir等里去分配的 dentry_add(dentry, NULL); return NULL; diff --git a/gdbscript b/gdbscript index 8ff45da..0cb0213 100644 --- a/gdbscript +++ b/gdbscript @@ -13,7 +13,7 @@ set confirm off #handle SIGINT nostop noprint -b root_task_entry +#b root_task_entry target remote localhost:1234 @@ -29,6 +29,9 @@ set pagination off #b setup_kernel #b e820_init_bootmem_data + +#b root_task_entry + c diff --git a/kernel/irq.c b/kernel/irq.c index 83cfada..701513a 100644 --- a/kernel/irq.c +++ b/kernel/irq.c @@ -160,6 +160,8 @@ __attribute__((regparm(1))) void irq_handler(pt_regs_t *regs) { return; } + enable_irq(); + // 如果需要调度程序 schedule(); } diff --git a/kernel/task_root.c b/kernel/task_root.c index 858d3c5..b71231d 100644 --- a/kernel/task_root.c +++ b/kernel/task_root.c @@ -166,6 +166,7 @@ void root_task_entry() { extern __attribute__((regparm(0))) long sysc_mkdir(const char *path, int mode); sysc_mkdir("/root", 0777); + sysc_mkdir("/root/aaa", 0777); { namei_t ni;