From 7c88e2cf4b68cbb4ffd86b848a3265cea9419c14 Mon Sep 17 00:00:00 2001 From: y2-binyahya <yasser2.binyahya@live.uwe.ac.uk> Date: Sun, 9 Jul 2023 17:06:02 +0000 Subject: [PATCH] created open syscall function --- src/userprog/syscall.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index 1e17a78..7980ce5 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -63,5 +63,31 @@ syscall_handler (struct intr_frame *f UNUSED) break; } */ + + case SYS_OPEN: { //calls at point=6 + // Retrieve the actual file name argument from the user program's stack to be opened + // this line of code will not work if our team membre did not finish the stack code + const char* file_name = (const char*) get_user((const uint8_t*)f->esp + 4); + + // Check if the file name pointer is valid and accessible + if (!file_name || !is_user_vaddr(file_name)) { + thread_exit(); // Terminate the thread if the pointer is invalid + } + + // Open the file using the file system + struct file* file_obj = filesys_open(file_name); + + // Check if the file opening was successful + if (!file_obj) { + f->eax = -1; // Return -1 to indicate failure + } else { + + int fd = process_add_file(file_obj); + // Return the file descriptor to the user program + f->eax = fd; + } + + break; +} thread_exit (); } -- GitLab