summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/examples/Makefile4
-rw-r--r--src/examples/create.c14
-rw-r--r--src/userprog/syscall.c14
3 files changed, 30 insertions, 2 deletions
diff --git a/src/examples/Makefile b/src/examples/Makefile
index 5517532..a89a3e3 100644
--- a/src/examples/Makefile
+++ b/src/examples/Makefile
@@ -8,6 +8,10 @@ PROGS = cat cmp cp echo halt hex-dump ls mcat mcp mkdir pwd rm shell \
sumargv lab2test lab1test lab1test2 pfs pfs_reader pfs_writer dummy longrun \
child parent create-bad printf
+PROGS += create
+
+create_SRC = create.c
+
# Added test programs
printf_SRC = printf.c
sumargv_SRC = sumargv.c
diff --git a/src/examples/create.c b/src/examples/create.c
new file mode 100644
index 0000000..4805e18
--- /dev/null
+++ b/src/examples/create.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+#include <syscall.h>
+
+int
+main (int argc, char *argv[])
+{
+ if (create("test", 1)) {
+ printf("created file\n");
+ halt();
+ } else {
+ printf("couldn't create file\n");
+ halt();
+ }
+}
diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c
index d53c1bd..5e5a6f1 100644
--- a/src/userprog/syscall.c
+++ b/src/userprog/syscall.c
@@ -1,10 +1,13 @@
#include "userprog/syscall.h"
#include <stdio.h>
#include <syscall-nr.h>
-#include "threads/init.h"
#include "threads/interrupt.h"
#include "threads/thread.h"
+#include "threads/init.h"
+#include "filesys/filesys.h"
+#include "filesys/off_t.h"
+
static void syscall_handler (struct intr_frame *);
void
@@ -30,6 +33,14 @@ syscall_handler (struct intr_frame *f UNUSED)
break;
case 4:
// create
+ ; // empty statement because c-grammar doesn't allow declarations following labels
+ printf("kernel: create\n");
+ char *filename = INTR_ESP(1, char *);
+ printf("create: read filename '%s'\n", filename);
+ off_t initial_size = INTR_ESP(2, off_t);
+ printf("create: read initial_size '%d'\n", initial_size);
+ f->eax = filesys_create(filename, initial_size);
+ printf("create: result (%d) put in f->eax\n", f->eax);
break;
case 6:
// open
@@ -48,5 +59,4 @@ syscall_handler (struct intr_frame *f UNUSED)
printf ("kernel: unknown syscall '%d'\n", syscall_number);
break;
}
- thread_exit ();
}