PKUOS - Pintos
Pintos source browser for PKU Operating System 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
12
13int
14main (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}
int main(int argc, char *argv[])
Definition: child-syn-wrt.c:14
char buf[BUF_SIZE]
Child process for syn-read test.
Definition: child-syn-wrt.c:11
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
void close(int fd)
Definition: syscall.c:139
int open(const char *file)
Definition: syscall.c:103
int write(int fd, const void *buffer, unsigned size)
Definition: syscall.c:121
void seek(int fd, unsigned position)
Definition: syscall.c:127
void msg(const char *format,...)
Definition: lib.c:28
bool quiet
Definition: lib.c:9
#define CHECK(SUCCESS,...)
Takes an expression to test for SUCCESS and a message, which may include printf-style arguments.
Definition: lib.h:29
void random_bytes(void *buf_, size_t size)
Writes SIZE random bytes into BUF.
Definition: random.c:54
void random_init(unsigned seed)
Initializes or reinitializes the PRNG with the given SEED.
Definition: random.c:34
#define BUF_SIZE
Definition: syn-read.h:4
static const char file_name[]
tests/filesys/base/syn-read.h
Definition: syn-read.h:5
#define CHUNK_SIZE
Definition: syn-write.h:5