From 4157d6d9b2456362badf972258dbfc33fc5c9c6e Mon Sep 17 00:00:00 2001
From: Alex Stratford <alexander3.stratford@live.uwe.ac.uk>
Date: Wed, 4 Dec 2019 15:56:43 +0000
Subject: [PATCH] Fixed issues

---
 userprog/syscall.c      | 22 +++++++++------
 userprog/system_calls.h | 61 +++++++++++++++++++++++++++++------------
 2 files changed, 57 insertions(+), 26 deletions(-)

diff --git a/userprog/syscall.c b/userprog/syscall.c
index 945a0e6..a104087 100644
--- a/userprog/syscall.c
+++ b/userprog/syscall.c
@@ -4,8 +4,6 @@
 #include "system_calls.h"
 #include "threads/interrupt.h"
 #include "threads/thread.h"
-// Dependency for list_elem struct and list_next / is_tail functions
-#include "lib/kernel/list.h"
 
 
 /* System call numbers. */
@@ -60,6 +58,9 @@ syscall_handler (struct intr_frame *f UNUSED)
   case SYSCALL_HALT:
     syscall_halt(f);
     break;
+  case SYSCALL_EXIT:
+    syscall_exit(f);
+    break;
   case SYSCALL_EXEC:
     syscall_exec(f);
     break;
@@ -68,15 +69,18 @@ syscall_handler (struct intr_frame *f UNUSED)
     break;
   case SYSCALL_CREATE:
     syscall_create(f);
-    break;
+	break;
+  case SYSCALL_REMOVE:
+	syscall_remove(f);
+	break;
   case SYSCALL_WRITE:
     syscall_write(f);
     break;
-  case SYSCALL_FILESIZE:
-	  syscall_filesize(f);
-	  break;
+  case SYSCALL_OPEN:
+    syscall_open(f);
+	break;
   default:
     printf ("WARNING: Invalid Syscall (%d)\n", syscall_number);
-	thread_exit();
-  }  
-}
\ No newline at end of file
+    thread_exit ();
+  }
+}
diff --git a/userprog/system_calls.h b/userprog/system_calls.h
index c063331..8dc87c9 100644
--- a/userprog/system_calls.h
+++ b/userprog/system_calls.h
@@ -1,16 +1,5 @@
 #include "filesys/file.h"
 #include "threads/interrupt.h"
-#include "lib/kernel/list.h" // Added due to dependency for list_elem
-#include "filesys/file.c" // Added due to dependency for file
-
-// Maps file descriptions to the associated file structure
-struct file_map
-{
-	struct list_elem list_element; // Defined in list.h
-	int file_descriptor;
-	struct file *file; // Defined in file.c
-};
-
 
 /*
  * Terminates Pintos by calling shutdown_power_off()
@@ -18,6 +7,14 @@ struct file_map
  */
 void syscall_halt(struct intr_frame *f);
 
+/*
+ * Terminates the current user program, returning status to the kernel. If the
+ * process's parent waits for it (see below), this is the status that will be
+ * returned. Conventionally, a status of 0 indicates success and nonzero
+ * values indicate errors. 
+ */
+void syscall_exit(struct intr_frame *f);
+
 /*
  * Runs the executable whose name is given in cmd_line, passing any given
  * arguments, and returns the new process's program id (pid). Must return pid
@@ -34,11 +31,41 @@ void syscall_exec(struct intr_frame *f);
 void syscall_wait(struct intr_frame *f);
 
 /*
-* Returns the size, in bytes, of the file open as fd.
-*/
-void syscall_filesize(struct intr_frame *f)
+ * Creates a new file called file initially initial_size bytes in size.
+ * Returns true if successful, false otherwise.
+ */
+void syscall_create(struct intr_frame *f);
+
+/*
+ * Writes size bytes from buffer to the open file fd.
+ * Returns the number of bytes actually written, which may be less than size if
+ * some bytes could not be written.
+ */
+void syscall_write(struct intr_frame *f);
 
 /*
- * NOTE: There are more system calls implemented by Pintos but we are not
- * implementing them because the assignment brief does not ask of it.
- */
\ No newline at end of file
+ * Opens the file called file. Returns a nonnegative integer handle called a
+ * "file descriptor" (fd), or -1 if the file could not be opened.
+ */
+void syscall_open(struct intr_frame *f);
+
+/*
+ * Deletes the file called file. Returns true if successful, false otherwise.
+ * A file may be removed regardless of whether it is open or closed, and
+ * Removing an open file does not close it. See Removing an Open File, for
+ * Details.
+ */
+void syscall_remove(struct intr_frame *f);
+
+/*
+ * special additional stuff for handling file descriptors because they're annoying
+ */
+
+// returns NULL if the given file descriptor does not match a known file
+struct file * get_associated_file_pointer(int fd);
+// remembers the given file, and returns int of file descriptor
+// returns -1 if could not store it (means we've opened too many files)
+int associate_new_file_descriptor(struct file* file_pointer);
+// disassociates the given file descriptor (and its associated pointer)
+// returns false if this failed for some reason
+bool disassociate_file_descriptor(int fd);
-- 
GitLab