diff --git a/kernel-src/arch/x86-64/syscall.asm b/kernel-src/arch/x86-64/syscall.asm index 292cf9f3..bf952daa 100644 --- a/kernel-src/arch/x86-64/syscall.asm +++ b/kernel-src/arch/x86-64/syscall.asm @@ -35,6 +35,7 @@ extern syscall_fchmodat extern syscall_umask extern syscall_poll extern syscall_nanosleep +extern syscall_ftruncate syscalltab: dq syscall_print dq syscall_mmap @@ -72,7 +73,8 @@ dq syscall_fchmodat dq syscall_umask dq syscall_poll dq syscall_nanosleep -syscallcount equ 36 +dq syscall_ftruncate +syscallcount equ 37 section .text global arch_syscall_entry ; on entry: diff --git a/kernel-src/arch/x86-64/syscalllog.c b/kernel-src/arch/x86-64/syscalllog.c index 6df52584..b33878a0 100644 --- a/kernel-src/arch/x86-64/syscalllog.c +++ b/kernel-src/arch/x86-64/syscalllog.c @@ -43,7 +43,8 @@ static char *name[] = { "fchmodat", "umask", "poll", - "nanosleep" + "nanosleep", + "ftruncate" }; static char *args[] = { @@ -82,7 +83,8 @@ static char *args[] = { "dirfd %d path %s mode %o flags %d", // fchmodat "mode %o", // umask "fds %p nfds %d timeout %d", // poll - "time %p remaining %p" // nanosleep + "time %p remaining %p", // nanosleep + "fd %d size %lu" // ftruncate }; #endif diff --git a/kernel-src/sys/syscalls/truncate.c b/kernel-src/sys/syscalls/truncate.c new file mode 100644 index 00000000..474627c4 --- /dev/null +++ b/kernel-src/sys/syscalls/truncate.c @@ -0,0 +1,27 @@ +#include + +syscallret_t syscall_ftruncate(int fd, size_t size) { + syscallret_t ret = { + .ret = -1 + }; + + file_t *file = fd_get(fd); + if (file == NULL) { + ret.errno = EBADF; + return ret; + } + + if ((file->flags & FILE_WRITE) == 0 || file->vnode->type != V_TYPE_REGULAR) { + ret.errno = EINVAL; + goto cleanup; + } + + ret.errno = VOP_RESIZE(file->vnode, size, &_cpu()->thread->proc->cred); + ret.ret = ret.errno ? -1 : 0; + + cleanup: + + fd_release(file); + + return ret; +} diff --git a/patches/mlibc/jinx-working-patch.patch b/patches/mlibc/jinx-working-patch.patch index b753503d..b218d56f 100644 --- a/patches/mlibc/jinx-working-patch.patch +++ b/patches/mlibc/jinx-working-patch.patch @@ -133,10 +133,10 @@ index 0000000..e5b087a + diff --git mlibc-workdir/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp new file mode 100644 -index 0000000..22db6d2 +index 0000000..f7b6375 --- /dev/null +++ mlibc-workdir/sysdeps/astral/generic/generic.cpp -@@ -0,0 +1,438 @@ +@@ -0,0 +1,443 @@ +#include +#include +#include @@ -216,6 +216,11 @@ index 0000000..22db6d2 + return 0; + } + ++ int sys_ftruncate(int fd, size_t size) { ++ long ret; ++ return syscall(SYSCALL_FTRUNCATE, &ret, fd, size); ++ } ++ + int sys_sleep(time_t *secs, long *nanos) { + struct timespec ts; + ts.tv_sec = *secs; @@ -594,10 +599,10 @@ index 0000000..990eca0 +#endif diff --git mlibc-workdir/sysdeps/astral/include/astral/syscall.h mlibc-workdir/sysdeps/astral/include/astral/syscall.h new file mode 100644 -index 0000000..4426771 +index 0000000..76b4800 --- /dev/null +++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h -@@ -0,0 +1,59 @@ +@@ -0,0 +1,60 @@ +#ifndef _SYSCALL_H_INCLUDE +#define _SYSCALL_H_INCLUDE + @@ -637,6 +642,7 @@ index 0000000..4426771 +#define SYSCALL_UMASK 33 +#define SYSCALL_POLL 34 +#define SYSCALL_NANOSLEEP 35 ++#define SYSCALL_FTRUNCATE 36 + +#include +#include