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

Merge

parents 0d9eb700 eccd699a
No related branches found
No related tags found
2 merge requests!22Merge Feature/system calls,!6Implemented filesize system call
...@@ -69,9 +69,6 @@ syscall_handler (struct intr_frame *f UNUSED) ...@@ -69,9 +69,6 @@ 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;
...@@ -83,3 +80,33 @@ syscall_handler (struct intr_frame *f UNUSED) ...@@ -83,3 +80,33 @@ syscall_handler (struct intr_frame *f UNUSED)
thread_exit(); thread_exit();
} }
} }
static struct list *file_list;
/* Goes through all the files in the file_list and looks for the given file
* Descriptor. Linear search
*/
void file_search(struct file_map *f) {
// Creates a struct to hold the currently checked file
struct file_map *curr_file;
// Creates the list element to test for end of list
struct list_elem *list_element;
*list_element = *list_begin(file_list);
// Loop to check each file in the linked list in turn
while ((curr_file->file_descriptor != f->file_descriptor) &&
(is_tail(list_element) == false)
) {
// Swaps the list_element for the next one in place
list_element = list_next(list_element);
}
// Copies list_element to current file
curr_file->list_element = *list_element;
// Checks if file has been found returning NULL if not or the file if it has
if (curr_file->file_descriptor != f->file_descriptor) {
f->file = NULL;
}
else {
f = curr_file;
}
}
\ No newline at end of file
...@@ -4,6 +4,13 @@ ...@@ -4,6 +4,13 @@
#include "filesys/file.c" // Added due to dependency for file #include "filesys/file.c" // Added due to dependency for file
// Maps file descriptions to the associated file structure // 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()
...@@ -11,14 +18,6 @@ ...@@ -11,14 +18,6 @@
*/ */
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
...@@ -35,41 +34,11 @@ void syscall_exec(struct intr_frame *f); ...@@ -35,41 +34,11 @@ void syscall_exec(struct intr_frame *f);
void syscall_wait(struct intr_frame *f); void syscall_wait(struct intr_frame *f);
/* /*
* Creates a new file called file initially initial_size bytes in size. * Returns the size, in bytes, of the file open as fd.
* 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_write(struct intr_frame *f); void syscall_filesize(struct intr_frame *f)
/* /*
* Opens the file called file. Returns a nonnegative integer handle called a * NOTE: There are more system calls implemented by Pintos but we are not
* "file descriptor" (fd), or -1 if the file could not be opened. * implementing them because the assignment brief does not ask of it.
*/ */
\ No newline at end of file
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