Skip to content
Snippets Groups Projects
Commit 7c88e2cf authored by y2-binyahya's avatar y2-binyahya
Browse files

created open syscall function

parent 7d2910dd
Branches
No related tags found
No related merge requests found
......@@ -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 ();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment