diff --git a/Makefile.build b/Makefile.build index 06c26277e141eb0fe57b90c142ff71a6405e16b0..79cfbd76c0e95a56f8fc986df19340606b0be0bd 100644 --- a/Makefile.build +++ b/Makefile.build @@ -74,6 +74,7 @@ userprog_SRC += userprog/file_descriptors_map.c userprog_SRC += userprog/syscall_read.c userprog_SRC += userprog/syscall_filesize.c userprog_SRC += userprog/syscall_tell.c +userprog_SRC += userprog/syscall_seek.c # No virtual memory code yet. #vm_SRC = vm/file.c # Some file. diff --git a/userprog/syscall.c b/userprog/syscall.c index b38eccabd22439f474267dc7ae12b07bcf7e4bd5..c429f13727aa3c9f0b9a57a7c0de1b9b4d4d821d 100644 --- a/userprog/syscall.c +++ b/userprog/syscall.c @@ -88,6 +88,9 @@ syscall_handler (struct intr_frame *f UNUSED) case SYSCALL_TELL: syscall_tell(f); break; + case SYSCALL_SEEK: + syscall_seek(f); + break; default: printf ("WARNING: Invalid Syscall (%d)\n", syscall_number); thread_exit (); diff --git a/userprog/syscall_seek.c b/userprog/syscall_seek.c new file mode 100644 index 0000000000000000000000000000000000000000..a623496bb1edb00c58b1cdc7001968b19239443c --- /dev/null +++ b/userprog/syscall_seek.c @@ -0,0 +1,22 @@ +/* +* Changes the next byte to be read or written in open file fd to position, +* Expressed in bytes from the beginning of the file. (Thus, a position of 0 +* Is the file�s start.) +* +* Authored by Alex Stratford +*/ + +#include "system_calls.h" +#include <stddef.h> // Dependency for NULL +#include "threads/interrupt.h" // Dependency for intr_frame struct +#include "filesys/file.h" // Dependency for file struct and file_seek function + +void syscall_seek(struct intr_frame *f) { + // pop off first int argument from interrupt frame + int* file_descriptor = (void*)*((int*)f->esp + 1); + // pop off second int argument from interrupt frame + int* file_pos = (void*)(*(int*)f->esp + 2); + struct file *file = get_associated_file_pointer(file_descriptor); + // Seek through the file + file_seek(file, file_pos); +} \ No newline at end of file diff --git a/userprog/system_calls.h b/userprog/system_calls.h index ebeed4c37da16c0d0dfdec3ce5df30f25719bc5e..4f955ad8fbac861dd0bb64d5d7d8af3efec61382 100644 --- a/userprog/system_calls.h +++ b/userprog/system_calls.h @@ -75,6 +75,13 @@ void syscall_remove(struct intr_frame *f); */ void syscall_tell(struct intr_frame *f); +/* +* Changes the next byte to be read or written in open file fd to position, +* Expressed in bytes from the beginning of the file. (Thus, a position of 0 +* Is the file�s start.) +*/ +void syscall_seek(struct intr_frame *f); + /* * special additional stuff for handling file descriptors because they're annoying */