From f5b06759464e6b14a114ed74194805cfe66f00c3 Mon Sep 17 00:00:00 2001 From: Alex Stratford <alexander3.stratford@live.uwe.ac.uk> Date: Mon, 2 Dec 2019 23:18:02 +0000 Subject: [PATCH] Implemented filesize system call Edited system_calls.h to add common struct --- userprog/syscall_filesize.c | 11 +++++++++++ userprog/system_calls.h | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 userprog/syscall_filesize.c diff --git a/userprog/syscall_filesize.c b/userprog/syscall_filesize.c new file mode 100644 index 0000000..ab74aad --- /dev/null +++ b/userprog/syscall_filesize.c @@ -0,0 +1,11 @@ +#include "system_calls.h" +#include "filesys/file.h" + +int syscall_filesize(struct intr_frame *file_descriptor) { + struct file_map *file_map = get_file(file_descriptor); // Described in system_calls.h, stores file descriptors mapped to files + int size; + if (file_map == NULL) // Checking if file is empty or non-existent + return -1; + size = file_length(file_map->file); // Using the file_length function in file.h to get the length and store it + return size; +} \ No newline at end of file diff --git a/userprog/system_calls.h b/userprog/system_calls.h index 8dc87c9..c1b87c7 100644 --- a/userprog/system_calls.h +++ b/userprog/system_calls.h @@ -1,5 +1,16 @@ #include "filesys/file.h" #include "threads/interrupt.h" +#include "lib/kernel/list.h" // Added due to dependency for list_elem +#include "filesys/file.c" // Added due to dependency for file + +// Maps file descriptions to the associated file structure +struct file_map +{ + struct list_elem list_element; // Defined in list.h + int file_descriptor; + struct file *file; // Defined in file.c +}; + /* * Terminates Pintos by calling shutdown_power_off() -- GitLab