From 95ef749e393eae8e3ea578fa69f88eaa1987580e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Sun, 14 Mar 2021 14:54:47 +0100 Subject: implement syscalls for lab 6 --- src/userprog/build/fail | 4 ++++ src/userprog/syscall.c | 30 ++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 src/userprog/build/fail (limited to 'src/userprog') diff --git a/src/userprog/build/fail b/src/userprog/build/fail new file mode 100644 index 0000000..d6016ef --- /dev/null +++ b/src/userprog/build/fail @@ -0,0 +1,4 @@ +FAIL tests/filesys/base/lg-random +FAIL tests/filesys/base/sm-random +FAIL tests/filesys/base/syn-remove +FAIL tests/filesys/base/syn-write diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index 8bdb42b..b9acb17 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -38,7 +38,7 @@ create (const char *filename, off_t initial_size) static bool remove (const char *filename) { - return false; + return filesys_remove (filename); } static int @@ -66,12 +66,6 @@ open (const char *filename) return -1; } -static int -filesize (int fd_i) -{ - return 0; -} - static struct file ** get_fd (struct thread *thread, int fd_i) { @@ -158,15 +152,35 @@ write (int fd_i, const void *buf, unsigned size) } } +static int +filesize (int fd_i) +{ + struct thread *thread = thread_current (); + struct file **fd = get_fd (thread, fd_i); + if (fd && *fd) { + return file_length (*fd); + } + return -1; +} + static void seek (int fd_i, unsigned position) { - return; + struct thread *thread = thread_current (); + struct file **fd = get_fd (thread, fd_i); + if (fd && *fd) { + file_seek (*fd, position); + } } static unsigned tell (int fd_i) { + struct thread *thread = thread_current (); + struct file **fd = get_fd (thread, fd_i); + if (fd && *fd) { + return file_tell (*fd); + } return 0; } -- cgit v1.2.1