summaryrefslogtreecommitdiffstats
path: root/src/userprog/syscall.c
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-02-11 11:47:37 +0100
committerGustav Sörnäs <gustav@sornas.net>2021-02-11 11:53:35 +0100
commitfcfef25ad1ac31268d7119c56c819467adf9424e (patch)
treef0bec16348c1705d7f26421b61f51d61753aa7a5 /src/userprog/syscall.c
parentc94d15c08a4f2c65f7f3b783d5b2b390b9bdd441 (diff)
downloadpintos-fcfef25ad1ac31268d7119c56c819467adf9424e.tar.gz
formatting
Diffstat (limited to 'src/userprog/syscall.c')
-rw-r--r--src/userprog/syscall.c34
1 files changed, 14 insertions, 20 deletions
diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c
index cce7574..3768e79 100644
--- a/src/userprog/syscall.c
+++ b/src/userprog/syscall.c
@@ -37,13 +37,12 @@ open (const char *filename)
struct thread *t = thread_current ();
if (!t->fds) {
- printf("[%s] open: allocating %d file descriptors\n", t->name, MAX_FDS);
t->fds = (struct fd *) calloc (MAX_FDS, sizeof (struct fd));
}
- struct file *file = filesys_open(filename);
+ struct file *file = filesys_open (filename);
if (!file) {
- printf("[%s] open: couldn't find file %s\n", t->name, filename);
+ printf ("[%s] open: couldn't find file %s\n", t->name, filename);
return -1;
}
@@ -55,8 +54,8 @@ open (const char *filename)
return i + 2; // 0 and 1 are reserved for stdin and stdout
}
}
- free(file);
- printf("[%s] open: unable to find empty file descriptor\n", t->name);
+ free (file);
+ printf ("[%s] open: unable to find empty file descriptor\n", t->name);
return -1;
}
@@ -73,10 +72,10 @@ get_fd (struct thread *thread, int fd_i)
static struct file *
get_file (struct thread *thread, int fd_i)
{
- struct fd *fd = get_fd(thread, fd_i);
+ struct fd *fd = get_fd (thread, fd_i);
if (!fd || !fd->active) {
- printf("[%s] get_file: invalid file descriptor\n", thread->name);
+ printf ("[%s] get_file: invalid file descriptor\n", thread->name);
return NULL;
}
@@ -96,7 +95,7 @@ exit (int status)
fd->active = false;
}
}
- free(thread->fds);
+ free (thread->fds);
}
}
@@ -114,18 +113,16 @@ read (int fd_i, void *buf, unsigned size)
return i;
} else if (fd_i == 1) {
// can't read from stdout
- printf("[%s] read: tried to read from stdout\n", thread->name);
+ printf ("[%s] read: tried to read from stdout\n", thread->name);
return -1;
}
- struct file *file = get_file(thread, fd_i);
+ struct file *file = get_file (thread, fd_i);
if (!file) {
return -1;
}
- int n = file_read (file, buf, size);
- printf("%d/%d: %s\n", n, size, (char *)buf);
- return n;
+ return file_read (file, buf, size);
}
static int
@@ -147,10 +144,7 @@ write (int fd_i, const void *buf, unsigned size)
return -1;
}
- int n = file_write(file, buf, size);
- printf ("%d/%d: %s\n", n, size, (char *)buf);
-
- return n;
+ return file_write (file, buf, size);
}
static void
@@ -158,12 +152,12 @@ close (int fd_i)
{
struct thread *thread = thread_current ();
- struct fd *fd = get_fd(thread, fd_i);
+ struct fd *fd = get_fd (thread, fd_i);
if (!fd) {
return;
}
if (!fd->active) {
- printf("[%s] close: tried to close inactive file descriptor %d\n", thread->name, fd_i);
+ printf ("[%s] close: tried to close inactive file descriptor %d\n", thread->name, fd_i);
return;
}
@@ -205,7 +199,7 @@ syscall_handler (struct intr_frame *f UNUSED)
break;
case 12:
// close
- close (INTR_ESP(1, int));
+ close (INTR_ESP (1, int));
break;
default:
printf ("kernel: unknown syscall '%d'\n", syscall_number);