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

Fixed issues

parent ce3d20cf
Branches
No related tags found
2 merge requests!22Merge Feature/system calls,!6Implemented filesize system call
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
#include "system_calls.h" #include "system_calls.h"
#include "threads/interrupt.h" #include "threads/interrupt.h"
#include "threads/thread.h" #include "threads/thread.h"
// Dependency for list_elem struct and list_next / is_tail functions
#include "lib/kernel/list.h"
/* System call numbers. */ /* System call numbers. */
...@@ -60,6 +58,9 @@ syscall_handler (struct intr_frame *f UNUSED) ...@@ -60,6 +58,9 @@ syscall_handler (struct intr_frame *f UNUSED)
case SYSCALL_HALT: case SYSCALL_HALT:
syscall_halt(f); syscall_halt(f);
break; break;
case SYSCALL_EXIT:
syscall_exit(f);
break;
case SYSCALL_EXEC: case SYSCALL_EXEC:
syscall_exec(f); syscall_exec(f);
break; break;
...@@ -69,11 +70,14 @@ syscall_handler (struct intr_frame *f UNUSED) ...@@ -69,11 +70,14 @@ syscall_handler (struct intr_frame *f UNUSED)
case SYSCALL_CREATE: case SYSCALL_CREATE:
syscall_create(f); syscall_create(f);
break; break;
case SYSCALL_REMOVE:
syscall_remove(f);
break;
case SYSCALL_WRITE: case SYSCALL_WRITE:
syscall_write(f); syscall_write(f);
break; break;
case SYSCALL_FILESIZE: case SYSCALL_OPEN:
syscall_filesize(f); syscall_open(f);
break; break;
default: default:
printf ("WARNING: Invalid Syscall (%d)\n", syscall_number); printf ("WARNING: Invalid Syscall (%d)\n", syscall_number);
......
#include "filesys/file.h" #include "filesys/file.h"
#include "threads/interrupt.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() * Terminates Pintos by calling shutdown_power_off()
...@@ -18,6 +7,14 @@ struct file_map ...@@ -18,6 +7,14 @@ struct file_map
*/ */
void syscall_halt(struct intr_frame *f); void syscall_halt(struct intr_frame *f);
/*
* Terminates the current user program, returning status to the kernel. If the
* process's parent waits for it (see below), this is the status that will be
* returned. Conventionally, a status of 0 indicates success and nonzero
* values indicate errors.
*/
void syscall_exit(struct intr_frame *f);
/* /*
* Runs the executable whose name is given in cmd_line, passing any given * Runs the executable whose name is given in cmd_line, passing any given
* arguments, and returns the new process's program id (pid). Must return pid * arguments, and returns the new process's program id (pid). Must return pid
...@@ -34,11 +31,41 @@ void syscall_exec(struct intr_frame *f); ...@@ -34,11 +31,41 @@ void syscall_exec(struct intr_frame *f);
void syscall_wait(struct intr_frame *f); void syscall_wait(struct intr_frame *f);
/* /*
* Returns the size, in bytes, of the file open as fd. * Creates a new file called file initially initial_size bytes in size.
* Returns true if successful, false otherwise.
*/
void syscall_create(struct intr_frame *f);
/*
* Writes size bytes from buffer to the open file fd.
* Returns the number of bytes actually written, which may be less than size if
* some bytes could not be written.
*/ */
void syscall_filesize(struct intr_frame *f) void syscall_write(struct intr_frame *f);
/* /*
* NOTE: There are more system calls implemented by Pintos but we are not * Opens the file called file. Returns a nonnegative integer handle called a
* implementing them because the assignment brief does not ask of it. * "file descriptor" (fd), or -1 if the file could not be opened.
*/ */
void syscall_open(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
*/
// returns NULL if the given file descriptor does not match a known file
struct file * get_associated_file_pointer(int fd);
// remembers the given file, and returns int of file descriptor
// returns -1 if could not store it (means we've opened too many files)
int associate_new_file_descriptor(struct file* file_pointer);
// disassociates the given file descriptor (and its associated pointer)
// returns false if this failed for some reason
bool disassociate_file_descriptor(int fd);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment