syscalls: ftruncate

This commit is contained in:
Matheus
2023-07-09 20:48:28 -03:00
parent 7a0bd0747e
commit 1259684ccf
4 changed files with 44 additions and 7 deletions
+3 -1
View File
@@ -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:
+4 -2
View File
@@ -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
+27
View File
@@ -0,0 +1,27 @@
#include <kernel/syscalls.h>
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;
}
+10 -4
View File
@@ -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 <bits/ensure.h>
+#include <mlibc/debug.hpp>
+#include <mlibc/all-sysdeps.hpp>
@@ -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 <stddef.h>
+#include <stdint.h>