4 char buf
[512], buf2
[512];
7 umain(int argc
, char **argv
)
11 if ((fd
= open("motd", O_RDONLY
)) < 0)
12 panic("open motd: %e", fd
);
14 if ((n
= readn(fd
, buf
, sizeof buf
)) <= 0)
15 panic("readn: %e", n
);
21 cprintf("going to read in child (might page fault if your sharing is buggy)\n");
22 if ((n2
= readn(fd
, buf2
, sizeof buf2
)) != n
)
23 panic("read in parent got %d, read in child got %d", n
, n2
);
24 if (memcmp(buf
, buf2
, n
) != 0)
25 panic("read in parent got different bytes from read in child");
26 cprintf("read in child succeeded\n");
32 if ((n2
= readn(fd
, buf2
, sizeof buf2
)) != n
)
33 panic("read in parent got %d, then got %d", n
, n2
);
34 cprintf("read in parent succeeded\n");
37 if ((fd
= open("newmotd", O_RDWR
)) < 0)
38 panic("open newmotd: %e", fd
);
40 if ((n
= write(fd
, "hello", 5)) != 5)
41 panic("write: %e", n
);
47 cprintf("going to write in child\n");
48 if ((n
= write(fd
, "world", 5)) != 5)
49 panic("write in child: %e", n
);
50 cprintf("write in child finished\n");
56 if ((n
= readn(fd
, buf
, 5)) != 5)
57 panic("readn: %e", n
);
59 if (strcmp(buf
, "hello") == 0)
60 cprintf("write to file failed; got old data\n");
61 else if (strcmp(buf
, "world") == 0)
62 cprintf("write to file succeeded\n");
64 cprintf("write to file failed; got %s\n", buf
);