aboutsummaryrefslogtreecommitdiffstats
path: root/src/examples/pfs_reader.c
diff options
context:
space:
mode:
authorklaar36 <klas.arvidsson@liu.se>2015-03-20 17:30:24 +0100
committerklaar36 <klas.arvidsson@liu.se>2015-03-20 17:30:24 +0100
commite7bc50ca8ffcaa6ed68ebd2315f78b0f5a7d10ad (patch)
tree4de97af7207676b69cb6a9aba8cb443cc134855d /src/examples/pfs_reader.c
parentb0418a24e709f0632d2ede5b0f327c422931939b (diff)
downloadpintos-rs-e7bc50ca8ffcaa6ed68ebd2315f78b0f5a7d10ad.tar.gz
Initial Pintos
Diffstat (limited to 'src/examples/pfs_reader.c')
-rw-r--r--src/examples/pfs_reader.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/examples/pfs_reader.c b/src/examples/pfs_reader.c
new file mode 100644
index 0000000..4f2d0fa
--- /dev/null
+++ b/src/examples/pfs_reader.c
@@ -0,0 +1,50 @@
+/* Part of pfs.c suite.
+
+ Reads from the file and checks consistency.
+ The buffer should all contain the same character!!
+ */
+
+#include <syscall.h>
+#include <stdio.h>
+#include "pfs.h"
+
+char buffer[BIG];
+
+int main(void)
+{
+ int bytes, i, j, inconsistency;
+ int id, messages;
+
+ messages = open("messages");
+
+ for (i = 0; i < TIMES; ++i)
+ {
+ id = open("file.1");
+ bytes = read(id, buffer, BIG);
+ close(id);
+
+ if (bytes != BIG)
+ {
+ write(messages, "Buffer not filled!\n", 19);
+ continue;
+ }
+ /* now check for consistency */
+ for (j = 1, inconsistency = 0; j < BIG; ++j)
+ {
+ if (buffer[0] != buffer[j])
+ {
+ /* Ooops, inconsistency */
+ write(messages, "INCONSISTENCY.", 14);
+ printf("INCONSISTENCY\n");
+ inconsistency = 1;
+ break; /* no need to check further */
+ }
+ }
+ if (!inconsistency)
+ {
+ write(messages, "cool\n", 5);
+ }
+ }
+ close(messages);
+ exit(0);
+}