Skip to content
Snippets Groups Projects
Commit 26a45135 authored by ja3-saxby's avatar ja3-saxby
Browse files

Merge branch 'Alex/21-implement-filesize-system-call' into 'feature/system-calls'

Implemented filesize system call

See merge request !6
parents a952dffb 88ff6a98
Branches
No related tags found
2 merge requests!22Merge Feature/system calls,!6Implemented filesize system call
......@@ -79,6 +79,9 @@ syscall_handler (struct intr_frame *f UNUSED)
case SYSCALL_OPEN:
syscall_open(f);
break;
case SYSCALL_FILESIZE:
syscall_filesize(f);
break;
default:
printf ("WARNING: Invalid Syscall (%d)\n", syscall_number);
thread_exit ();
......
/*
* Returns the size, in bytes, of the file open as fd.
*
* Authored by Alex Stratford
*/
#include "system_calls.h"
#include "filesys/file.h"
void syscall_filesize(struct intr_frame *f) {
// pop off first int argument from interrupt frame
int file_descriptor = *((int*)f->esp + 1);
struct file *file = get_associated_file_pointer(file_descriptor);
if (file == NULL) { // Checking if file is empty or non-existent
f->eax -1; // Returning failure state
}
// Using the file_length function in file.h to get the length and store it
int size = file_length(file);
f->eax = size;
}
\ No newline at end of file
......@@ -49,6 +49,11 @@ void syscall_write(struct intr_frame *f);
*/
void syscall_open(struct intr_frame *f);
/*
* Returns the size, in bytes, of the file open as fd.
*/
void syscall_filesize(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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment