mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-31 14:38:21 +00:00
syscalls: fstatat
This commit is contained in:
@@ -24,7 +24,8 @@ extern syscall_getpid
|
|||||||
extern syscall_getdirent
|
extern syscall_getdirent
|
||||||
extern syscall_ioctl
|
extern syscall_ioctl
|
||||||
extern syscall_chdir
|
extern syscall_chdir
|
||||||
func_count equ 23
|
extern syscall_fstatat
|
||||||
|
func_count equ 24
|
||||||
|
|
||||||
|
|
||||||
func_table:
|
func_table:
|
||||||
@@ -51,6 +52,7 @@ func_table:
|
|||||||
dq syscall_getdirent
|
dq syscall_getdirent
|
||||||
dq syscall_ioctl
|
dq syscall_ioctl
|
||||||
dq syscall_chdir
|
dq syscall_chdir
|
||||||
|
dq syscall_fstatat
|
||||||
section .text
|
section .text
|
||||||
global asm_syscall_entry
|
global asm_syscall_entry
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
#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>
|
||||||
|
|
||||||
|
#define AT_FDCWD -100
|
||||||
|
|
||||||
|
syscallret syscall_fstatat(int ifd, char* path, stat* st, int flags){
|
||||||
|
syscallret retv;
|
||||||
|
retv.ret = -1;
|
||||||
|
|
||||||
|
if(flags){
|
||||||
|
retv.errno = EINVAL;
|
||||||
|
return retv;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(st > USER_SPACE_END || path > USER_SPACE_END){
|
||||||
|
retv.errno = EFAULT;
|
||||||
|
return retv;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t len = strlen(path);
|
||||||
|
|
||||||
|
char buff[len+1];
|
||||||
|
|
||||||
|
strcpy(buff, path);
|
||||||
|
|
||||||
|
proc_t* proc = arch_getcls()->thread->proc;
|
||||||
|
|
||||||
|
dirnode_t* targnode;
|
||||||
|
fd_t* fd;
|
||||||
|
|
||||||
|
if(ifd != AT_FDCWD){
|
||||||
|
|
||||||
|
|
||||||
|
int err = fd_access(&proc->fdtable, &fd, ifd);
|
||||||
|
|
||||||
|
if(err){
|
||||||
|
retv.errno = err;
|
||||||
|
return retv;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(buff[0] != '/' && GETTYPE(fd->mode) != TYPE_DIR){
|
||||||
|
retv.errno = ENOTDIR;
|
||||||
|
goto _fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
targnode = fd->node;
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
targnode = proc->cwd;
|
||||||
|
|
||||||
|
|
||||||
|
vnode_t* node;
|
||||||
|
|
||||||
|
retv.errno = vfs_open(&node, buff[0] == '/' ? proc->root : targnode, buff);
|
||||||
|
|
||||||
|
if(retv.errno)
|
||||||
|
goto _fail;
|
||||||
|
|
||||||
|
|
||||||
|
memcpy(st, &node->st, sizeof(stat)); // XXX user memcpy
|
||||||
|
|
||||||
|
vfs_close(node);
|
||||||
|
|
||||||
|
_fail:
|
||||||
|
|
||||||
|
if(ifd != AT_FDCWD)
|
||||||
|
fd_release(fd);
|
||||||
|
|
||||||
|
retv.ret = 0;
|
||||||
|
|
||||||
|
return retv;
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user