diff --git a/userprog/syscall.c b/userprog/syscall.c index eb1f0341acefb1d466108eb01b599c893a1b75fc..c015dd1cccd641dfeaf08f0ed42a1c1f65ebb50d 100644 --- a/userprog/syscall.c +++ b/userprog/syscall.c @@ -68,10 +68,7 @@ syscall_handler (struct intr_frame *f UNUSED) break; case SYSCALL_CREATE: syscall_create(f); - break; - case SYSCALL_REMOVE: - syscall_remove(f); - break; + break; case SYSCALL_WRITE: syscall_write(f); break; @@ -82,4 +79,34 @@ syscall_handler (struct intr_frame *f UNUSED) printf ("WARNING: Invalid Syscall (%d)\n", syscall_number); 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 diff --git a/userprog/system_calls.h b/userprog/system_calls.h index 1df16bb806876f4ca8cc7d99215d5045b92b0e92..c063331cf819351a84a6d061aad305a5a9c8d4bd 100644 --- a/userprog/system_calls.h +++ b/userprog/system_calls.h @@ -4,6 +4,13 @@ #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() @@ -11,14 +18,6 @@ */ 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 * arguments, and returns the new process's program id (pid). Must return pid @@ -35,41 +34,11 @@ void syscall_exec(struct intr_frame *f); void syscall_wait(struct intr_frame *f); /* - * 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_write(struct intr_frame *f); - -/* - * Opens the file called file. Returns a nonnegative integer handle called a - * "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); +* Returns the size, in bytes, of the file open as fd. +*/ +void syscall_filesize(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); + * NOTE: There are more system calls implemented by Pintos but we are not + * implementing them because the assignment brief does not ask of it. + */ \ No newline at end of file