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

Merge branch 'Alex/24-implement-seek-system-call' into 'feature/system-calls'

Implemented the system call seek

See merge request !21
parents d2743d6b 1df54429
No related branches found
No related tags found
2 merge requests!22Merge Feature/system calls,!21Implemented the system call seek
...@@ -74,6 +74,8 @@ userprog_SRC += userprog/file_descriptors_map.c ...@@ -74,6 +74,8 @@ userprog_SRC += userprog/file_descriptors_map.c
userprog_SRC += userprog/syscall_read.c userprog_SRC += userprog/syscall_read.c
userprog_SRC += userprog/syscall_filesize.c userprog_SRC += userprog/syscall_filesize.c
userprog_SRC += userprog/syscall_tell.c userprog_SRC += userprog/syscall_tell.c
userprog_SRC += userprog/syscall_seek.c
userprog_SRC += userprog/syscall_close.c
# No virtual memory code yet. # No virtual memory code yet.
#vm_SRC = vm/file.c # Some file. #vm_SRC = vm/file.c # Some file.
......
...@@ -88,6 +88,12 @@ syscall_handler (struct intr_frame *f UNUSED) ...@@ -88,6 +88,12 @@ syscall_handler (struct intr_frame *f UNUSED)
case SYSCALL_TELL: case SYSCALL_TELL:
syscall_tell(f); syscall_tell(f);
break; break;
case SYSCALL_SEEK:
syscall_seek(f);
break;
case SYSCALL_CLOSE:
syscall_close(f);
break;
default: default:
printf ("WARNING: Invalid Syscall (%d)\n", syscall_number); printf ("WARNING: Invalid Syscall (%d)\n", syscall_number);
thread_exit (); thread_exit ();
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
void syscall_close(struct intr_frame *f) { void syscall_close(struct intr_frame *f) {
// pop off first int argument from interrupt frame // pop off first int argument from interrupt frame
int* file_descriptor = (void*)(*(int*)f->esp + 1); int file_descriptor = *((int*)f->esp + 1);
// Get file associated with file_descriptor // Get file associated with file_descriptor
struct file *file = get_associated_file_pointer(file_descriptor); struct file *file = get_associated_file_pointer(file_descriptor);
if (file == NULL) { // Checking if file is empty or non-existent if (file == NULL) { // Checking if file is empty or non-existent
......
/*
* Changes the next byte to be read or written in open file fd to position,
* Expressed in bytes from the beginning of the file. (Thus, a position of 0
* Is the file’s start.)
*
* Authored by Alex Stratford
*/
#include "system_calls.h"
#include <stddef.h> // Dependency for NULL
#include "threads/interrupt.h" // Dependency for intr_frame struct
#include "filesys/file.h" // Dependency for file struct and file_seek function
void syscall_seek(struct intr_frame *f) {
// pop off first int argument from interrupt frame
int file_descriptor = *((int*)f->esp + 1);
// pop off second int argument from interrupt frame
unsigned file_pos = *((unsigned*)((int*)f->esp + 2));
struct file *file = get_associated_file_pointer(file_descriptor);
// Seek through the file
file_seek(file, file_pos);
}
...@@ -75,6 +75,19 @@ void syscall_remove(struct intr_frame *f); ...@@ -75,6 +75,19 @@ void syscall_remove(struct intr_frame *f);
*/ */
void syscall_tell(struct intr_frame *f); void syscall_tell(struct intr_frame *f);
/*
* Changes the next byte to be read or written in open file fd to position,
* Expressed in bytes from the beginning of the file. (Thus, a position of 0
* Is the file’s start.)
*/
void syscall_seek(struct intr_frame *f);
/*
* Closes file descriptor fd. Exiting or terminating a process implicitly closes
* all its open file descriptors, as if by calling this function for each one.
*/
void syscall_close(struct intr_frame *f);
/* /*
* special additional stuff for handling file descriptors because they're annoying * 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