diff --git a/Makefile.build b/Makefile.build index cd6c9f0f5778a81d3814d6a2ad7a68c74b6531ba..2d43ff2d270d8e2caff7a87971321c7e590617ff 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 diff --git a/userprog/syscall.c b/userprog/syscall.c index bfd235f882a10d965eadb22795940873b1d369dd..a104087f96233896df559ed9c72e37c0c3ea2b14 100644 --- a/userprog/syscall.c +++ b/userprog/syscall.c @@ -69,7 +69,10 @@ 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; 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 235183330ee8f1944802728f29ee55337667f6d0..8dc87c9d325a52ee224a1597b3bfd7877553cf5a 100644 --- a/userprog/system_calls.h +++ b/userprog/system_calls.h @@ -49,6 +49,14 @@ void syscall_write(struct intr_frame *f); */ void syscall_open(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 */