diff --git a/Makefile.build b/Makefile.build index 0810c23211f18d2e5061f89b0ae00b483078f7bd..30d709bed0682faf702cab87e8fe75b2e85cffd3 100644 --- a/Makefile.build +++ b/Makefile.build @@ -66,6 +66,7 @@ userprog_SRC += userprog/syscall_exec.c userprog_SRC += userprog/syscall_exit.c userprog_SRC += userprog/syscall_halt.c userprog_SRC += userprog/syscall_wait.c +userprog_SRC += userprog/syscall_create.c # No virtual memory code yet. #vm_SRC = vm/file.c # Some file. diff --git a/examples/Makefile b/examples/Makefile index 41a663d610cb89d30b7aa0277a644b0f63a2c0c5..f2243272fdebdd343b5ed47bcd38afbd8a1c3087 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -4,7 +4,7 @@ SRCDIR = .. # To add a new test, put its name on the PROGS list # and then add a name_SRC line that lists its source files. PROGS = cat cmp cp echo halt hex-dump ls mcat mcp mkdir pwd rm shell \ - bubsort insult lineup matmult recursor my + bubsort insult lineup matmult recursor my touch # Should work from project 2 onward. cat_SRC = cat.c @@ -31,5 +31,8 @@ mkdir_SRC = mkdir.c pwd_SRC = pwd.c shell_SRC = shell.c +# Joshua Saxby special additions! +touch_SRC = touch.c + include $(SRCDIR)/Make.config include $(SRCDIR)/Makefile.userprog diff --git a/examples/touch b/examples/touch new file mode 100755 index 0000000000000000000000000000000000000000..0d81b3ea3dccb90bf0a39ad1b64cfed65f0da0ca Binary files /dev/null and b/examples/touch differ diff --git a/examples/touch.c b/examples/touch.c new file mode 100644 index 0000000000000000000000000000000000000000..d6d3684b61a5834637541a6313e9100eaaea3333 --- /dev/null +++ b/examples/touch.c @@ -0,0 +1,16 @@ +/* touch.c + + Creates an empty file with the name given on the command-line. + + Author: Joshua Saxby + +*/ + +#include <stdio.h> +#include <syscall.h> + +int main (int argc, char *argv[]) { + if (argc != 2) exit(1); // very basic error-handling + char* filename = argv[1]; + return create(filename, 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/userprog/syscall.c b/userprog/syscall.c index 0c4d8cf5c0bb0c96c5115e1b1a6d875959b69e0e..e96679fee225a048692debc300481ab70aba9dc6 100644 --- a/userprog/syscall.c +++ b/userprog/syscall.c @@ -67,6 +67,9 @@ syscall_handler (struct intr_frame *f UNUSED) case SYSCALL_WAIT: syscall_wait(f); break; + case SYSCALL_CREATE: + syscall_create(f); + break; default: printf ("WARNING: Invalid Syscall (%d)\n", syscall_number); } diff --git a/userprog/syscall_create.c b/userprog/syscall_create.c new file mode 100644 index 0000000000000000000000000000000000000000..dc631c0de393243e99bc0f5ed64a49b0c89c6c45 --- /dev/null +++ b/userprog/syscall_create.c @@ -0,0 +1,15 @@ +/* + * The Create System Call + * + * Authored by Joshua Saxby + */ +#include "filesys/filesys.h" +#include "system_calls.h" +#include "threads/interrupt.h" + +void syscall_create(struct intr_frame *f) { + // first argument is syscall code (already handled) + char* filename = (void*)(*((int*)f->esp + 1)); // filename is second argument + unsigned initial_size = *((unsigned*)((int*)f->esp + 2)); // third + f->eax = filesys_create(filename, initial_size); +} diff --git a/userprog/system_calls.h b/userprog/system_calls.h index c8b55188d39c5f70ddb72d15d790c69be3678ec5..6fadcd1f7e3d556e4884521bb746da97de11b6e0 100644 --- a/userprog/system_calls.h +++ b/userprog/system_calls.h @@ -29,6 +29,12 @@ void syscall_exec(struct intr_frame *f); */ void syscall_wait(struct intr_frame *f); +/* + * Creates a new file called file initially initial_size bytes in size. + * Returns true if successful, false otherwise. + */ +void syscall_create(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.