diff options
-rw-r--r-- | pk/file.c | 5 | ||||
-rw-r--r-- | pk/file.h | 1 | ||||
-rw-r--r-- | pk/syscall.c | 15 | ||||
-rw-r--r-- | pk/syscall.h | 1 |
4 files changed, 22 insertions, 0 deletions
@@ -145,6 +145,11 @@ int file_stat(file_t* f, struct stat* s) return frontend_syscall(SYS_fstat, f->kfd, (uintptr_t)s, 0, 0, 0, 0, 0); } +int file_truncate(file_t* f, off_t len) +{ + return frontend_syscall(SYS_ftruncate, f->kfd, len, 0, 0, 0, 0, 0); +} + ssize_t file_lseek(file_t* f, size_t ptr, int dir) { return frontend_syscall(SYS_lseek, f->kfd, ptr, dir, 0, 0, 0, 0); @@ -31,6 +31,7 @@ ssize_t file_pread(file_t* f, void* buf, size_t n, off_t off); ssize_t file_write(file_t* f, const void* buf, size_t n); ssize_t file_read(file_t* f, void* buf, size_t n); ssize_t file_lseek(file_t* f, size_t ptr, int dir); +int file_truncate(file_t* f, off_t len); int file_stat(file_t* f, struct stat* s); int fd_close(int fd); diff --git a/pk/syscall.c b/pk/syscall.c index e80535b..2d96282 100644 --- a/pk/syscall.c +++ b/pk/syscall.c @@ -165,6 +165,20 @@ int sys_fcntl(int fd, int cmd, int arg) return r; } +int sys_ftruncate(int fd, off_t len) +{ + int r = -EBADF; + file_t* f = file_get(fd); + + if (f) + { + r = file_truncate(f, len); + file_decref(f); + } + + return r; +} + int sys_dup(int fd) { int r = -EBADF; @@ -446,6 +460,7 @@ long do_syscall(long a0, long a1, long a2, long a3, long a4, long a5, unsigned l [SYS_writev] = sys_writev, [SYS_faccessat] = sys_faccessat, [SYS_fcntl] = sys_fcntl, + [SYS_ftruncate] = sys_ftruncate, [SYS_getdents] = sys_getdents, [SYS_dup] = sys_dup, [SYS_readlinkat] = sys_stub_nosys, diff --git a/pk/syscall.h b/pk/syscall.h index 1619e3e..bed30e9 100644 --- a/pk/syscall.h +++ b/pk/syscall.h @@ -38,6 +38,7 @@ #define SYS_gettimeofday 169 #define SYS_times 153 #define SYS_fcntl 25 +#define SYS_ftruncate 46 #define SYS_getdents 61 #define SYS_dup 23 #define SYS_readlinkat 78 |