Implement syscall for close() and fix typing bug in fd_get_file w/ S.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "userprog/syscall.h"
|
||||
#include "devices/shutdown.h"
|
||||
#include "devices/input.h"
|
||||
#include "filesys/file.h"
|
||||
#include "filesys/filesys.h"
|
||||
#include "threads/vaddr.h"
|
||||
#include "threads/interrupt.h"
|
||||
@@ -261,9 +262,18 @@ syscall_tell (int fd UNUSED)
|
||||
}
|
||||
|
||||
static void
|
||||
syscall_close (int fd UNUSED)
|
||||
syscall_close (int fd)
|
||||
{
|
||||
//TODO
|
||||
struct open_file *file_info = fd_get_file (fd);
|
||||
if (file_info != NULL)
|
||||
{
|
||||
hash_delete (&thread_current ()->open_files, &file_info->elem);
|
||||
|
||||
lock_acquire (&filesys_lock);
|
||||
file_close (file_info->file);
|
||||
lock_release (&filesys_lock);
|
||||
free (file_info);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned
|
||||
@@ -289,11 +299,11 @@ fd_get_file (int fd)
|
||||
{
|
||||
/* We have to set up a fake open_file in order to be able to search the hash
|
||||
table. See hash.h. */
|
||||
struct open_file *fake_file_info;
|
||||
fake_file_info->fd = fd;
|
||||
struct open_file fake_file_info;
|
||||
fake_file_info.fd = fd;
|
||||
|
||||
struct hash_elem *e
|
||||
= hash_find (&thread_current ()->open_files, &fake_file_info->elem);
|
||||
= hash_find (&thread_current ()->open_files, &fake_file_info.elem);
|
||||
|
||||
return hash_entry (e, struct open_file, elem);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user