From 2d6197e6d39a02e89ac619dd1b6ffecbcc0aa14d Mon Sep 17 00:00:00 2001
From: Alex Stratford <alexander3.stratford@live.uwe.ac.uk>
Date: Tue, 3 Dec 2019 20:25:09 +0000
Subject: [PATCH] Minor bug fixes

---
 userprog/syscall_open.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 userprog/syscall_open.c

diff --git a/userprog/syscall_open.c b/userprog/syscall_open.c
new file mode 100644
index 0000000..8855a8b
--- /dev/null
+++ b/userprog/syscall_open.c
@@ -0,0 +1,26 @@
+/*
+ * Opens the file called file. Returns a nonnegative integer handle called a 
+ * "file descriptor" (fd), or -1 if the file could not be opened.
+ *
+ * Authored by Alex Stratford
+ */
+
+
+#include "system_calls.h"
+#include "threads/interrupt.h" // Dependency for intr_frame struct
+#include "filesys/file.h" // Dependency for and file struct
+#include "filesys/filesys.h" // Dependency for filesys_open
+
+void syscall_open(struct intr_frame *f) {
+	// pop off first int argument from interrupt frame
+	char* file_name = (void*)(*(int*)f->esp + 1);
+	// Described in filesys.h, opens the file
+	struct file *file = filesys_open(file_name);
+	if (file == NULL) { // Checking if file is empty or non-existent
+		f->eax = -1; // Returning a failure state
+		return;
+	}
+	// Described in system_calls.h, get a new file descriptor
+	int file_descriptor = associate_new_file_descriptor(file);
+	f->eax = file_descriptor; // Returning the file descriptor
+}
-- 
GitLab