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

Merge branch 'josh/25-tell' into 'feature/system-calls'

Implement tell() system call

See merge request !20
parents 271ab108 1acef028
Branches
No related tags found
2 merge requests!22Merge Feature/system calls,!20Implement tell() system call
......@@ -73,6 +73,7 @@ userprog_SRC += userprog/syscall_write.c
userprog_SRC += userprog/file_descriptors_map.c
userprog_SRC += userprog/syscall_read.c
userprog_SRC += userprog/syscall_filesize.c
userprog_SRC += userprog/syscall_tell.c
# No virtual memory code yet.
#vm_SRC = vm/file.c # Some file.
......
......@@ -85,6 +85,9 @@ syscall_handler (struct intr_frame *f UNUSED)
case SYSCALL_FILESIZE:
syscall_filesize(f);
break;
case SYSCALL_TELL:
syscall_tell(f);
break;
default:
printf ("WARNING: Invalid Syscall (%d)\n", syscall_number);
thread_exit ();
......
/*
* Returns the current offset into the file that the given file descriptor is at
*
* Authored by Joshua Saxby
*/
#include <stddef.h>
#include "system_calls.h"
#include "filesys/file.h"
void syscall_tell(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);
/*
* tell() return type is unsigned so we can't return a special error code if
* file descriptor passed is invalid. Instead, we return 0 silently.
*/
f->eax = (file != NULL) ? file_tell(file) : 0;
}
......@@ -69,6 +69,12 @@ void syscall_filesize(struct intr_frame *f);
*/
void syscall_remove(struct intr_frame *f);
/*
* Returns the position of the next byte to be read or written in open file fd,
* expressed in bytes from the beginning of the file.
*/
void syscall_tell(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