mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-28 13:18:22 +00:00
syscalls: ftruncate
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user