Permalink
Browse files

Merge branch 'master' of https://github.com/grantborthwick/Lasagnos i…

…nto bens
  • Loading branch information...
2 parents 92db82f + 7244f5e commit 6b06411c700ed7c1418eb5625d1d93b26f9a92d3 @Frankencelery Frankencelery committed Oct 28, 2012
Showing with 39 additions and 7 deletions.
  1. +39 −7 src/userprog/syscall.c
View
@@ -279,23 +279,45 @@ static struct file_descriptor *
lookup_fd (int handle)
{
/* Add code to lookup file descriptor in the current thread's fds */
+
+ struct thread* cur = thread_current();
+ struct list_elem* e = list_front(&(cur->fds));
+ struct file_descriptor * e2;
+ while(e != NULL){
+ e2 = list_entry(e, struct file_descriptor, elem);
+ if (e2->handle == handle){
+ lock_release (&fs_lock);
+ return e2;
+ }
+ e = list_next(e);
+ }
+
thread_exit ();
}
/* Filesize system call. */
static int
sys_filesize (int handle)
{
-/* Add code */
- thread_exit ();
+ struct file_descriptor * e2 = lookup_fd(handle);
+ lock_acquire (&fs_lock);
+ int len = file_length( e2->file);
+ lock_release (&fs_lock);
+ return len;
}
/* Read system call. */
static int
sys_read (int handle, void *udst_, unsigned size)
{
/* Add code */
- thread_exit ();
+ struct file_descriptor* fd = lookup_fd(handle); // NEED TO FIGURE OUT FILE IO. MAYBE FROM STDOUT_FILENO...
+ if (fd != NULL){
+ lock_acquire (&fs_lock);
+ int read = file_read(fd->file, udst_, size);
+ lock_release (&fs_lock);
+ return read;
+ } else{return -1;}
}
/* Write system call. */
@@ -305,7 +327,7 @@ sys_write (int handle, void *usrc_, unsigned size)
uint8_t *usrc = usrc_;
struct file_descriptor *fd = NULL;
int bytes_written = 0;
-
+
/* Lookup up file descriptor. */
if (handle != STDOUT_FILENO)
fd = lookup_fd (handle);
@@ -358,15 +380,25 @@ sys_write (int handle, void *usrc_, unsigned size)
static int
sys_seek (int handle, unsigned position)
{
-/* Add code */
- thread_exit ();
+ struct file_descriptor * fd = lookup_fd (handle);
+ if (fd!= NULL){
+ lock_acquire (&fs_lock);
+ file_seek(fd->file, position);
+ lock_release (&fs_lock);
+ }
+ //thread_exit ();
}
/* Tell system call. */
static int
sys_tell (int handle)
{
-/* Add code */
+ struct file_descriptor * fd = lookup_fd (handle);
+ if (fd!= NULL){
+ lock_acquire (&fs_lock);
+ file_tell(fd->file);
+ lock_release (&fs_lock);
+ }
thread_exit ();
}

0 comments on commit 6b06411

Please sign in to comment.