Skip to content
Snippets Groups Projects
Verified Commit 1df54429 authored by ja3-saxby's avatar ja3-saxby
Browse files

Fix both the close() and seek() system calls

parent a9cf422f
Branches
No related tags found
2 merge requests!22Merge Feature/system calls,!21Implemented the system call seek
...@@ -75,6 +75,7 @@ userprog_SRC += userprog/syscall_read.c ...@@ -75,6 +75,7 @@ userprog_SRC += userprog/syscall_read.c
userprog_SRC += userprog/syscall_filesize.c userprog_SRC += userprog/syscall_filesize.c
userprog_SRC += userprog/syscall_tell.c userprog_SRC += userprog/syscall_tell.c
userprog_SRC += userprog/syscall_seek.c userprog_SRC += userprog/syscall_seek.c
userprog_SRC += userprog/syscall_close.c
# No virtual memory code yet. # No virtual memory code yet.
#vm_SRC = vm/file.c # Some file. #vm_SRC = vm/file.c # Some file.
......
...@@ -91,6 +91,9 @@ syscall_handler (struct intr_frame *f UNUSED) ...@@ -91,6 +91,9 @@ syscall_handler (struct intr_frame *f UNUSED)
case SYSCALL_SEEK: case SYSCALL_SEEK:
syscall_seek(f); syscall_seek(f);
break; break;
case SYSCALL_CLOSE:
syscall_close(f);
break;
default: default:
printf ("WARNING: Invalid Syscall (%d)\n", syscall_number); printf ("WARNING: Invalid Syscall (%d)\n", syscall_number);
thread_exit (); thread_exit ();
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
void syscall_close(struct intr_frame *f) { void syscall_close(struct intr_frame *f) {
// pop off first int argument from interrupt frame // pop off first int argument from interrupt frame
int* file_descriptor = (void*)(*(int*)f->esp + 1); int file_descriptor = *((int*)f->esp + 1);
// Get file associated with file_descriptor // Get file associated with file_descriptor
struct file *file = get_associated_file_pointer(file_descriptor); struct file *file = get_associated_file_pointer(file_descriptor);
if (file == NULL) { // Checking if file is empty or non-existent if (file == NULL) { // Checking if file is empty or non-existent
......
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
void syscall_seek(struct intr_frame *f) { void syscall_seek(struct intr_frame *f) {
// pop off first int argument from interrupt frame // pop off first int argument from interrupt frame
int* file_descriptor = (void*)*((int*)f->esp + 1); int file_descriptor = *((int*)f->esp + 1);
// pop off second int argument from interrupt frame // pop off second int argument from interrupt frame
int* file_pos = (void*)(*(int*)f->esp + 2); unsigned file_pos = *((unsigned*)((int*)f->esp + 2));
struct file *file = get_associated_file_pointer(file_descriptor); struct file *file = get_associated_file_pointer(file_descriptor);
// Seek through the file // Seek through the file
file_seek(file, file_pos); file_seek(file, file_pos);
......
...@@ -82,6 +82,12 @@ void syscall_tell(struct intr_frame *f); ...@@ -82,6 +82,12 @@ void syscall_tell(struct intr_frame *f);
*/ */
void syscall_seek(struct intr_frame *f); void syscall_seek(struct intr_frame *f);
/*
* Closes file descriptor fd. Exiting or terminating a process implicitly closes
* all its open file descriptors, as if by calling this function for each one.
*/
void syscall_close(struct intr_frame *f);
/* /*
* special additional stuff for handling file descriptors because they're annoying * special additional stuff for handling file descriptors because they're annoying
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment