mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
syscalls: fstat
This commit is contained in:
@@ -12,7 +12,8 @@ extern syscall_close
|
||||
extern syscall_isatty
|
||||
extern syscall_write
|
||||
extern syscall_stat
|
||||
func_count equ 11
|
||||
extern syscall_fstat
|
||||
func_count equ 12
|
||||
|
||||
|
||||
func_table:
|
||||
@@ -27,6 +28,7 @@ func_table:
|
||||
dq syscall_isatty
|
||||
dq syscall_write
|
||||
dq syscall_stat
|
||||
dq syscall_fstat
|
||||
section .text
|
||||
global asm_syscall_entry
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
#include <kernel/syscalls.h>
|
||||
#include <sys/stat.h>
|
||||
#include <kernel/fd.h>
|
||||
#include <arch/cls.h>
|
||||
#include <kernel/vfs.h>
|
||||
#include <arch/spinlock.h>
|
||||
#include <string.h>
|
||||
|
||||
syscallret syscall_fstat(int ifd, stat* st){
|
||||
syscallret retv;
|
||||
retv.ret = -1;
|
||||
|
||||
if(st > USER_SPACE_END){
|
||||
retv.errno = EFAULT;
|
||||
return retv;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
memcpy(st, &fd->node->st, sizeof(stat)); // XXX user memcpy
|
||||
|
||||
spinlock_release(&fd->lock);
|
||||
|
||||
retv.errno = 0;
|
||||
retv.ret = 0;
|
||||
|
||||
return retv;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user