0a43f5a7f008418eee3bf06fe21068df97289850
[pintos-anon] / grading / filesys / child-syn-wrt.c
1 #include <random.h>
2 #include <stdlib.h>
3 #include <syscall.h>
4 #include "fslib.h"
5 #include "syn-write.h"
6
7 const char test_name[] = "child-syn-wrt";
8
9 char buf[BUF_SIZE];
10
11 int
12 main (int argc, char *argv[])
13 {
14   int child_idx;
15   int fd;
16
17   quiet = true;
18   
19   CHECK (argc == 2, "argc must be 2, actually %d", argc);
20   child_idx = atoi (argv[1]);
21
22   random_init (0);
23   random_bytes (buf, sizeof buf);
24
25   CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
26   seek (fd, CHUNK_SIZE * child_idx);
27   CHECK (write (fd, buf + CHUNK_SIZE * child_idx, CHUNK_SIZE) > 0,
28          "write \"%s\"", filename);
29   msg ("close \"%s\"", filename);
30   close (fd);
31
32   return child_idx;
33 }