diff --git a/userprog/syscall_filesize.c b/userprog/syscall_filesize.c new file mode 100644 index 0000000000000000000000000000000000000000..ab74aadcacf00c85bc3125bd55b2b77534aae809 --- /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 8dc87c9d325a52ee224a1597b3bfd7877553cf5a..c1b87c754c211cb083172e5e54d69f79151df70c 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()