aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@cs.berkeley.edu>2015-09-14 12:46:54 -0700
committerAndrew Waterman <waterman@cs.berkeley.edu>2015-09-14 12:46:54 -0700
commit4a37572381acc146da66720f1f8073772f2c9119 (patch)
treeeb46aded5af6936491162048160f947ccc91051b
parent18efb61dc4fa2f20ce54cafcf12b12545751dd43 (diff)
downloadpk-4a37572381acc146da66720f1f8073772f2c9119.zip
pk-4a37572381acc146da66720f1f8073772f2c9119.tar.gz
pk-4a37572381acc146da66720f1f8073772f2c9119.tar.bz2
Add ftruncate syscall
-rw-r--r--pk/file.c5
-rw-r--r--pk/file.h1
-rw-r--r--pk/syscall.c15
-rw-r--r--pk/syscall.h1
4 files changed, 22 insertions, 0 deletions
diff --git a/pk/file.c b/pk/file.c
index ad1bde3..ee2f9fd 100644
--- a/pk/file.c
+++ b/pk/file.c
@@ -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);
diff --git a/pk/file.h b/pk/file.h
index 0d942b2..c9f7ce4 100644
--- a/pk/file.h
+++ b/pk/file.h
@@ -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