Implement syscall_read for console input w/ S.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#include "userprog/syscall.h"
|
#include "userprog/syscall.h"
|
||||||
#include "devices/shutdown.h"
|
#include "devices/shutdown.h"
|
||||||
|
#include "devices/input.h"
|
||||||
#include "threads/vaddr.h"
|
#include "threads/vaddr.h"
|
||||||
#include "threads/interrupt.h"
|
#include "threads/interrupt.h"
|
||||||
#include "threads/thread.h"
|
#include "threads/thread.h"
|
||||||
@@ -150,10 +151,29 @@ syscall_filesize (int fd UNUSED)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
syscall_read (int fd UNUSED, void *buffer UNUSED, unsigned size UNUSED)
|
syscall_read (int fd, void *buffer, unsigned size)
|
||||||
{
|
{
|
||||||
//TODO
|
/* Only console (fd = 0) or other files, not including STDOUT, (fd > 1) are
|
||||||
return 0;
|
allowed. */
|
||||||
|
if (fd < 0 && fd != STDOUT_FILENO)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
validate_user_pointer (buffer, size);
|
||||||
|
|
||||||
|
if (fd == STDIN_FILENO)
|
||||||
|
{
|
||||||
|
/* Reading from the console. */
|
||||||
|
char *write_buffer = buffer;
|
||||||
|
for (int i = 0; i < size; i++)
|
||||||
|
write_buffer[i] = input_getc ();
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Reading from a file. */
|
||||||
|
return 0; // TODO: Implement Write to Files
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|||||||
Reference in New Issue
Block a user