mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 06:58:22 +00:00
close syscall
This commit is contained in:
@@ -8,7 +8,8 @@ extern syscall_gettid
|
|||||||
extern syscall_open
|
extern syscall_open
|
||||||
extern syscall_read
|
extern syscall_read
|
||||||
extern syscall_lseek
|
extern syscall_lseek
|
||||||
func_count equ 6
|
extern syscall_close
|
||||||
|
func_count equ 8
|
||||||
|
|
||||||
|
|
||||||
func_table:
|
func_table:
|
||||||
@@ -19,6 +20,7 @@ func_table:
|
|||||||
dq syscall_open
|
dq syscall_open
|
||||||
dq syscall_read
|
dq syscall_read
|
||||||
dq syscall_lseek
|
dq syscall_lseek
|
||||||
|
dq syscall_close
|
||||||
section .text
|
section .text
|
||||||
global asm_syscall_entry
|
global asm_syscall_entry
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -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_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_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){
|
static int tmpfs_mkdir(dirnode_t* parent, char* name, mode_t mode){
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user