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();
*/
#include <errno.h>
+#include <fcntl.h>
#include <fs.h>
#include <sched.h>
+#include <system.h>
#include <types.h>
#include <vfs.h>
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;
+}
}
static dentry_t *ramfs_lookup(inode_t *dir, dentry_t *dentry) {
+ // 不用上dir去找了,直接用dentry就可以了
+
+ // dentry对应的inode在ramfs_mkdir等里去分配的
dentry_add(dentry, NULL);
return NULL;
#handle SIGINT nostop noprint
-b root_task_entry
+#b root_task_entry
target remote localhost:1234
#b setup_kernel
#b e820_init_bootmem_data
+
+#b root_task_entry
+
c
return;
}
+ enable_irq();
+
// 如果需要调度程序
schedule();
}
extern __attribute__((regparm(0))) long sysc_mkdir(const char *path, int mode);
sysc_mkdir("/root", 0777);
+ sysc_mkdir("/root/aaa", 0777);
{
namei_t ni;