close syscall

This commit is contained in:
Matheus
2022-08-19 22:54:07 -03:00
parent 9e3f0b5c3f
commit fc7986e5be
3 changed files with 50 additions and 2 deletions
+3 -1
View File
@@ -8,7 +8,8 @@ extern syscall_gettid
extern syscall_open
extern syscall_read
extern syscall_lseek
func_count equ 6
extern syscall_close
func_count equ 8
func_table:
@@ -19,6 +20,7 @@ func_table:
dq syscall_open
dq syscall_read
dq syscall_lseek
dq syscall_close
section .text
global asm_syscall_entry
+1 -1
View File
@@ -69,7 +69,7 @@ static int tmpfs_read(int *error, vnode_t* node, void* buff, size_t count, size_
static int tmpfs_unmount(fs_t* fs) UNIMPLEMENTED
static int tmpfs_open(dirnode_t* parent, char* name){ return ENOENT;} // tmpfs open should never be called if a file exists
static int tmpfs_close(vnode_t* node) UNIMPLEMENTED
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){
+46
View File
@@ -0,0 +1,46 @@
#include <kernel/syscalls.h>
#include <kernel/fd.h>
#include <arch/cls.h>
#include <kernel/vfs.h>
#include <arch/spinlock.h>
syscallret syscall_close(int ifd){
syscallret retv;
retv.ret = -1;
proc_t* proc = arch_getcls()->thread->proc;
fd_t* fd = proc->fds + ifd;
spinlock_acquire(&proc->fdlock);
if(proc->fdcount <= ifd || fd->node == NULL || (fd->flags & FD_FLAGS_READ) == 0){
spinlock_release(&proc->fdlock);
retv.errno = EBADF;
return retv;
}
spinlock_acquire(&fd->lock);
spinlock_release(&proc->fdlock);
int ret = vfs_close(fd->node);
if(ret){
retv.errno = ret;
goto _ret;
}
// the fd table isn't resized on a close
// although that can be added if it becomes an issue
fd->node = NULL;
retv.ret = 0;
retv.errno = 0;
_ret:
spinlock_release(&fd->lock);
return retv;
}