diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index 1e17a78d53f1c7f8925bf8c95d734755905ba0f6..7980ce5a2aa53df479003f193b4f11119d1a68e0 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 (); }