Skip to content
Snippets Groups Projects
Commit b6f4ad10 authored by a2-stratford's avatar a2-stratford
Browse files

Merge branch 'feature/system-calls' into 'josh/22-read-syscall'

# Conflicts:
#   userprog/syscall.c
#   userprog/system_calls.h
parents cb1f903f 26a45135
No related branches found
No related tags found
2 merge requests!22Merge Feature/system calls,!18Implement read() system call
......@@ -68,6 +68,7 @@ userprog_SRC += userprog/syscall_open.c
userprog_SRC += userprog/syscall_halt.c
userprog_SRC += userprog/syscall_wait.c
userprog_SRC += userprog/syscall_create.c
userprog_SRC += userprog/syscall_remove.c
userprog_SRC += userprog/syscall_write.c
userprog_SRC += userprog/file_descriptors_map.c
userprog_SRC += userprog/syscall_read.c
......
......@@ -70,6 +70,9 @@ syscall_handler (struct intr_frame *f UNUSED)
case SYSCALL_CREATE:
syscall_create(f);
break;
case SYSCALL_REMOVE:
syscall_remove(f);
break;
case SYSCALL_WRITE:
syscall_write(f);
break;
......@@ -79,6 +82,9 @@ syscall_handler (struct intr_frame *f UNUSED)
case SYSCALL_READ:
syscall_read(f);
break;
case SYSCALL_FILESIZE:
syscall_filesize(f);
break;
default:
printf ("WARNING: Invalid Syscall (%d)\n", syscall_number);
thread_exit ();
......
......@@ -23,8 +23,6 @@ void syscall_close(struct intr_frame *f) {
}
// Close the file using file_close, defined in file.h
file_close(file);
if (disassociate_file_descriptor(file_descriptor) == false) { // Checking if file is empty or non-existent
f->eax = -1; // Returning a failure state
return;
}
// Remove the file_descriptor
disassociate_file_descriptor(file_descriptor);
}
\ No newline at end of file
/*
* 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
......@@ -14,7 +14,7 @@
void syscall_open(struct intr_frame *f) {
// pop off first int argument from interrupt frame
char* file_name = (void*)(*(int*)f->esp + 1);
char* file_name = (void*)*((int*)f->esp + 1);
// Described in filesys.h, opens the file
struct file *file = filesys_open(file_name);
if (file == NULL) { // Checking if file is empty or non-existent
......
/*
* 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
* Removing an open file does not close it. See Removing an Open File, for
* Details.
*
* Authored by Alex Stratford
*/
#include "system_calls.h"
#include "threads/interrupt.h" // Dependency for intr_frame struct
#include "filesys/file.h" // Dependency for and file struct
#include "filesys/filesys.h" // Dependency for filesys_remove
void syscall_remove(struct intr_frame *f) {
// pop off first int argument from interrupt frame
char* file_name = (void*)*((int*)f->esp + 1);
// Described in filesys.h, opens the file
if (filesys_remove(file_name) == false) { // Checking if file is empty or non-existent
f->eax = false; // Returning a failure state
return;
}
f->eax = true;
}
......@@ -57,9 +57,17 @@ void syscall_write(struct intr_frame *f);
void syscall_open(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.
* 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
* Removing an open file does not close it. See Removing an Open File, for
* Details.
*/
void syscall_remove(struct intr_frame *f);
/*
* special additional stuff for handling file descriptors because they're annoying
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment