diff options
| author | Felipe Boeira <felipe.boeira@liu.se> | 2019-01-08 18:39:03 +0100 |
|---|---|---|
| committer | Felipe Boeira <felipe.boeira@liu.se> | 2019-01-08 18:39:03 +0100 |
| commit | d4522b8e9854178473adcea0fbb84f23f6e744bd (patch) | |
| tree | fbcf620617c5023154eba3f965b3a982daa64a47 /src/examples/pfs_reader.c | |
| download | pintos-d4522b8e9854178473adcea0fbb84f23f6e744bd.tar.gz | |
Initial commit
Diffstat (limited to 'src/examples/pfs_reader.c')
| -rw-r--r-- | src/examples/pfs_reader.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/examples/pfs_reader.c b/src/examples/pfs_reader.c new file mode 100644 index 0000000..583583a --- /dev/null +++ b/src/examples/pfs_reader.c @@ -0,0 +1,48 @@ +/* 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); +} |
