CS318 - Pintos
Pintos source browser for JHU CS318 course
child-syn-wrt.c
Go to the documentation of this file.
1 /** Child process for syn-read test.
2  Writes into part of a test file. Other processes will be
3  writing into other parts at the same time. */
4 
5 #include <random.h>
6 #include <stdlib.h>
7 #include <syscall.h>
8 #include "tests/lib.h"
10 
11 char buf[BUF_SIZE];
12 
13 int
14 main (int argc, char *argv[])
15 {
16  int child_idx;
17  int fd;
18 
19  quiet = true;
20 
21  CHECK (argc == 2, "argc must be 2, actually %d", argc);
22  child_idx = atoi (argv[1]);
23 
24  random_init (0);
25  random_bytes (buf, sizeof buf);
26 
27  CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
28  seek (fd, CHUNK_SIZE * child_idx);
29  CHECK (write (fd, buf + CHUNK_SIZE * child_idx, CHUNK_SIZE) > 0,
30  "write \"%s\"", file_name);
31  msg ("close \"%s\"", file_name);
32  close (fd);
33 
34  return child_idx;
35 }
main
int main(int argc, char *argv[])
Definition: child-syn-wrt.c:14
lib.h
write
int write(int fd, const void *buffer, unsigned size)
Definition: syscall.c:121
CHECK
#define CHECK(SUCCESS,...)
Takes an expression to test for SUCCESS and a message, which may include printf-style arguments.
Definition: lib.h:29
atoi
int atoi(const char *s)
Converts a string representation of a signed decimal integer in S into an ‘int’, which is returned.
Definition: stdlib.c:10
CHUNK_SIZE
#define CHUNK_SIZE
Definition: syn-write.h:5
random_bytes
void random_bytes(void *buf_, size_t size)
Writes SIZE random bytes into BUF.
Definition: random.c:54
random.h
syn-write.h
random_init
void random_init(unsigned seed)
Initializes or reinitializes the PRNG with the given SEED.
Definition: random.c:34
open
int open(const char *file)
Definition: syscall.c:103
seek
void seek(int fd, unsigned position)
Definition: syscall.c:127
file_name
static const char file_name[]
tests/filesys/base/syn-read.h
Definition: syn-read.h:5
close
void close(int fd)
Definition: syscall.c:139
buf
char buf[BUF_SIZE]
Child process for syn-read test.
Definition: child-syn-wrt.c:11
msg
void msg(const char *format,...)
Definition: lib.c:28
stdlib.h
BUF_SIZE
#define BUF_SIZE
Definition: syn-read.h:4
quiet
bool quiet
Definition: lib.c:9