summaryrefslogtreecommitdiffstats
path: root/src/examples/pfs_writer.c
diff options
context:
space:
mode:
authorFelipe Boeira <felipe.boeira@liu.se>2019-01-08 18:39:03 +0100
committerFelipe Boeira <felipe.boeira@liu.se>2019-01-08 18:39:03 +0100
commitd4522b8e9854178473adcea0fbb84f23f6e744bd (patch)
treefbcf620617c5023154eba3f965b3a982daa64a47 /src/examples/pfs_writer.c
downloadpintos-d4522b8e9854178473adcea0fbb84f23f6e744bd.tar.gz
Initial commit
Diffstat (limited to 'src/examples/pfs_writer.c')
-rw-r--r--src/examples/pfs_writer.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/examples/pfs_writer.c b/src/examples/pfs_writer.c
new file mode 100644
index 0000000..0ebd772
--- /dev/null
+++ b/src/examples/pfs_writer.c
@@ -0,0 +1,47 @@
+/* Write on the disk.
+ * Each time the buffer is filled with same character.
+ * Different character every time!
+ */
+
+#include <syscall.h>
+#include <stdio.h>
+#include <string.h>
+#include "pfs.h"
+
+char buffer[BIG];
+
+int main(int argc, char* argv[])
+{
+ int i,j;
+ char c;
+ int id;
+ int write_count;
+ char start;
+ char end;
+
+ if (argc != 3 || strlen(argv[1]) != 1 || strlen(argv[2]) != 1)
+ exit(1);
+
+ start = argv[1][0];
+ end = argv[2][0];
+
+ for (i = 0; i < TIMES / (end - start + 1) + 1; ++i)
+ {
+ for (c = start; c <= end; ++c)
+ {
+ for (j = 0; j < BIG; j++)
+ buffer[j] = c;
+
+ id = open("file.1");
+ write_count = write(id, buffer, BIG);
+
+ if ( write_count != BIG )
+ {
+ printf("TEST ERROR: write() wrote only %d bytes out of %d bytes\n",
+ write_count, BIG);
+ }
+ close(id);
+ }
+ }
+ exit(0);
+}