Implement syscall for file opening and refactor open_files initialisation in thread.c w/ S.
This commit is contained in:
@@ -238,6 +238,7 @@ thread_create (const char *name, int priority,
|
||||
struct thread *parent_thread = thread_current ();
|
||||
init_thread (t, name, parent_thread->nice, priority, parent_thread->recent_cpu);
|
||||
tid = t->tid = allocate_tid ();
|
||||
hash_init (&t->open_files, fd_hash, fd_less, NULL);
|
||||
|
||||
/* Prepare thread for first run by initializing its stack.
|
||||
Do this atomically so intermediate values for the 'stack'
|
||||
@@ -662,7 +663,6 @@ init_thread (struct thread *t, const char *name, int nice, int priority,
|
||||
t->priority = t->base_priority;
|
||||
|
||||
t->exit_status = -1;
|
||||
hash_init (&t->open_files, fd_hash, fd_less, NULL);
|
||||
|
||||
old_level = intr_disable ();
|
||||
list_push_back (&all_list, &t->allelem);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "filesys/filesys.h"
|
||||
#include "threads/vaddr.h"
|
||||
#include "threads/interrupt.h"
|
||||
#include "threads/malloc.h"
|
||||
#include "threads/thread.h"
|
||||
#include "threads/synch.h"
|
||||
#include "userprog/process.h"
|
||||
@@ -12,6 +13,7 @@
|
||||
#include <syscall-nr.h>
|
||||
|
||||
static struct lock filesys_lock;
|
||||
static unsigned fd_counter = MIN_USER_FD;
|
||||
|
||||
struct open_file
|
||||
{
|
||||
@@ -165,10 +167,27 @@ syscall_remove (const char *file)
|
||||
}
|
||||
|
||||
static int
|
||||
syscall_open (const char *file UNUSED)
|
||||
syscall_open (const char *file)
|
||||
{
|
||||
//TODO
|
||||
return 0;
|
||||
validate_user_pointer (file, 1);
|
||||
|
||||
lock_acquire (&filesys_lock);
|
||||
struct file *ptr = filesys_open (file);
|
||||
lock_release (&filesys_lock);
|
||||
if (ptr == NULL)
|
||||
return -1;
|
||||
|
||||
struct open_file *file_info
|
||||
= (struct open_file*) malloc (sizeof (struct open_file));
|
||||
if (file_info == NULL)
|
||||
return -1;
|
||||
|
||||
file_info->fd = fd_counter++;
|
||||
file_info->file = ptr;
|
||||
|
||||
hash_insert (&thread_current ()->open_files, &file_info->elem);
|
||||
|
||||
return file_info->fd;
|
||||
}
|
||||
|
||||
static int
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <hash.h>
|
||||
|
||||
#define MIN_USER_FD 2
|
||||
|
||||
typedef int pid_t;
|
||||
|
||||
void syscall_init (void);
|
||||
|
||||
Reference in New Issue
Block a user