summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-03-14 14:54:47 +0100
committerGustav Sörnäs <gustav@sornas.net>2021-03-14 14:54:47 +0100
commit95ef749e393eae8e3ea578fa69f88eaa1987580e (patch)
treee99f0cabe7f1ce1e3048ebf33f3c7216db7a3269
parent548f7b19415640ad44502ef9ccb42c98bd92b6d1 (diff)
downloadpintos-95ef749e393eae8e3ea578fa69f88eaa1987580e.tar.gz
implement syscalls for lab 6
-rw-r--r--src/userprog/build/fail4
-rw-r--r--src/userprog/syscall.c30
2 files changed, 26 insertions, 8 deletions
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;
}