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

Implement tell()

parent 271ab108
No related branches found
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 ...@@ -73,6 +73,7 @@ userprog_SRC += userprog/syscall_write.c
userprog_SRC += userprog/file_descriptors_map.c 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
# No virtual memory code yet. # No virtual memory code yet.
#vm_SRC = vm/file.c # Some file. #vm_SRC = vm/file.c # Some file.
......
/*
* 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); ...@@ -69,6 +69,12 @@ void syscall_filesize(struct intr_frame *f);
*/ */
void syscall_remove(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 * 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