From 56bee8be77bd51f9acfb86f1eeac839252948c2f Mon Sep 17 00:00:00 2001 From: Matheus Date: Sun, 28 Aug 2022 16:28:11 -0300 Subject: [PATCH] VFS: dot entries --- src/fs/devfs.c | 3 +-- src/fs/tmpfs.c | 6 ++---- src/fs/vfs.c | 11 +++++++---- src/include/kernel/vfs.h | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/fs/devfs.c b/src/fs/devfs.c index 4c53e629..1dabf8d1 100644 --- a/src/fs/devfs.c +++ b/src/fs/devfs.c @@ -10,13 +10,12 @@ static fs_t* fs; static int devfs_mount(dirnode_t* mountpoint, vnode_t* device, int mountflags, void* fsinfo){ - dirnode_t* node = vfs_newdirnode(mountpoint->vnode.name, fs, 0); + dirnode_t* node = vfs_newdirnode(mountpoint->vnode.name, fs, NULL, mountpoint->vnode.parent); if(!node) return ENOMEM; mountpoint->mount = node; - node->vnode.parent = mountpoint->vnode.parent; return 0; } diff --git a/src/fs/tmpfs.c b/src/fs/tmpfs.c index fae24c69..58e8114a 100644 --- a/src/fs/tmpfs.c +++ b/src/fs/tmpfs.c @@ -12,7 +12,7 @@ static int tmpfs_mount(dirnode_t* mountpoint, vnode_t* device, int mountflags, v if(!desc) return ENOMEM; - dirnode_t* root = vfs_newdirnode(mountpoint->vnode.name, desc, NULL); + dirnode_t* root = vfs_newdirnode(mountpoint->vnode.name, desc, NULL, mountpoint->vnode.parent); if(!root){ free(desc); @@ -21,7 +21,6 @@ static int tmpfs_mount(dirnode_t* mountpoint, vnode_t* device, int mountflags, v desc->calls = tmpfs_getfuncs(); mountpoint->mount = root; - root->vnode.parent = mountpoint->vnode.parent; return 0; } @@ -74,7 +73,7 @@ static int tmpfs_close(vnode_t* node){return 0;} // nothing to do really static int tmpfs_mkdir(dirnode_t* parent, char* name, mode_t mode){ - dirnode_t* node = vfs_newdirnode(name, parent->vnode.fs, NULL); + dirnode_t* node = vfs_newdirnode(name, parent->vnode.fs, NULL, parent); if(!node) return ENOMEM; @@ -84,7 +83,6 @@ static int tmpfs_mkdir(dirnode_t* parent, char* name, mode_t mode){ return ENOMEM; } - node->vnode.parent = parent; stat* st = &node->vnode.st; st->st_mode = MAKETYPE(TYPE_DIR) | GETMODE(mode); st->st_blksize = PAGE_SIZE; diff --git a/src/fs/vfs.c b/src/fs/vfs.c index 244d60da..00bc0198 100644 --- a/src/fs/vfs.c +++ b/src/fs/vfs.c @@ -276,7 +276,7 @@ vnode_t* vfs_newnode(char* name, fs_t* fs, void* fsdata){ } -dirnode_t* vfs_newdirnode(char* name, fs_t* fs, void* fsdata){ +dirnode_t* vfs_newdirnode(char* name, fs_t* fs, void* fsdata, dirnode_t* parent){ dirnode_t* node = alloc(sizeof(dirnode_t)); if(!node) return NULL; @@ -289,12 +289,15 @@ dirnode_t* vfs_newdirnode(char* name, fs_t* fs, void* fsdata){ return NULL; } - if(!hashtable_init(&node->children, 10)){ // add more here later + if(!hashtable_init(&node->children, 25)){ // add more here later free(vnode->name); free(node); return NULL; } - + + hashtable_insert(&node->children, ".", node); + hashtable_insert(&node->children, "..", parent); + vnode->st.st_mode = MAKETYPE(TYPE_DIR); vnode->fs = fs; vnode->fsdata = fsdata; @@ -401,7 +404,7 @@ void vfs_releasenode(vnode_t* node){ void vfs_init(){ printf("Creating a fake root for the VFS\n"); - vfsroot = vfs_newdirnode("/", NULL, NULL); + vfsroot = vfs_newdirnode("/", NULL, NULL, NULL); hashtable_init(&fsfuncs, 10); diff --git a/src/include/kernel/vfs.h b/src/include/kernel/vfs.h index c7212187..7fc5762d 100644 --- a/src/include/kernel/vfs.h +++ b/src/include/kernel/vfs.h @@ -74,7 +74,7 @@ dirnode_t* vfs_root(); void vfs_acquirenode(vnode_t* node); void vfs_releasenode(vnode_t* node); vnode_t* vfs_newnode(char* name, fs_t* fs, void* fsdata); -dirnode_t* vfs_newdirnode(char* name, fs_t* fs, void* fsdata); +dirnode_t* vfs_newdirnode(char* name, fs_t* fs, void* fsdata, dirnode_t* parent); void vfs_destroynode(vnode_t* node); int vfs_resolvepath(vnode_t** result, dirnode_t** parent, dirnode_t* ref, char* path, char* name);