diff --git a/include/metalsvm/syscall.h b/include/metalsvm/syscall.h index 04390311..fbec1a66 100644 --- a/include/metalsvm/syscall.h +++ b/include/metalsvm/syscall.h @@ -80,6 +80,7 @@ extern "C" { #define __NR_sendto 27 #define __NR_recvfrom 28 #define __NR_select 29 +#define __NR_stat 30 #ifdef __cplusplus } diff --git a/kernel/syscall.c b/kernel/syscall.c index 2618a757..735b0583 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -229,6 +229,13 @@ int syscall_handler(uint32_t sys_nr, ...) ret = sys_close(fd); break; } + case __NR_stat: { + const char* name = va_arg(vl, const char*); + //struct stat* st = va_arg(vl, struct stat*); + + ret = -EINVAL; + break; + } case __NR_read: { int fd = va_arg(vl, int); const char* buf = va_arg(vl, const char*); diff --git a/newlib/net/syscall.h b/newlib/net/syscall.h index 26acb507..5e2416b8 100644 --- a/newlib/net/syscall.h +++ b/newlib/net/syscall.h @@ -69,6 +69,7 @@ extern "C" { #define __NR_sendto 27 #define __NR_recvfrom 28 #define __NR_select 29 +#define __NR_stat 30 #define _STR(token) #token #define _SYSCALLSTR(x) "int $" _STR(x) " " diff --git a/newlib/src/libgloss/metalsvm/stat.c b/newlib/src/libgloss/metalsvm/stat.c index 4ab81546..cb6c39f2 100644 --- a/newlib/src/libgloss/metalsvm/stat.c +++ b/newlib/src/libgloss/metalsvm/stat.c @@ -46,12 +46,25 @@ #undef errno extern int errno; #include "warning.h" +#include "syscall.h" int _DEFUN (stat, (file, st), const char *file _AND struct stat *st) { - st->st_mode = S_IFCHR; + int ret; + + if (!file && ! st) { + errno = EINVAL; + return -1; + } + + ret = SYSCALL2(__NR_stat, file, st); + if (ret < 0) { + errno = -ret; + return -1; + } + return 0; } diff --git a/newlib/src/libgloss/metalsvm/syscall.h b/newlib/src/libgloss/metalsvm/syscall.h index 26acb507..5e2416b8 100644 --- a/newlib/src/libgloss/metalsvm/syscall.h +++ b/newlib/src/libgloss/metalsvm/syscall.h @@ -69,6 +69,7 @@ extern "C" { #define __NR_sendto 27 #define __NR_recvfrom 28 #define __NR_select 29 +#define __NR_stat 30 #define _STR(token) #token #define _SYSCALLSTR(x) "int $" _STR(x) " "