bugfixes, change types.h to be linux abi, stat system call

This commit is contained in:
Matheus
2022-08-23 19:44:18 -03:00
parent 9c6ce452f8
commit 023937809d
13 changed files with 92 additions and 44 deletions
-1
View File
@@ -5,7 +5,6 @@
#include <arch/spinlock.h>
syscallret syscall_close(int ifd){
syscallret retv;
retv.ret = -1;
+1 -1
View File
@@ -69,7 +69,7 @@ syscallret syscall_open(const char* pathname, int flags, mode_t mode){
fd->flags = flags + 1; // 1 is added to make O_RDONLY etc easier to lookup
fd->offset = 0;
vnode_t* file;
vnode_t* file = NULL;
size_t ret = vfs_open(&file,
*name == '/' ? proc->root : proc->cwd,
+2
View File
@@ -57,6 +57,8 @@ syscallret syscall_read(int ifd, void* buff, size_t count){
retv.errno = 0;
retv.ret = readc;
free(kbuff);
return retv;
}
+51
View File
@@ -0,0 +1,51 @@
#include <kernel/syscalls.h>
#include <sys/stat.h>
#include <kernel/vmm.h>
#include <errno.h>
#include <kernel/vfs.h>
#include <kernel/sched.h>
#include <arch/cls.h>
#include <kernel/alloc.h>
#include <string.h>
syscallret syscall_stat(const char* path, stat* st){
syscallret retv;
retv.ret = -1;
if(st > USER_SPACE_END){
retv.errno = EFAULT;
return retv;
}
char* kpath = alloc(strlen(path)); // XXX use proper user strlen func
if(!path){
retv.errno = ENOMEM;
return retv;
}
strcpy(kpath, path); // XXX use user strcpy func
vnode_t* file;
proc_t* proc = arch_getcls()->thread->proc;
int ret = vfs_open(&file, *kpath == '/' ? proc->root : proc->cwd, kpath);
if(ret){
retv.errno = ret;
goto _ret;
}
stat stbuff = file->st;
vfs_close(file);
memcpy(st, &stbuff, sizeof(stat)); // XXX use user memcpy
_ret:
free(kpath);
return retv;
}