Add a helper function to get a file from its descriptor (FD), w/ E
This commit is contained in:
@@ -281,6 +281,22 @@ fd_less (const struct hash_elem *a_, const struct hash_elem *b_,
|
|||||||
return a->fd < b->fd;
|
return a->fd < b->fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Gets a file from its descriptor (FD number). If there is no file with the fd
|
||||||
|
FD it returns NULL. */
|
||||||
|
static struct file *
|
||||||
|
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 file *file
|
||||||
|
= hash_find (thread_current ()->open_files, fake_file_info->elem);
|
||||||
|
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
/* Validates if a block of memory starting at PTR and of size SIZE bytes is
|
/* Validates if a block of memory starting at PTR and of size SIZE bytes is
|
||||||
fully contained within user virtual memory. Kills the thread (by calling
|
fully contained within user virtual memory. Kills the thread (by calling
|
||||||
thread_exit) if the memory is invalid. Otherwise, returns the PTR given.
|
thread_exit) if the memory is invalid. Otherwise, returns the PTR given.
|
||||||
|
|||||||
Reference in New Issue
Block a user