mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 15:08:21 +00:00
vfs: very basic locking
This commit is contained in:
+55
-11
@@ -4,9 +4,11 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <kernel/devman.h>
|
#include <kernel/devman.h>
|
||||||
|
#include <arch/spinlock.h>
|
||||||
|
|
||||||
dirnode_t* vfsroot;
|
dirnode_t* vfsroot;
|
||||||
hashtable fsfuncs;
|
hashtable fsfuncs;
|
||||||
|
static int lock;
|
||||||
|
|
||||||
static inline dirnode_t* mountpoint(dirnode_t* node){
|
static inline dirnode_t* mountpoint(dirnode_t* node){
|
||||||
dirnode_t* ret = node;
|
dirnode_t* ret = node;
|
||||||
@@ -72,8 +74,13 @@ int vfs_write(int* error, vnode_t* node, void* buff, size_t count, size_t offset
|
|||||||
return writecount;
|
return writecount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
spinlock_acquire(&lock);
|
||||||
|
|
||||||
int writecount = node->fs->calls->write(error, node, buff, count, offset);
|
int writecount = node->fs->calls->write(error, node, buff, count, offset);
|
||||||
|
|
||||||
|
spinlock_release(&lock);
|
||||||
|
|
||||||
return writecount;
|
return writecount;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -101,14 +108,20 @@ int vfs_read(int* error, vnode_t* node, void* buff, size_t count, size_t offset)
|
|||||||
return readcount;
|
return readcount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
spinlock_acquire(&lock);
|
||||||
|
|
||||||
int readcount = node->fs->calls->read(error, node, buff, count, offset);
|
int readcount = node->fs->calls->read(error, node, buff, count, offset);
|
||||||
|
|
||||||
|
spinlock_release(&lock);
|
||||||
|
|
||||||
return readcount;
|
return readcount;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int vfs_close(vnode_t* node){
|
int vfs_close(vnode_t* node){
|
||||||
|
|
||||||
|
spinlock_acquire(&lock);
|
||||||
|
|
||||||
vfs_releasenode(node);
|
vfs_releasenode(node);
|
||||||
|
|
||||||
int status = 0;
|
int status = 0;
|
||||||
@@ -116,6 +129,8 @@ int vfs_close(vnode_t* node){
|
|||||||
if(node->refcount == 0)
|
if(node->refcount == 0)
|
||||||
status = node->fs->calls->close(node);
|
status = node->fs->calls->close(node);
|
||||||
|
|
||||||
|
spinlock_release(&lock);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,13 +138,18 @@ int vfs_open(vnode_t** buff, dirnode_t* ref, char* path){
|
|||||||
|
|
||||||
vnode_t* node;
|
vnode_t* node;
|
||||||
|
|
||||||
|
spinlock_acquire(&lock);
|
||||||
|
|
||||||
int res = vfs_resolvepath(&node, NULL, ref, path, NULL);
|
int res = vfs_resolvepath(&node, NULL, ref, path, NULL);
|
||||||
|
|
||||||
if(res)
|
if(res){
|
||||||
|
spinlock_release(&lock);
|
||||||
return res;
|
return res;
|
||||||
|
}
|
||||||
vfs_acquirenode(node);
|
vfs_acquirenode(node);
|
||||||
|
|
||||||
|
spinlock_release(&lock);
|
||||||
|
|
||||||
*buff = node;
|
*buff = node;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -143,16 +163,23 @@ int vfs_create(dirnode_t* ref, char* path, mode_t mode){
|
|||||||
|
|
||||||
char name[512];
|
char name[512];
|
||||||
|
|
||||||
|
spinlock_acquire(&lock);
|
||||||
|
|
||||||
int result = vfs_resolvepath(&buff, &parent, ref, path, name);
|
int result = vfs_resolvepath(&buff, &parent, ref, path, name);
|
||||||
|
|
||||||
if(!parent)
|
if(!parent){
|
||||||
|
spinlock_release(&lock);
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
if(buff)
|
if(buff){
|
||||||
|
spinlock_release(&lock);
|
||||||
return EEXIST;
|
return EEXIST;
|
||||||
|
}
|
||||||
result = parent->vnode.fs->calls->create(parent, name, NULL);
|
result = parent->vnode.fs->calls->create(parent, name, NULL);
|
||||||
|
|
||||||
|
spinlock_release(&lock);
|
||||||
|
|
||||||
if(result) return result;
|
if(result) return result;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -165,16 +192,23 @@ int vfs_mkdir(dirnode_t* ref, char* path, mode_t mode){
|
|||||||
|
|
||||||
char name[512];
|
char name[512];
|
||||||
|
|
||||||
|
spinlock_acquire(&lock);
|
||||||
|
|
||||||
int result = vfs_resolvepath(&buff, &parent, ref, path, name);
|
int result = vfs_resolvepath(&buff, &parent, ref, path, name);
|
||||||
|
|
||||||
if(!parent)
|
if(!parent){
|
||||||
|
spinlock_release(&lock);
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
if(buff)
|
if(buff){
|
||||||
|
spinlock_release(&lock);
|
||||||
return EEXIST;
|
return EEXIST;
|
||||||
|
}
|
||||||
|
|
||||||
result = parent->vnode.fs->calls->mkdir(parent, name, NULL);
|
result = parent->vnode.fs->calls->mkdir(parent, name, NULL);
|
||||||
|
|
||||||
|
spinlock_release(&lock);
|
||||||
|
|
||||||
if(result) return result;
|
if(result) return result;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -191,27 +225,37 @@ int vfs_mount(dirnode_t* ref, char* device, char* mountpoint, char* fs, int moun
|
|||||||
dirnode_t* mountdir = ref;
|
dirnode_t* mountdir = ref;
|
||||||
dirnode_t* parent = NULL;
|
dirnode_t* parent = NULL;
|
||||||
|
|
||||||
|
spinlock_acquire(&lock);
|
||||||
|
|
||||||
if(device){
|
if(device){
|
||||||
dev = ref;
|
dev = ref;
|
||||||
if(*device){
|
if(*device){
|
||||||
int result = vfs_resolvepath(&dev, &parent, ref, device, NULL);
|
int result = vfs_resolvepath(&dev, &parent, ref, device, NULL);
|
||||||
|
|
||||||
if(result)
|
if(result){
|
||||||
|
spinlock_release(&lock);
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int result = vfs_resolvepath(&mountdir, &parent, ref, mountpoint, NULL);
|
int result = vfs_resolvepath(&mountdir, &parent, ref, mountpoint, NULL);
|
||||||
|
|
||||||
if(result)
|
if(result){
|
||||||
|
spinlock_release(&lock);
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
if(GETTYPE(mountdir->vnode.st.st_mode) != TYPE_DIR)
|
if(GETTYPE(mountdir->vnode.st.st_mode) != TYPE_DIR){
|
||||||
|
spinlock_release(&lock);
|
||||||
return ENOTDIR;
|
return ENOTDIR;
|
||||||
|
}
|
||||||
|
|
||||||
result = fscalls->mount(mountdir, dev, mountflags, fsinfo);
|
result = fscalls->mount(mountdir, dev, mountflags, fsinfo);
|
||||||
|
|
||||||
|
spinlock_release(&lock);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user