diff --git a/Makefile.build b/Makefile.build index c22507de4cc178d2a20a1298e4c3ee6531769dce..d136a6f1c1e8fbc60df45bc898ef0d96fd7f53ed 100644 --- a/Makefile.build +++ b/Makefile.build @@ -68,6 +68,7 @@ userprog_SRC += userprog/syscall_open.c userprog_SRC += userprog/syscall_halt.c userprog_SRC += userprog/syscall_wait.c userprog_SRC += userprog/syscall_create.c +userprog_SRC += userprog/syscall_remove.c userprog_SRC += userprog/syscall_write.c userprog_SRC += userprog/file_descriptors_map.c userprog_SRC += userprog/syscall_read.c diff --git a/userprog/syscall.c b/userprog/syscall.c index cb02bce9aeaffc86b8d5fc331b2ad6bae40fbb4f..fb62a79e4a8e648b19c08c774ef33dfcef5ca417 100644 --- a/userprog/syscall.c +++ b/userprog/syscall.c @@ -69,16 +69,22 @@ syscall_handler (struct intr_frame *f UNUSED) break; case SYSCALL_CREATE: syscall_create(f); - break; + break; + case SYSCALL_REMOVE: + syscall_remove(f); + break; case SYSCALL_WRITE: syscall_write(f); break; case SYSCALL_OPEN: syscall_open(f); - break; + break; case SYSCALL_READ: syscall_read(f); break; + case SYSCALL_FILESIZE: + syscall_filesize(f); + break; default: printf ("WARNING: Invalid Syscall (%d)\n", syscall_number); thread_exit (); diff --git a/userprog/syscall_close.c b/userprog/syscall_close.c index 1448e04184e60f0cec1d29bd2d99740032de6e05..651173b53910e646cfe56c9417fe49a87d495939 100644 --- a/userprog/syscall_close.c +++ b/userprog/syscall_close.c @@ -22,9 +22,7 @@ void syscall_close(struct intr_frame *f) { return; } // Close the file using file_close, defined in file.h - file_close(file); - if (disassociate_file_descriptor(file_descriptor) == false) { // Checking if file is empty or non-existent - f->eax = -1; // Returning a failure state - return; - } + file_close(file); + // Remove the file_descriptor + disassociate_file_descriptor(file_descriptor); } \ No newline at end of file diff --git a/userprog/syscall_filesize.c b/userprog/syscall_filesize.c new file mode 100644 index 0000000000000000000000000000000000000000..ae8e45a80bf0e1ed618a6d54c5c416deacae49dd --- /dev/null +++ b/userprog/syscall_filesize.c @@ -0,0 +1,20 @@ +/* + * Returns the size, in bytes, of the file open as fd. + * + * Authored by Alex Stratford + */ + +#include "system_calls.h" +#include "filesys/file.h" + +void syscall_filesize(struct intr_frame *f) { + // pop off first int argument from interrupt frame + int file_descriptor = *((int*)f->esp + 1); + struct file *file = get_associated_file_pointer(file_descriptor); + if (file == NULL) { // Checking if file is empty or non-existent + f->eax -1; // Returning failure state + } + // Using the file_length function in file.h to get the length and store it + int size = file_length(file); + f->eax = size; +} \ No newline at end of file diff --git a/userprog/syscall_open.c b/userprog/syscall_open.c index fcbbe06e7b871a726c740ffe5ada079184f31984..54631b762fc52947d9d900a9cc722185b2f9334a 100644 --- a/userprog/syscall_open.c +++ b/userprog/syscall_open.c @@ -14,7 +14,7 @@ void syscall_open(struct intr_frame *f) { // pop off first int argument from interrupt frame - char* file_name = (void*)(*(int*)f->esp + 1); + 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 diff --git a/userprog/syscall_remove.c b/userprog/syscall_remove.c new file mode 100644 index 0000000000000000000000000000000000000000..0b8d308cc49e759c008275f9b9eaba0c4a5bdab6 --- /dev/null +++ b/userprog/syscall_remove.c @@ -0,0 +1,25 @@ +/* + * Deletes the file called file. Returns true if successful, false otherwise. + * A file may be removed regardless of whether it is open or closed, and + * Removing an open file does not close it. See Removing an Open File, for + * Details. + * + * 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_remove + +void syscall_remove(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 + if (filesys_remove(file_name) == false) { // Checking if file is empty or non-existent + f->eax = false; // Returning a failure state + return; + } + f->eax = true; +} diff --git a/userprog/system_calls.h b/userprog/system_calls.h index 136c4e140801de91bece921efaedc54d0d9226d3..b22867040cc55488aa61fdffd7dca93e74638288 100644 --- a/userprog/system_calls.h +++ b/userprog/system_calls.h @@ -57,9 +57,17 @@ void syscall_write(struct intr_frame *f); void syscall_open(struct intr_frame *f); /* - * NOTE: There are more system calls implemented by Pintos but we are not - * implementing them because the assignment brief does not ask of it. + * Returns the size, in bytes, of the file open as fd. */ +void syscall_filesize(struct intr_frame *f); + +/* + * Deletes the file called file. Returns true if successful, false otherwise. + * A file may be removed regardless of whether it is open or closed, and + * Removing an open file does not close it. See Removing an Open File, for + * Details. + */ +void syscall_remove(struct intr_frame *f); /* * special additional stuff for handling file descriptors because they're annoying