fd: new abstraction

This commit is contained in:
Matheus
2022-09-18 16:21:19 -03:00
parent 73a8584a72
commit 41d6e7230e
11 changed files with 216 additions and 151 deletions
+6 -29
View File
@@ -6,40 +6,17 @@
syscallret syscall_close(int ifd){
syscallret retv;
retv.ret = -1;
retv.ret = 0;
retv.errno = 0;
proc_t* proc = arch_getcls()->thread->proc;
fd_t* fd = proc->fds + ifd;
int err = fd_free(&proc->fdtable, 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;
if(err){
retv.errno = err;
retv.ret = -1;
}
// 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;
}