提交 010080dd 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

Merge commit '03f6bac6' into scale-amd64

...@@ -12,7 +12,7 @@ cat(int fd) ...@@ -12,7 +12,7 @@ cat(int fd)
while((n = read(fd, buf, sizeof(buf))) > 0) while((n = read(fd, buf, sizeof(buf))) > 0)
write(1, buf, n); write(1, buf, n);
if(n < 0){ if(n < 0){
printf(1, "cat: read error\n"); fprintf(1, "cat: read error\n");
exit(); exit();
} }
} }
...@@ -29,7 +29,7 @@ main(int argc, char *argv[]) ...@@ -29,7 +29,7 @@ main(int argc, char *argv[])
for(i = 1; i < argc; i++){ for(i = 1; i < argc; i++){
if((fd = open(argv[i], 0)) < 0){ if((fd = open(argv[i], 0)) < 0){
printf(1, "cat: cannot open %s\n", argv[i]); fprintf(1, "cat: cannot open %s\n", argv[i]);
exit(); exit();
} }
cat(fd); cat(fd);
......
...@@ -22,7 +22,7 @@ bench(u32 tid) ...@@ -22,7 +22,7 @@ bench(u32 tid)
int fd = open(pn, O_CREATE | O_RDWR); int fd = open(pn, O_CREATE | O_RDWR);
if (fd < 0) if (fd < 0)
printf(1, "create failed\n"); fprintf(1, "create failed\n");
close(fd); close(fd);
} }
...@@ -31,7 +31,7 @@ bench(u32 tid) ...@@ -31,7 +31,7 @@ bench(u32 tid)
snprintf(pn, sizeof(pn), "%s/f:%d:%d", dirs[tid], tid, (i % nfile)); snprintf(pn, sizeof(pn), "%s/f:%d:%d", dirs[tid], tid, (i % nfile));
int fd = open(pn, O_RDWR); int fd = open(pn, O_RDWR);
if (fd < 0) if (fd < 0)
printf(1, "open failed\n"); fprintf(1, "open failed\n");
close(fd); close(fd);
} }
...@@ -39,7 +39,7 @@ bench(u32 tid) ...@@ -39,7 +39,7 @@ bench(u32 tid)
for (u32 i = 0; i < nfile; i++) { for (u32 i = 0; i < nfile; i++) {
snprintf(pn, sizeof(pn), "%s/f:%d:%d", dirs[tid], tid, i); snprintf(pn, sizeof(pn), "%s/f:%d:%d", dirs[tid], tid, i);
if (unlink(pn) < 0) if (unlink(pn) < 0)
printf(1, "unlink failed\n"); fprintf(1, "unlink failed\n");
} }
} }
...@@ -53,12 +53,12 @@ main(void) ...@@ -53,12 +53,12 @@ main(void)
//snprintf(dirs[i], sizeof(dirs[i]), "/db%d", i); //snprintf(dirs[i], sizeof(dirs[i]), "/db%d", i);
snprintf(dirs[i], sizeof(dirs[i]), "/dbx"); snprintf(dirs[i], sizeof(dirs[i]), "/dbx");
if (mkdir(dirs[i]) < 0) if (mkdir(dirs[i]) < 0)
printf(1, "mkdir failed\n"); fprintf(1, "mkdir failed\n");
} }
// mtrace_enable_set(1, "xv6-dirbench"); // mtrace_enable_set(1, "xv6-dirbench");
printf(1, "dirbench[%d]: start\n", getpid()); fprintf(1, "dirbench[%d]: start\n", getpid());
for(u32 i = 0; i < nthread; i++) { for(u32 i = 0; i < nthread; i++) {
int pid = fork(0); int pid = fork(0);
if (pid == 0) if (pid == 0)
...@@ -69,7 +69,7 @@ main(void) ...@@ -69,7 +69,7 @@ main(void)
wait(); wait();
// mtrace_enable_set(0, "xv6-dirbench"); // mtrace_enable_set(0, "xv6-dirbench");
printf(1, "dirbench[%d]: done\n", getpid()); fprintf(1, "dirbench[%d]: done\n", getpid());
// halt(); // halt();
exit(); exit();
} }
...@@ -8,6 +8,6 @@ main(int argc, char *argv[]) ...@@ -8,6 +8,6 @@ main(int argc, char *argv[])
int i; int i;
for(i = 1; i < argc; i++) for(i = 1; i < argc; i++)
printf(1, "%s%s", argv[i], i+1 < argc ? " " : "\n"); fprintf(1, "%s%s", argv[i], i+1 < argc ? " " : "\n");
exit(); exit();
} }
...@@ -14,13 +14,13 @@ execbench(void) ...@@ -14,13 +14,13 @@ execbench(void)
for (int i = 0; i < NITERS; i++) { for (int i = 0; i < NITERS; i++) {
int pid = fork(0); int pid = fork(0);
if (pid < 0) { if (pid < 0) {
printf(1, "fork error\n"); fprintf(1, "fork error\n");
exit(); exit();
} }
if (pid == 0) { if (pid == 0) {
const char *av[] = { "forkexecbench", "x", 0 }; const char *av[] = { "forkexecbench", "x", 0 };
exec("forkexecbench", av); exec("forkexecbench", av);
printf(1, "exec failed\n"); fprintf(1, "exec failed\n");
exit(); exit();
} else { } else {
wait(); wait();
...@@ -30,7 +30,7 @@ execbench(void) ...@@ -30,7 +30,7 @@ execbench(void)
mtdisable("xv6-forkexecbench"); mtdisable("xv6-forkexecbench");
u64 e = rdtsc(); u64 e = rdtsc();
printf(1, "%lu\n", (e-s) / NITERS); fprintf(1, "%lu\n", (e-s) / NITERS);
} }
int int
......
...@@ -10,7 +10,7 @@ void ...@@ -10,7 +10,7 @@ void
forktree(int depth) forktree(int depth)
{ {
if (depth == 0) { if (depth == 0) {
printf(1, "%d: forkexectree\n", getpid()); fprintf(1, "%d: forkexectree\n", getpid());
mtenable("xv6-forkexectree"); mtenable("xv6-forkexectree");
} }
...@@ -20,7 +20,7 @@ forktree(int depth) ...@@ -20,7 +20,7 @@ forktree(int depth)
for (int i = 0; i < NCHILD; i++) { for (int i = 0; i < NCHILD; i++) {
int pid = fork(0); int pid = fork(0);
if (pid < 0) { if (pid < 0) {
printf(1, "fork error\n"); fprintf(1, "fork error\n");
exit(); exit();
} }
...@@ -35,13 +35,13 @@ forktree(int depth) ...@@ -35,13 +35,13 @@ forktree(int depth)
for (int i = 0; i < NCHILD; i++) { for (int i = 0; i < NCHILD; i++) {
if (wait() < 0) { if (wait() < 0) {
printf(1, "wait stopped early\n"); fprintf(1, "wait stopped early\n");
exit(); exit();
} }
} }
if (wait() != -1) { if (wait() != -1) {
printf(1, "wait got too many\n"); fprintf(1, "wait got too many\n");
exit(); exit();
} }
...@@ -51,7 +51,7 @@ forktree(int depth) ...@@ -51,7 +51,7 @@ forktree(int depth)
mtops(0); mtops(0);
mtdisable("xv6-forkexectree"); mtdisable("xv6-forkexectree");
printf(1, "%d: forkexectree OK\n", getpid()); fprintf(1, "%d: forkexectree OK\n", getpid());
// halt(); // halt();
} }
......
...@@ -11,7 +11,7 @@ forktree(void) ...@@ -11,7 +11,7 @@ forktree(void)
{ {
int depth = 0; int depth = 0;
printf(1, "%d: fork tree\n", getpid()); fprintf(1, "%d: fork tree\n", getpid());
mtenable("xv6-forktree"); mtenable("xv6-forktree");
next_level: next_level:
...@@ -22,7 +22,7 @@ forktree(void) ...@@ -22,7 +22,7 @@ forktree(void)
for (int i = 0; i < NCHILD; i++) { for (int i = 0; i < NCHILD; i++) {
int pid = fork(0); int pid = fork(0);
if (pid < 0) { if (pid < 0) {
printf(1, "fork error\n"); fprintf(1, "fork error\n");
exit(); exit();
} }
...@@ -34,13 +34,13 @@ forktree(void) ...@@ -34,13 +34,13 @@ forktree(void)
for (int i = 0; i < NCHILD; i++) { for (int i = 0; i < NCHILD; i++) {
if (wait() < 0) { if (wait() < 0) {
printf(1, "wait stopped early\n"); fprintf(1, "wait stopped early\n");
exit(); exit();
} }
} }
if (wait() != -1) { if (wait() != -1) {
printf(1, "wait got too many\n"); fprintf(1, "wait got too many\n");
exit(); exit();
} }
...@@ -50,7 +50,7 @@ forktree(void) ...@@ -50,7 +50,7 @@ forktree(void)
mtops(0); mtops(0);
mtdisable("xv6-forktree"); mtdisable("xv6-forktree");
printf(1, "%d: fork tree OK\n", getpid()); fprintf(1, "%d: fork tree OK\n", getpid());
// halt(); // halt();
} }
......
...@@ -16,7 +16,7 @@ static int xwrite(int fd, const void *buf, u64 n) ...@@ -16,7 +16,7 @@ static int xwrite(int fd, const void *buf, u64 n)
while (n) { while (n) {
r = write(fd, buf, n); r = write(fd, buf, n);
if (r < 0 || r == 0) { if (r < 0 || r == 0) {
printf(1, "xwrite: failed %d\n", r); fprintf(1, "xwrite: failed %d\n", r);
return -1; return -1;
} }
buf = (char *) buf + r; buf = (char *) buf + r;
...@@ -59,7 +59,7 @@ error(int s, int code) ...@@ -59,7 +59,7 @@ error(int s, int code)
r = strlen(buf); r = strlen(buf);
if (xwrite(s, buf, r)) if (xwrite(s, buf, r))
printf(2, "httpd error: incomplete write\n"); fprintf(2, "httpd error: incomplete write\n");
} }
static int static int
...@@ -128,7 +128,7 @@ content(int s, int fd) ...@@ -128,7 +128,7 @@ content(int s, int fd)
for (;;) { for (;;) {
n = read(fd, buf, sizeof(buf)); n = read(fd, buf, sizeof(buf));
if (n < 0) { if (n < 0) {
printf(2, "send_data: read failed %d\n", n); fprintf(2, "send_data: read failed %d\n", n);
return n; return n;
} else if (n == 0) { } else if (n == 0) {
return 0; return 0;
...@@ -154,7 +154,7 @@ resp(int s, const char *url) ...@@ -154,7 +154,7 @@ resp(int s, const char *url)
r = fstat(fd, &stat); r = fstat(fd, &stat);
if (r < 0) { if (r < 0) {
printf(2, "httpd resp: fstat %d\n", r); fprintf(2, "httpd resp: fstat %d\n", r);
close(fd); close(fd);
return error(s, 404); return error(s, 404);
} }
...@@ -227,7 +227,7 @@ client(int s) ...@@ -227,7 +227,7 @@ client(int s)
r = read(s, b, NELEM(b)-1); r = read(s, b, NELEM(b)-1);
if (r < 0) if (r < 0)
printf(1, "httpd client: read %d\n", r); fprintf(1, "httpd client: read %d\n", r);
b[r] = 0; b[r] = 0;
r = parse(b, &url); r = parse(b, &url);
...@@ -236,7 +236,7 @@ client(int s) ...@@ -236,7 +236,7 @@ client(int s)
return; return;
} }
printf(1, "httpd client: url %s\n", url); fprintf(1, "httpd client: url %s\n", url);
resp(s, url); resp(s, url);
free(url); free(url);
} }
...@@ -263,7 +263,7 @@ main(void) ...@@ -263,7 +263,7 @@ main(void)
if (r < 0) if (r < 0)
die("httpd listen: %d\n", r); die("httpd listen: %d\n", r);
printf(1, "httpd: port 80\n"); fprintf(1, "httpd: port 80\n");
for (;;) { for (;;) {
socklen_t socklen; socklen_t socklen;
...@@ -272,10 +272,10 @@ main(void) ...@@ -272,10 +272,10 @@ main(void)
socklen = sizeof(sin); socklen = sizeof(sin);
ss = accept(s, (struct sockaddr *)&sin, &socklen); ss = accept(s, (struct sockaddr *)&sin, &socklen);
if (ss < 0) { if (ss < 0) {
printf(2, "telnetd accept: %d\n", ss); fprintf(2, "telnetd accept: %d\n", ss);
continue; continue;
} }
printf(1, "httpd: connection %s\n", ipaddr(&sin)); fprintf(1, "httpd: connection %s\n", ipaddr(&sin));
client(ss); client(ss);
close(ss); close(ss);
......
...@@ -21,12 +21,12 @@ startone(const char **argv) ...@@ -21,12 +21,12 @@ startone(const char **argv)
pid = fork(0); pid = fork(0);
if(pid < 0){ if(pid < 0){
printf(1, "init: fork failed\n"); fprintf(1, "init: fork failed\n");
exit(); exit();
} }
if(pid == 0){ if(pid == 0){
exec(argv[0], argv); exec(argv[0], argv);
printf(1, "init: exec %s failed\n", argv[0]); fprintf(1, "init: exec %s failed\n", argv[0]);
exit(); exit();
} }
return pid; return pid;
...@@ -46,11 +46,11 @@ main(void) ...@@ -46,11 +46,11 @@ main(void)
mkdir("dev"); mkdir("dev");
if (mknod("/dev/netif", 2, 1) < 0) if (mknod("/dev/netif", 2, 1) < 0)
printf(2, "init: mknod netif failed\n"); fprintf(2, "init: mknod netif failed\n");
if (mknod("/dev/sampler", 3, 1) < 0) if (mknod("/dev/sampler", 3, 1) < 0)
printf(2, "init: mknod sampler failed\n"); fprintf(2, "init: mknod sampler failed\n");
if (mknod("/dev/lockstat", 4, 1) < 0) if (mknod("/dev/lockstat", 4, 1) < 0)
printf(2, "init: mknod lockstat failed\n"); fprintf(2, "init: mknod lockstat failed\n");
for (u32 i = 0; i < NELEM(app_argv); i++) for (u32 i = 0; i < NELEM(app_argv); i++)
startone(app_argv[i]); startone(app_argv[i]);
...@@ -58,6 +58,6 @@ main(void) ...@@ -58,6 +58,6 @@ main(void)
for(;;){ for(;;){
pid = startone(sh_argv); pid = startone(sh_argv);
while((wpid=wait()) >= 0 && wpid != pid) while((wpid=wait()) >= 0 && wpid != pid)
printf(1, "zombie!\n"); fprintf(1, "zombie!\n");
} }
} }
...@@ -29,8 +29,8 @@ stats(void) ...@@ -29,8 +29,8 @@ stats(void)
if (sfd < 0) if (sfd < 0)
die("lockstat: open failed"); die("lockstat: open failed");
printf(1, "## name acquires contends locking locked\n"); fprintf(1, "## name acquires contends locking locked\n");
printf(sfd, "## name acquires contends locking locked\n"); fprintf(sfd, "## name acquires contends locking locked\n");
while (1) { while (1) {
r = read(fd, &ls, sz); r = read(fd, &ls, sz);
...@@ -51,9 +51,9 @@ stats(void) ...@@ -51,9 +51,9 @@ stats(void)
locked += ls.cpu[i].locked; locked += ls.cpu[i].locked;
} }
if (contends > 0) { if (contends > 0) {
printf(1, "%s %lu %lu %lu %lu\n", fprintf(1, "%s %lu %lu %lu %lu\n",
ls.name, acquires, contends, locking, locked); ls.name, acquires, contends, locking, locked);
printf(sfd, "%s %lu %lu %lu %lu\n", fprintf(sfd, "%s %lu %lu %lu %lu\n",
ls.name, acquires, contends, locking, locked); ls.name, acquires, contends, locking, locked);
} }
} }
......
...@@ -24,7 +24,7 @@ main(void) ...@@ -24,7 +24,7 @@ main(void)
{ {
const char *pw; const char *pw;
printf(1, "password: "); fprintf(1, "password: ");
pw = readpw(); pw = readpw();
if (pw && !strcmp(pw, "xv6")) { if (pw && !strcmp(pw, "xv6")) {
......
...@@ -31,24 +31,24 @@ ls(const char *path) ...@@ -31,24 +31,24 @@ ls(const char *path)
struct stat st; struct stat st;
if((fd = open(path, 0)) < 0){ if((fd = open(path, 0)) < 0){
printf(2, "ls: cannot open %s\n", path); fprintf(2, "ls: cannot open %s\n", path);
return; return;
} }
if(fstat(fd, &st) < 0){ if(fstat(fd, &st) < 0){
printf(2, "ls: cannot stat %s\n", path); fprintf(2, "ls: cannot stat %s\n", path);
close(fd); close(fd);
return; return;
} }
switch(st.type){ switch(st.type){
case T_FILE: case T_FILE:
printf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size); fprintf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size);
break; break;
case T_DIR: case T_DIR:
if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf){ if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf){
printf(1, "ls: path too long\n"); fprintf(1, "ls: path too long\n");
break; break;
} }
strcpy(buf, path); strcpy(buf, path);
...@@ -60,10 +60,10 @@ ls(const char *path) ...@@ -60,10 +60,10 @@ ls(const char *path)
memmove(p, de.name, DIRSIZ); memmove(p, de.name, DIRSIZ);
p[DIRSIZ] = 0; p[DIRSIZ] = 0;
if(stat(buf, &st) < 0){ if(stat(buf, &st) < 0){
printf(1, "ls: cannot stat %s\n", buf); fprintf(1, "ls: cannot stat %s\n", buf);
continue; continue;
} }
printf(1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size); fprintf(1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size);
} }
break; break;
} }
......
...@@ -21,7 +21,7 @@ thr(void *arg) ...@@ -21,7 +21,7 @@ thr(void *arg)
volatile char *p = (char*) (0x40000UL + tid * 8 * 4096); volatile char *p = (char*) (0x40000UL + tid * 8 * 4096);
if (map((void *) p, 8 * 4096) < 0) { if (map((void *) p, 8 * 4096) < 0) {
printf(1, "%d: map failed\n", tid); fprintf(1, "%d: map failed\n", tid);
exit(); exit();
} }
...@@ -31,13 +31,13 @@ thr(void *arg) ...@@ -31,13 +31,13 @@ thr(void *arg)
} }
if (unmap((void *) p, 8 * 4096) < 0) { if (unmap((void *) p, 8 * 4096) < 0) {
printf(1, "%d: unmap failed\n", tid); fprintf(1, "%d: unmap failed\n", tid);
exit(); exit();
} }
} }
acquire(&l); acquire(&l);
// printf(1, "mapbench[%d]: done\n", getpid()); // fprintf(1, "mapbench[%d]: done\n", getpid());
tcount++; tcount++;
release(&l); release(&l);
} }
...@@ -48,26 +48,26 @@ main(int ac, char **av) ...@@ -48,26 +48,26 @@ main(int ac, char **av)
mtenable("xv6-mapbench"); mtenable("xv6-mapbench");
if (ac != 2) { if (ac != 2) {
printf(1, "usage: %s nthreads\n", av[0]); fprintf(1, "usage: %s nthreads\n", av[0]);
exit(); exit();
} }
int nthread = atoi(av[1]); int nthread = atoi(av[1]);
acquire(&l); acquire(&l);
// printf(1, "mapbench[%d]: start esp %x, nthread=%d\n", getpid(), rrsp(), nthread); // fprintf(1, "mapbench[%d]: start esp %x, nthread=%d\n", getpid(), rrsp(), nthread);
for(int i = 0; i < nthread; i++) { for(int i = 0; i < nthread; i++) {
sbrk(8192); sbrk(8192);
void *tstack = sbrk(0); void *tstack = sbrk(0);
// printf(1, "tstack %lx\n", tstack); // fprintf(1, "tstack %lx\n", tstack);
int tid = forkt(tstack, (void*) thr, (void *)(u64)i); int tid = forkt(tstack, (void*) thr, (void *)(u64)i);
if (0) printf(1, "mapbench[%d]: child %d\n", getpid(), tid); if (0) fprintf(1, "mapbench[%d]: child %d\n", getpid(), tid);
} }
for(;;){ for(;;){
int lastc = tcount; int lastc = tcount;
// printf(1, "mapbench[%d]: tcount=%d\n", getpid(), lastc); // fprintf(1, "mapbench[%d]: tcount=%d\n", getpid(), lastc);
release(&l); release(&l);
if(lastc==nthread) if(lastc==nthread)
break; break;
...@@ -76,7 +76,7 @@ main(int ac, char **av) ...@@ -76,7 +76,7 @@ main(int ac, char **av)
acquire(&l); acquire(&l);
} }
release(&l); release(&l);
// printf(1, "mapbench[%d]: done\n", getpid()); // fprintf(1, "mapbench[%d]: done\n", getpid());
for(int i = 0; i < nthread; i++) for(int i = 0; i < nthread; i++)
wait(); wait();
......
...@@ -30,14 +30,14 @@ thr(void) ...@@ -30,14 +30,14 @@ thr(void)
if (state == 3) { if (state == 3) {
state = 4; state = 4;
printf(1, "about to access after unmap\n"); fprintf(1, "about to access after unmap\n");
release(&l); release(&l);
p[0] = 'X'; p[0] = 'X';
p[4096] = 'Y'; p[4096] = 'Y';
acquire(&l); acquire(&l);
printf(1, "still alive after unmap write\n"); fprintf(1, "still alive after unmap write\n");
exit(); exit();
} }
release(&l); release(&l);
...@@ -50,7 +50,7 @@ main(void) ...@@ -50,7 +50,7 @@ main(void)
{ {
p = (char *) 0x80000; p = (char *) 0x80000;
if (map((void *) p, 8192) < 0) { if (map((void *) p, 8192) < 0) {
printf(1, "map failed\n"); fprintf(1, "map failed\n");
exit(); exit();
} }
...@@ -66,25 +66,25 @@ main(void) ...@@ -66,25 +66,25 @@ main(void)
} }
if (p[0] != 'x' || p[4096] != 'y') { if (p[0] != 'x' || p[4096] != 'y') {
printf(1, "mismatch\n"); fprintf(1, "mismatch\n");
exit(); exit();
} }
printf(1, "shm ok\n"); fprintf(1, "shm ok\n");
if (unmap((void *) p, 8192) < 0) { if (unmap((void *) p, 8192) < 0) {
printf(1, "unmap failed\n"); fprintf(1, "unmap failed\n");
exit(); exit();
} }
state = 3; state = 3;
printf(1, "waiting for unmap access\n"); fprintf(1, "waiting for unmap access\n");
while (state != 4) { while (state != 4) {
release(&l); release(&l);
spin(); spin();
acquire(&l); acquire(&l);
} }
printf(1, "maptest done\n"); fprintf(1, "maptest done\n");
exit(); exit();
} }
...@@ -73,7 +73,7 @@ kernlet_pread(int fd, size_t count, off_t off) ...@@ -73,7 +73,7 @@ kernlet_pread(int fd, size_t count, off_t off)
msgid = ipc_msg_alloc(); msgid = ipc_msg_alloc();
if (msgid == NULL_MSGID) { if (msgid == NULL_MSGID) {
printf(2, "kernlet_pread: ipc_alloc_msg failed"); fprintf(2, "kernlet_pread: ipc_alloc_msg failed");
return; return;
} }
...@@ -81,7 +81,7 @@ kernlet_pread(int fd, size_t count, off_t off) ...@@ -81,7 +81,7 @@ kernlet_pread(int fd, size_t count, off_t off)
die("kernlet_pread: count oops"); die("kernlet_pread: count oops");
pageid = ipc_page_alloc(); pageid = ipc_page_alloc();
if (pageid == NULL_PAGEID) { if (pageid == NULL_PAGEID) {
printf(2, "kernlet_pread: ipc_alloc_page failed"); fprintf(2, "kernlet_pread: ipc_alloc_page failed");
return; return;
} }
...@@ -152,8 +152,8 @@ main(int ac, char **av) ...@@ -152,8 +152,8 @@ main(int ac, char **av)
} }
t1 = rdtsc(); t1 = rdtsc();
printf(1, "usekernlet %u\n", usekernlet); fprintf(1, "usekernlet %u\n", usekernlet);
printf(1, "cycles %lu\n", t1 - t0); fprintf(1, "cycles %lu\n", t1 - t0);
exit(); exit();
} }
...@@ -13,7 +13,7 @@ writec(int c, void *arg) ...@@ -13,7 +13,7 @@ writec(int c, void *arg)
} }
void void
printf(int fd, const char *fmt, ...) fprintf(int fd, const char *fmt, ...)
{ {
va_list ap; va_list ap;
...@@ -64,6 +64,6 @@ die(const char* errstr, ...) ...@@ -64,6 +64,6 @@ die(const char* errstr, ...)
va_start(ap, errstr); va_start(ap, errstr);
vprintfmt(writec, (void*) (u64)1, errstr, ap); vprintfmt(writec, (void*) (u64)1, errstr, ap);
va_end(ap); va_end(ap);
printf(1, "\n"); fprintf(2, "\n");
exit(); exit();
} }
...@@ -76,14 +76,14 @@ runcmd(struct cmd *cmd) ...@@ -76,14 +76,14 @@ runcmd(struct cmd *cmd)
if(ecmd->argv[0] == 0) if(ecmd->argv[0] == 0)
exit(); exit();
exec(ecmd->argv[0], ecmd->argv); exec(ecmd->argv[0], ecmd->argv);
printf(2, "exec %s failed\n", ecmd->argv[0]); fprintf(2, "exec %s failed\n", ecmd->argv[0]);
break; break;
case REDIR: case REDIR:
rcmd = (struct redircmd*)cmd; rcmd = (struct redircmd*)cmd;
close(rcmd->fd); close(rcmd->fd);
if(open(rcmd->file, rcmd->mode) < 0){ if(open(rcmd->file, rcmd->mode) < 0){
printf(2, "open %s failed\n", rcmd->file); fprintf(2, "open %s failed\n", rcmd->file);
exit(); exit();
} }
runcmd(rcmd->cmd); runcmd(rcmd->cmd);
...@@ -133,7 +133,7 @@ runcmd(struct cmd *cmd) ...@@ -133,7 +133,7 @@ runcmd(struct cmd *cmd)
int int
getcmd(char *buf, int nbuf) getcmd(char *buf, int nbuf)
{ {
printf(2, "$ "); fprintf(2, "$ ");
memset(buf, 0, nbuf); memset(buf, 0, nbuf);
gets(buf, nbuf); gets(buf, nbuf);
if(buf[0] == 0) // EOF if(buf[0] == 0) // EOF
...@@ -162,7 +162,7 @@ main(void) ...@@ -162,7 +162,7 @@ main(void)
// Chdir has no effect on the parent if run in the child. // Chdir has no effect on the parent if run in the child.
buf[strlen(buf)-1] = 0; // chop \n buf[strlen(buf)-1] = 0; // chop \n
if(chdir(buf+3) < 0) if(chdir(buf+3) < 0)
printf(2, "cannot cd %s\n", buf+3); fprintf(2, "cannot cd %s\n", buf+3);
continue; continue;
} }
if(fork1() == 0) if(fork1() == 0)
...@@ -175,7 +175,7 @@ main(void) ...@@ -175,7 +175,7 @@ main(void)
void void
panic(const char *s) panic(const char *s)
{ {
printf(2, "%s\n", s); fprintf(2, "%s\n", s);
exit(); exit();
} }
...@@ -335,7 +335,7 @@ parsecmd(char *s) ...@@ -335,7 +335,7 @@ parsecmd(char *s)
cmd = parseline(&s, es); cmd = parseline(&s, es);
peek(&s, es, ""); peek(&s, es, "");
if(s != es){ if(s != es){
printf(2, "leftovers: %s\n", s); fprintf(2, "leftovers: %s\n", s);
panic("syntax"); panic("syntax");
} }
nulterminate(cmd); nulterminate(cmd);
......
...@@ -8,7 +8,7 @@ int ...@@ -8,7 +8,7 @@ int
main(int ac, char *av[]) main(int ac, char *av[])
{ {
if (ac != 2) { if (ac != 2) {
printf(1, "Usage: %s ticks\n", av[0]); fprintf(1, "Usage: %s ticks\n", av[0]);
exit(); exit();
} }
......
...@@ -24,7 +24,7 @@ main(void) ...@@ -24,7 +24,7 @@ main(void)
if (r < 0) if (r < 0)
die("telnetd listen: %d\n", r); die("telnetd listen: %d\n", r);
printf(1, "telnetd: port 23\n"); fprintf(1, "telnetd: port 23\n");
for (;;) { for (;;) {
socklen_t socklen; socklen_t socklen;
...@@ -34,14 +34,14 @@ main(void) ...@@ -34,14 +34,14 @@ main(void)
socklen = sizeof(sin); socklen = sizeof(sin);
ss = accept(s, (struct sockaddr *)&sin, &socklen); ss = accept(s, (struct sockaddr *)&sin, &socklen);
if (ss < 0) { if (ss < 0) {
printf(2, "telnetd accept: %d\n", ss); fprintf(2, "telnetd accept: %d\n", ss);
continue; continue;
} }
printf(1, "telnetd: connection %s\n", ipaddr(&sin)); fprintf(1, "telnetd: connection %s\n", ipaddr(&sin));
pid = fork(0); pid = fork(0);
if (pid < 0) { if (pid < 0) {
printf(2, "telnetd fork: %d\n", pid); fprintf(2, "telnetd fork: %d\n", pid);
close(ss); close(ss);
continue; continue;
} }
...@@ -58,6 +58,6 @@ main(void) ...@@ -58,6 +58,6 @@ main(void)
} }
close(ss); close(ss);
wait(); wait();
printf(1, "telnetd: connection closed\n"); fprintf(1, "telnetd: connection closed\n");
} }
} }
...@@ -13,7 +13,7 @@ void ...@@ -13,7 +13,7 @@ void
thr(void *arg) thr(void *arg)
{ {
acquire(&l); acquire(&l);
printf(1, "thrtest[%d]: arg 0x%lx rsp %lx\n", getpid(), arg, rrsp()); fprintf(1, "thrtest[%d]: arg 0x%lx rsp %lx\n", getpid(), arg, rrsp());
tcount++; tcount++;
release(&l); release(&l);
exit(); exit();
...@@ -23,18 +23,18 @@ int ...@@ -23,18 +23,18 @@ int
main(void) main(void)
{ {
acquire(&l); acquire(&l);
printf(1, "thrtest[%d]: start esp %x\n", getpid(), rrsp()); fprintf(1, "thrtest[%d]: start esp %x\n", getpid(), rrsp());
for(int i = 0; i < nthread; i++) { for(int i = 0; i < nthread; i++) {
sbrk(8192); sbrk(8192);
void *tstack = sbrk(0); void *tstack = sbrk(0);
int tid = forkt(tstack, (void*) thr, (void*)(u64)(0xc0ffee00|i)); int tid = forkt(tstack, (void*) thr, (void*)(u64)(0xc0ffee00|i));
printf(1, "thrtest[%d]: child %d\n", getpid(), tid); fprintf(1, "thrtest[%d]: child %d\n", getpid(), tid);
} }
for(;;){ for(;;){
int lastc = tcount; int lastc = tcount;
printf(1, "thrtest[%d]: tcount=%d\n", getpid(), lastc); fprintf(1, "thrtest[%d]: tcount=%d\n", getpid(), lastc);
release(&l); release(&l);
if(lastc==nthread) if(lastc==nthread)
break; break;
...@@ -43,7 +43,7 @@ main(void) ...@@ -43,7 +43,7 @@ main(void)
acquire(&l); acquire(&l);
} }
release(&l); release(&l);
printf(1, "thrtest[%d]: done\n", getpid()); fprintf(1, "thrtest[%d]: done\n", getpid());
for(int i = 0; i < nthread; i++) for(int i = 0; i < nthread; i++)
wait(); wait();
......
...@@ -11,18 +11,18 @@ main(int ac, const char *av[]) ...@@ -11,18 +11,18 @@ main(int ac, const char *av[])
int pid = fork(0); int pid = fork(0);
if (pid < 0) { if (pid < 0) {
printf(1, "time: fork failed\n"); fprintf(1, "time: fork failed\n");
exit(); exit();
} }
if (pid == 0) { if (pid == 0) {
exec(av[1], av+1); exec(av[1], av+1);
printf(1, "time: exec failed\n"); fprintf(1, "time: exec failed\n");
exit(); exit();
} }
wait(); wait();
u64 t1 = rdtsc(); u64 t1 = rdtsc();
printf(1, "%lu cycles\n", t1-t0); fprintf(1, "%lu cycles\n", t1-t0);
exit(); exit();
} }
...@@ -49,7 +49,7 @@ int atoi(const char*); ...@@ -49,7 +49,7 @@ int atoi(const char*);
int forkt(void *sp, void *pc, void *arg); int forkt(void *sp, void *pc, void *arg);
// printf.c // printf.c
void printf(int, const char*, ...); void fprintf(int, const char*, ...);
void snprintf(char *buf, unsigned int n, const char *fmt, ...); void snprintf(char *buf, unsigned int n, const char *fmt, ...);
void die(const char* errstr, ...) __attribute__((noreturn)); void die(const char* errstr, ...) __attribute__((noreturn));
END_DECLS END_DECLS
...@@ -18,19 +18,19 @@ opentest(void) ...@@ -18,19 +18,19 @@ opentest(void)
{ {
int fd; int fd;
printf(stdout, "open test\n"); fprintf(stdout, "open test\n");
fd = open("echo", 0); fd = open("echo", 0);
if(fd < 0){ if(fd < 0){
printf(stdout, "open echo failed!\n"); fprintf(stdout, "open echo failed!\n");
exit(); exit();
} }
close(fd); close(fd);
fd = open("doesnotexist", 0); fd = open("doesnotexist", 0);
if(fd >= 0){ if(fd >= 0){
printf(stdout, "open doesnotexist succeeded!\n"); fprintf(stdout, "open doesnotexist succeeded!\n");
exit(); exit();
} }
printf(stdout, "open test ok\n"); fprintf(stdout, "open test ok\n");
} }
void void
...@@ -39,47 +39,47 @@ writetest(void) ...@@ -39,47 +39,47 @@ writetest(void)
int fd; int fd;
int i; int i;
printf(stdout, "small file test\n"); fprintf(stdout, "small file test\n");
fd = open("small", O_CREATE|O_RDWR); fd = open("small", O_CREATE|O_RDWR);
if(fd >= 0){ if(fd >= 0){
printf(stdout, "creat small succeeded; ok\n"); fprintf(stdout, "creat small succeeded; ok\n");
} else { } else {
printf(stdout, "error: creat small failed!\n"); fprintf(stdout, "error: creat small failed!\n");
exit(); exit();
} }
for(i = 0; i < 100; i++){ for(i = 0; i < 100; i++){
if(write(fd, "aaaaaaaaaa", 10) != 10){ if(write(fd, "aaaaaaaaaa", 10) != 10){
printf(stdout, "error: write aa %d new file failed\n", i); fprintf(stdout, "error: write aa %d new file failed\n", i);
exit(); exit();
} }
if(write(fd, "bbbbbbbbbb", 10) != 10){ if(write(fd, "bbbbbbbbbb", 10) != 10){
printf(stdout, "error: write bb %d new file failed\n", i); fprintf(stdout, "error: write bb %d new file failed\n", i);
exit(); exit();
} }
} }
printf(stdout, "writes ok\n"); fprintf(stdout, "writes ok\n");
close(fd); close(fd);
fd = open("small", O_RDONLY); fd = open("small", O_RDONLY);
if(fd >= 0){ if(fd >= 0){
printf(stdout, "open small succeeded ok\n"); fprintf(stdout, "open small succeeded ok\n");
} else { } else {
printf(stdout, "error: open small failed!\n"); fprintf(stdout, "error: open small failed!\n");
exit(); exit();
} }
i = read(fd, buf, 2000); i = read(fd, buf, 2000);
if(i == 2000){ if(i == 2000){
printf(stdout, "read succeeded ok\n"); fprintf(stdout, "read succeeded ok\n");
} else { } else {
printf(stdout, "read failed\n"); fprintf(stdout, "read failed\n");
exit(); exit();
} }
close(fd); close(fd);
if(unlink("small") < 0){ if(unlink("small") < 0){
printf(stdout, "unlink small failed\n"); fprintf(stdout, "unlink small failed\n");
exit(); exit();
} }
printf(stdout, "small file test ok\n"); fprintf(stdout, "small file test ok\n");
} }
void void
...@@ -87,18 +87,18 @@ writetest1(void) ...@@ -87,18 +87,18 @@ writetest1(void)
{ {
int fd, n; int fd, n;
printf(stdout, "big files test\n"); fprintf(stdout, "big files test\n");
fd = open("big", O_CREATE|O_RDWR); fd = open("big", O_CREATE|O_RDWR);
if(fd < 0){ if(fd < 0){
printf(stdout, "error: creat big failed!\n"); fprintf(stdout, "error: creat big failed!\n");
exit(); exit();
} }
for(u32 i = 0; i < MAXFILE; i++){ for(u32 i = 0; i < MAXFILE; i++){
((int*)buf)[0] = i; ((int*)buf)[0] = i;
if(write(fd, buf, 512) != 512){ if(write(fd, buf, 512) != 512){
printf(stdout, "error: write big file failed\n", i); fprintf(stdout, "error: write big file failed\n", i);
exit(); exit();
} }
} }
...@@ -107,7 +107,7 @@ writetest1(void) ...@@ -107,7 +107,7 @@ writetest1(void)
fd = open("big", O_RDONLY); fd = open("big", O_RDONLY);
if(fd < 0){ if(fd < 0){
printf(stdout, "error: open big failed!\n"); fprintf(stdout, "error: open big failed!\n");
exit(); exit();
} }
...@@ -116,16 +116,16 @@ writetest1(void) ...@@ -116,16 +116,16 @@ writetest1(void)
u32 i = read(fd, buf, 512); u32 i = read(fd, buf, 512);
if(i == 0){ if(i == 0){
if(n == MAXFILE - 1){ if(n == MAXFILE - 1){
printf(stdout, "read only %d blocks from big", n); fprintf(stdout, "read only %d blocks from big", n);
exit(); exit();
} }
break; break;
} else if(i != 512){ } else if(i != 512){
printf(stdout, "read failed %d\n", i); fprintf(stdout, "read failed %d\n", i);
exit(); exit();
} }
if(((int*)buf)[0] != n){ if(((int*)buf)[0] != n){
printf(stdout, "read content of block %d is %d\n", fprintf(stdout, "read content of block %d is %d\n",
n, ((int*)buf)[0]); n, ((int*)buf)[0]);
exit(); exit();
} }
...@@ -133,10 +133,10 @@ writetest1(void) ...@@ -133,10 +133,10 @@ writetest1(void)
} }
close(fd); close(fd);
if(unlink("big") < 0){ if(unlink("big") < 0){
printf(stdout, "unlink big failed\n"); fprintf(stdout, "unlink big failed\n");
exit(); exit();
} }
printf(stdout, "big files ok\n"); fprintf(stdout, "big files ok\n");
} }
void void
...@@ -144,7 +144,7 @@ createtest(void) ...@@ -144,7 +144,7 @@ createtest(void)
{ {
int i, fd; int i, fd;
printf(stdout, "many creates, followed by unlink test\n"); fprintf(stdout, "many creates, followed by unlink test\n");
name[0] = 'a'; name[0] = 'a';
name[2] = '\0'; name[2] = '\0';
...@@ -159,41 +159,41 @@ createtest(void) ...@@ -159,41 +159,41 @@ createtest(void)
name[1] = '0' + i; name[1] = '0' + i;
unlink(name); unlink(name);
} }
printf(stdout, "many creates, followed by unlink; ok\n"); fprintf(stdout, "many creates, followed by unlink; ok\n");
} }
void dirtest(void) void dirtest(void)
{ {
printf(stdout, "mkdir test\n"); fprintf(stdout, "mkdir test\n");
if(mkdir("dir0") < 0){ if(mkdir("dir0") < 0){
printf(stdout, "mkdir failed\n"); fprintf(stdout, "mkdir failed\n");
exit(); exit();
} }
if(chdir("dir0") < 0){ if(chdir("dir0") < 0){
printf(stdout, "chdir dir0 failed\n"); fprintf(stdout, "chdir dir0 failed\n");
exit(); exit();
} }
if(chdir("..") < 0){ if(chdir("..") < 0){
printf(stdout, "chdir .. failed\n"); fprintf(stdout, "chdir .. failed\n");
exit(); exit();
} }
if(unlink("dir0") < 0){ if(unlink("dir0") < 0){
printf(stdout, "unlink dir0 failed\n"); fprintf(stdout, "unlink dir0 failed\n");
exit(); exit();
} }
printf(stdout, "mkdir test\n"); fprintf(stdout, "mkdir test\n");
} }
void void
exectest(void) exectest(void)
{ {
printf(stdout, "exec test\n"); fprintf(stdout, "exec test\n");
if(exec("echo", echoargv) < 0){ if(exec("echo", echoargv) < 0){
printf(stdout, "exec echo failed\n"); fprintf(stdout, "exec echo failed\n");
exit(); exit();
} }
} }
...@@ -207,7 +207,7 @@ pipe1(void) ...@@ -207,7 +207,7 @@ pipe1(void)
int seq, i, n, cc, total; int seq, i, n, cc, total;
if(pipe(fds) != 0){ if(pipe(fds) != 0){
printf(1, "pipe() failed\n"); fprintf(1, "pipe() failed\n");
exit(); exit();
} }
pid = fork(0); pid = fork(0);
...@@ -218,7 +218,7 @@ pipe1(void) ...@@ -218,7 +218,7 @@ pipe1(void)
for(i = 0; i < 1033; i++) for(i = 0; i < 1033; i++)
buf[i] = seq++; buf[i] = seq++;
if(write(fds[1], buf, 1033) != 1033){ if(write(fds[1], buf, 1033) != 1033){
printf(1, "pipe1 oops 1\n"); fprintf(1, "pipe1 oops 1\n");
exit(); exit();
} }
} }
...@@ -230,7 +230,7 @@ pipe1(void) ...@@ -230,7 +230,7 @@ pipe1(void)
while((n = read(fds[0], buf, cc)) > 0){ while((n = read(fds[0], buf, cc)) > 0){
for(i = 0; i < n; i++){ for(i = 0; i < n; i++){
if((buf[i] & 0xff) != (seq++ & 0xff)){ if((buf[i] & 0xff) != (seq++ & 0xff)){
printf(1, "pipe1 oops 2\n"); fprintf(1, "pipe1 oops 2\n");
return; return;
} }
} }
...@@ -240,14 +240,14 @@ pipe1(void) ...@@ -240,14 +240,14 @@ pipe1(void)
cc = sizeof(buf); cc = sizeof(buf);
} }
if(total != 5 * 1033) if(total != 5 * 1033)
printf(1, "pipe1 oops 3 total %d\n", total); fprintf(1, "pipe1 oops 3 total %d\n", total);
close(fds[0]); close(fds[0]);
wait(); wait();
} else { } else {
printf(1, "fork(0) failed\n"); fprintf(1, "fork(0) failed\n");
exit(); exit();
} }
printf(1, "pipe1 ok\n"); fprintf(1, "pipe1 ok\n");
} }
// meant to be run w/ at most two CPUs // meant to be run w/ at most two CPUs
...@@ -257,7 +257,7 @@ preempt(void) ...@@ -257,7 +257,7 @@ preempt(void)
int pid1, pid2, pid3; int pid1, pid2, pid3;
int pfds[2]; int pfds[2];
printf(1, "preempt: "); fprintf(1, "preempt: ");
pid1 = fork(0); pid1 = fork(0);
if(pid1 == 0) if(pid1 == 0)
for(;;) for(;;)
...@@ -273,7 +273,7 @@ preempt(void) ...@@ -273,7 +273,7 @@ preempt(void)
if(pid3 == 0){ if(pid3 == 0){
close(pfds[0]); close(pfds[0]);
if(write(pfds[1], "x", 1) != 1) if(write(pfds[1], "x", 1) != 1)
printf(1, "preempt write error"); fprintf(1, "preempt write error");
close(pfds[1]); close(pfds[1]);
for(;;) for(;;)
; ;
...@@ -281,19 +281,19 @@ preempt(void) ...@@ -281,19 +281,19 @@ preempt(void)
close(pfds[1]); close(pfds[1]);
if(read(pfds[0], buf, sizeof(buf)) != 1){ if(read(pfds[0], buf, sizeof(buf)) != 1){
printf(1, "preempt read error"); fprintf(1, "preempt read error");
return; return;
} }
close(pfds[0]); close(pfds[0]);
printf(1, "kill... "); fprintf(1, "kill... ");
kill(pid1); kill(pid1);
kill(pid2); kill(pid2);
kill(pid3); kill(pid3);
printf(1, "wait... "); fprintf(1, "wait... ");
wait(); wait();
wait(); wait();
wait(); wait();
printf(1, "preempt ok\n"); fprintf(1, "preempt ok\n");
} }
// try to find any races between exit and wait // try to find any races between exit and wait
...@@ -305,19 +305,19 @@ exitwait(void) ...@@ -305,19 +305,19 @@ exitwait(void)
for(i = 0; i < 100; i++){ for(i = 0; i < 100; i++){
pid = fork(0); pid = fork(0);
if(pid < 0){ if(pid < 0){
printf(1, "fork failed\n"); fprintf(1, "fork failed\n");
return; return;
} }
if(pid){ if(pid){
if(wait() != pid){ if(wait() != pid){
printf(1, "wait wrong pid\n"); fprintf(1, "wait wrong pid\n");
return; return;
} }
} else { } else {
exit(); exit();
} }
} }
printf(1, "exitwait ok\n"); fprintf(1, "exitwait ok\n");
} }
void void
...@@ -326,7 +326,7 @@ mem(void) ...@@ -326,7 +326,7 @@ mem(void)
void *m1, *m2; void *m1, *m2;
int pid, ppid; int pid, ppid;
printf(1, "mem test\n"); fprintf(1, "mem test\n");
ppid = getpid(); ppid = getpid();
if((pid = fork(0)) == 0){ if((pid = fork(0)) == 0){
m1 = 0; m1 = 0;
...@@ -341,12 +341,12 @@ mem(void) ...@@ -341,12 +341,12 @@ mem(void)
} }
m1 = malloc(1024*20); m1 = malloc(1024*20);
if(m1 == 0){ if(m1 == 0){
printf(1, "couldn't allocate mem?!!\n"); fprintf(1, "couldn't allocate mem?!!\n");
kill(ppid); kill(ppid);
exit(); exit();
} }
free(m1); free(m1);
printf(1, "mem ok\n"); fprintf(1, "mem ok\n");
exit(); exit();
} else { } else {
wait(); wait();
...@@ -366,14 +366,14 @@ sharedfd(void) ...@@ -366,14 +366,14 @@ sharedfd(void)
unlink("sharedfd"); unlink("sharedfd");
fd = open("sharedfd", O_CREATE|O_RDWR); fd = open("sharedfd", O_CREATE|O_RDWR);
if(fd < 0){ if(fd < 0){
printf(1, "fstests: cannot open sharedfd for writing"); fprintf(1, "fstests: cannot open sharedfd for writing");
return; return;
} }
pid = fork(0); pid = fork(0);
memset(buf, pid==0?'c':'p', sizeof(buf)); memset(buf, pid==0?'c':'p', sizeof(buf));
for(i = 0; i < 1000; i++){ for(i = 0; i < 1000; i++){
if(write(fd, buf, sizeof(buf)) != sizeof(buf)){ if(write(fd, buf, sizeof(buf)) != sizeof(buf)){
printf(1, "fstests: write sharedfd failed\n"); fprintf(1, "fstests: write sharedfd failed\n");
break; break;
} }
} }
...@@ -384,7 +384,7 @@ sharedfd(void) ...@@ -384,7 +384,7 @@ sharedfd(void)
close(fd); close(fd);
fd = open("sharedfd", 0); fd = open("sharedfd", 0);
if(fd < 0){ if(fd < 0){
printf(1, "fstests: cannot open sharedfd for reading\n"); fprintf(1, "fstests: cannot open sharedfd for reading\n");
return; return;
} }
nc = np = 0; nc = np = 0;
...@@ -399,9 +399,9 @@ sharedfd(void) ...@@ -399,9 +399,9 @@ sharedfd(void)
close(fd); close(fd);
unlink("sharedfd"); unlink("sharedfd");
if(nc == 10000 && np == 10000) if(nc == 10000 && np == 10000)
printf(1, "sharedfd ok\n"); fprintf(1, "sharedfd ok\n");
else else
printf(1, "sharedfd oops %d %d\n", nc, np); fprintf(1, "sharedfd oops %d %d\n", nc, np);
} }
// two processes write two different files at the same // two processes write two different files at the same
...@@ -412,28 +412,28 @@ twofiles(void) ...@@ -412,28 +412,28 @@ twofiles(void)
int fd, pid, i, j, n, total; int fd, pid, i, j, n, total;
const char *fname; const char *fname;
printf(1, "twofiles test\n"); fprintf(1, "twofiles test\n");
unlink("f1"); unlink("f1");
unlink("f2"); unlink("f2");
pid = fork(0); pid = fork(0);
if(pid < 0){ if(pid < 0){
printf(1, "fork failed\n"); fprintf(1, "fork failed\n");
return; return;
} }
fname = pid ? "f1" : "f2"; fname = pid ? "f1" : "f2";
fd = open(fname, O_CREATE | O_RDWR); fd = open(fname, O_CREATE | O_RDWR);
if(fd < 0){ if(fd < 0){
printf(1, "create failed\n"); fprintf(1, "create failed\n");
exit(); exit();
} }
memset(buf, pid?'p':'c', 512); memset(buf, pid?'p':'c', 512);
for(i = 0; i < 12; i++){ for(i = 0; i < 12; i++){
if((n = write(fd, buf, 500)) != 500){ if((n = write(fd, buf, 500)) != 500){
printf(1, "write failed %d\n", n); fprintf(1, "write failed %d\n", n);
exit(); exit();
} }
} }
...@@ -449,7 +449,7 @@ twofiles(void) ...@@ -449,7 +449,7 @@ twofiles(void)
while((n = read(fd, buf, sizeof(buf))) > 0){ while((n = read(fd, buf, sizeof(buf))) > 0){
for(j = 0; j < n; j++){ for(j = 0; j < n; j++){
if(buf[j] != (i?'p':'c')){ if(buf[j] != (i?'p':'c')){
printf(1, "wrong char\n"); fprintf(1, "wrong char\n");
exit(); exit();
} }
} }
...@@ -457,7 +457,7 @@ twofiles(void) ...@@ -457,7 +457,7 @@ twofiles(void)
} }
close(fd); close(fd);
if(total != 12*500){ if(total != 12*500){
printf(1, "wrong length %d\n", total); fprintf(1, "wrong length %d\n", total);
exit(); exit();
} }
} }
...@@ -465,7 +465,7 @@ twofiles(void) ...@@ -465,7 +465,7 @@ twofiles(void)
unlink("f1"); unlink("f1");
unlink("f2"); unlink("f2");
printf(1, "twofiles ok\n"); fprintf(1, "twofiles ok\n");
} }
// two processes create and delete different files in same directory // two processes create and delete different files in same directory
...@@ -476,10 +476,10 @@ createdelete(void) ...@@ -476,10 +476,10 @@ createdelete(void)
int pid, i, fd; int pid, i, fd;
char name[32]; char name[32];
printf(1, "createdelete test\n"); fprintf(1, "createdelete test\n");
pid = fork(0); pid = fork(0);
if(pid < 0){ if(pid < 0){
printf(1, "fork failed\n"); fprintf(1, "fork failed\n");
exit(); exit();
} }
...@@ -489,14 +489,14 @@ createdelete(void) ...@@ -489,14 +489,14 @@ createdelete(void)
name[1] = '0' + i; name[1] = '0' + i;
fd = open(name, O_CREATE | O_RDWR); fd = open(name, O_CREATE | O_RDWR);
if(fd < 0){ if(fd < 0){
printf(1, "create failed\n"); fprintf(1, "create failed\n");
exit(); exit();
} }
close(fd); close(fd);
if(i > 0 && (i % 2 ) == 0){ if(i > 0 && (i % 2 ) == 0){
name[1] = '0' + (i / 2); name[1] = '0' + (i / 2);
if(unlink(name) < 0){ if(unlink(name) < 0){
printf(1, "unlink failed\n"); fprintf(1, "unlink failed\n");
exit(); exit();
} }
} }
...@@ -512,10 +512,10 @@ createdelete(void) ...@@ -512,10 +512,10 @@ createdelete(void)
name[1] = '0' + i; name[1] = '0' + i;
fd = open(name, 0); fd = open(name, 0);
if((i == 0 || i >= N/2) && fd < 0){ if((i == 0 || i >= N/2) && fd < 0){
printf(1, "oops createdelete %s didn't exist\n", name); fprintf(1, "oops createdelete %s didn't exist\n", name);
exit(); exit();
} else if((i >= 1 && i < N/2) && fd >= 0){ } else if((i >= 1 && i < N/2) && fd >= 0){
printf(1, "oops createdelete %s did exist\n", name); fprintf(1, "oops createdelete %s did exist\n", name);
exit(); exit();
} }
if(fd >= 0) if(fd >= 0)
...@@ -525,10 +525,10 @@ createdelete(void) ...@@ -525,10 +525,10 @@ createdelete(void)
name[1] = '0' + i; name[1] = '0' + i;
fd = open(name, 0); fd = open(name, 0);
if((i == 0 || i >= N/2) && fd < 0){ if((i == 0 || i >= N/2) && fd < 0){
printf(1, "oops createdelete %s didn't exist\n", name); fprintf(1, "oops createdelete %s didn't exist\n", name);
exit(); exit();
} else if((i >= 1 && i < N/2) && fd >= 0){ } else if((i >= 1 && i < N/2) && fd >= 0){
printf(1, "oops createdelete %s did exist\n", name); fprintf(1, "oops createdelete %s did exist\n", name);
exit(); exit();
} }
if(fd >= 0) if(fd >= 0)
...@@ -543,7 +543,7 @@ createdelete(void) ...@@ -543,7 +543,7 @@ createdelete(void)
unlink(name); unlink(name);
} }
printf(1, "createdelete ok\n"); fprintf(1, "createdelete ok\n");
} }
// can I unlink a file and still read it? // can I unlink a file and still read it?
...@@ -552,10 +552,10 @@ unlinkread(void) ...@@ -552,10 +552,10 @@ unlinkread(void)
{ {
int fd, fd1; int fd, fd1;
printf(1, "unlinkread test\n"); fprintf(1, "unlinkread test\n");
fd = open("unlinkread", O_CREATE | O_RDWR); fd = open("unlinkread", O_CREATE | O_RDWR);
if(fd < 0){ if(fd < 0){
printf(1, "create unlinkread failed\n"); fprintf(1, "create unlinkread failed\n");
exit(); exit();
} }
write(fd, "hello", 5); write(fd, "hello", 5);
...@@ -563,11 +563,11 @@ unlinkread(void) ...@@ -563,11 +563,11 @@ unlinkread(void)
fd = open("unlinkread", O_RDWR); fd = open("unlinkread", O_RDWR);
if(fd < 0){ if(fd < 0){
printf(1, "open unlinkread failed\n"); fprintf(1, "open unlinkread failed\n");
exit(); exit();
} }
if(unlink("unlinkread") != 0){ if(unlink("unlinkread") != 0){
printf(1, "unlink unlinkread failed\n"); fprintf(1, "unlink unlinkread failed\n");
exit(); exit();
} }
...@@ -576,20 +576,20 @@ unlinkread(void) ...@@ -576,20 +576,20 @@ unlinkread(void)
close(fd1); close(fd1);
if(read(fd, buf, sizeof(buf)) != 5){ if(read(fd, buf, sizeof(buf)) != 5){
printf(1, "unlinkread read failed"); fprintf(1, "unlinkread read failed");
exit(); exit();
} }
if(buf[0] != 'h'){ if(buf[0] != 'h'){
printf(1, "unlinkread wrong data\n"); fprintf(1, "unlinkread wrong data\n");
exit(); exit();
} }
if(write(fd, buf, 10) != 10){ if(write(fd, buf, 10) != 10){
printf(1, "unlinkread write failed\n"); fprintf(1, "unlinkread write failed\n");
exit(); exit();
} }
close(fd); close(fd);
unlink("unlinkread"); unlink("unlinkread");
printf(1, "unlinkread ok\n"); fprintf(1, "unlinkread ok\n");
} }
void void
...@@ -597,61 +597,61 @@ linktest(void) ...@@ -597,61 +597,61 @@ linktest(void)
{ {
int fd; int fd;
printf(1, "linktest\n"); fprintf(1, "linktest\n");
unlink("lf1"); unlink("lf1");
unlink("lf2"); unlink("lf2");
fd = open("lf1", O_CREATE|O_RDWR); fd = open("lf1", O_CREATE|O_RDWR);
if(fd < 0){ if(fd < 0){
printf(1, "create lf1 failed\n"); fprintf(1, "create lf1 failed\n");
exit(); exit();
} }
if(write(fd, "hello", 5) != 5){ if(write(fd, "hello", 5) != 5){
printf(1, "write lf1 failed\n"); fprintf(1, "write lf1 failed\n");
exit(); exit();
} }
close(fd); close(fd);
if(link("lf1", "lf2") < 0){ if(link("lf1", "lf2") < 0){
printf(1, "link lf1 lf2 failed\n"); fprintf(1, "link lf1 lf2 failed\n");
exit(); exit();
} }
unlink("lf1"); unlink("lf1");
if(open("lf1", 0) >= 0){ if(open("lf1", 0) >= 0){
printf(1, "unlinked lf1 but it is still there!\n"); fprintf(1, "unlinked lf1 but it is still there!\n");
exit(); exit();
} }
fd = open("lf2", 0); fd = open("lf2", 0);
if(fd < 0){ if(fd < 0){
printf(1, "open lf2 failed\n"); fprintf(1, "open lf2 failed\n");
exit(); exit();
} }
if(read(fd, buf, sizeof(buf)) != 5){ if(read(fd, buf, sizeof(buf)) != 5){
printf(1, "read lf2 failed\n"); fprintf(1, "read lf2 failed\n");
exit(); exit();
} }
close(fd); close(fd);
if(link("lf2", "lf2") >= 0){ if(link("lf2", "lf2") >= 0){
printf(1, "link lf2 lf2 succeeded! oops\n"); fprintf(1, "link lf2 lf2 succeeded! oops\n");
exit(); exit();
} }
unlink("lf2"); unlink("lf2");
if(link("lf2", "lf1") >= 0){ if(link("lf2", "lf1") >= 0){
printf(1, "link non-existant succeeded! oops\n"); fprintf(1, "link non-existant succeeded! oops\n");
exit(); exit();
} }
if(link(".", "lf1") >= 0){ if(link(".", "lf1") >= 0){
printf(1, "link . lf1 succeeded! oops\n"); fprintf(1, "link . lf1 succeeded! oops\n");
exit(); exit();
} }
printf(1, "linktest ok\n"); fprintf(1, "linktest ok\n");
} }
// test concurrent create and unlink of the same file // test concurrent create and unlink of the same file
...@@ -666,7 +666,7 @@ concreate(void) ...@@ -666,7 +666,7 @@ concreate(void)
char name[14]; char name[14];
} de; } de;
printf(1, "concreate test\n"); fprintf(1, "concreate test\n");
file[0] = 'C'; file[0] = 'C';
file[2] = '\0'; file[2] = '\0';
for(i = 0; i < 40; i++){ for(i = 0; i < 40; i++){
...@@ -680,7 +680,7 @@ concreate(void) ...@@ -680,7 +680,7 @@ concreate(void)
} else { } else {
fd = open(file, O_CREATE | O_RDWR); fd = open(file, O_CREATE | O_RDWR);
if(fd < 0){ if(fd < 0){
printf(1, "concreate create %s failed\n", file); fprintf(1, "concreate create %s failed\n", file);
exit(); exit();
} }
close(fd); close(fd);
...@@ -700,11 +700,11 @@ concreate(void) ...@@ -700,11 +700,11 @@ concreate(void)
if(de.name[0] == 'C' && de.name[2] == '\0'){ if(de.name[0] == 'C' && de.name[2] == '\0'){
i = de.name[1] - '0'; i = de.name[1] - '0';
if(i < 0 || i >= sizeof(fa)){ if(i < 0 || i >= sizeof(fa)){
printf(1, "concreate weird file %s\n", de.name); fprintf(1, "concreate weird file %s\n", de.name);
exit(); exit();
} }
if(fa[i]){ if(fa[i]){
printf(1, "concreate duplicate file %s\n", de.name); fprintf(1, "concreate duplicate file %s\n", de.name);
exit(); exit();
} }
fa[i] = 1; fa[i] = 1;
...@@ -714,7 +714,7 @@ concreate(void) ...@@ -714,7 +714,7 @@ concreate(void)
close(fd); close(fd);
if(n != 40){ if(n != 40){
printf(1, "concreate not enough files in directory listing\n"); fprintf(1, "concreate not enough files in directory listing\n");
exit(); exit();
} }
...@@ -722,7 +722,7 @@ concreate(void) ...@@ -722,7 +722,7 @@ concreate(void)
file[1] = '0' + i; file[1] = '0' + i;
pid = fork(0); pid = fork(0);
if(pid < 0){ if(pid < 0){
printf(1, "fork failed\n"); fprintf(1, "fork failed\n");
exit(); exit();
} }
if(((i % 3) == 0 && pid == 0) || if(((i % 3) == 0 && pid == 0) ||
...@@ -738,7 +738,7 @@ concreate(void) ...@@ -738,7 +738,7 @@ concreate(void)
wait(); wait();
} }
printf(1, "concreate ok\n"); fprintf(1, "concreate ok\n");
} }
// directory that uses indirect blocks // directory that uses indirect blocks
...@@ -748,12 +748,12 @@ bigdir(void) ...@@ -748,12 +748,12 @@ bigdir(void)
int i, fd; int i, fd;
char name[10]; char name[10];
printf(1, "bigdir test\n"); fprintf(1, "bigdir test\n");
unlink("bd"); unlink("bd");
fd = open("bd", O_CREATE); fd = open("bd", O_CREATE);
if(fd < 0){ if(fd < 0){
printf(1, "bigdir create failed\n"); fprintf(1, "bigdir create failed\n");
exit(); exit();
} }
close(fd); close(fd);
...@@ -764,7 +764,7 @@ bigdir(void) ...@@ -764,7 +764,7 @@ bigdir(void)
name[2] = '0' + (i % 64); name[2] = '0' + (i % 64);
name[3] = '\0'; name[3] = '\0';
if(link("bd", name) != 0){ if(link("bd", name) != 0){
printf(1, "bigdir link failed\n"); fprintf(1, "bigdir link failed\n");
exit(); exit();
} }
} }
...@@ -776,12 +776,12 @@ bigdir(void) ...@@ -776,12 +776,12 @@ bigdir(void)
name[2] = '0' + (i % 64); name[2] = '0' + (i % 64);
name[3] = '\0'; name[3] = '\0';
if(unlink(name) != 0){ if(unlink(name) != 0){
printf(1, "bigdir unlink failed"); fprintf(1, "bigdir unlink failed");
exit(); exit();
} }
} }
printf(1, "bigdir ok\n"); fprintf(1, "bigdir ok\n");
} }
void void
...@@ -789,35 +789,35 @@ subdir(void) ...@@ -789,35 +789,35 @@ subdir(void)
{ {
int fd, cc; int fd, cc;
printf(1, "subdir test\n"); fprintf(1, "subdir test\n");
unlink("ff"); unlink("ff");
if(mkdir("dd") != 0){ if(mkdir("dd") != 0){
printf(1, "subdir mkdir dd failed\n"); fprintf(1, "subdir mkdir dd failed\n");
exit(); exit();
} }
fd = open("dd/ff", O_CREATE | O_RDWR); fd = open("dd/ff", O_CREATE | O_RDWR);
if(fd < 0){ if(fd < 0){
printf(1, "create dd/ff failed\n"); fprintf(1, "create dd/ff failed\n");
exit(); exit();
} }
write(fd, "ff", 2); write(fd, "ff", 2);
close(fd); close(fd);
if(unlink("dd") >= 0){ if(unlink("dd") >= 0){
printf(1, "unlink dd (non-empty dir) succeeded!\n"); fprintf(1, "unlink dd (non-empty dir) succeeded!\n");
exit(); exit();
} }
if(mkdir("/dd/dd") != 0){ if(mkdir("/dd/dd") != 0){
printf(1, "subdir mkdir dd/dd failed\n"); fprintf(1, "subdir mkdir dd/dd failed\n");
exit(); exit();
} }
fd = open("dd/dd/ff", O_CREATE | O_RDWR); fd = open("dd/dd/ff", O_CREATE | O_RDWR);
if(fd < 0){ if(fd < 0){
printf(1, "create dd/dd/ff failed\n"); fprintf(1, "create dd/dd/ff failed\n");
exit(); exit();
} }
write(fd, "FF", 2); write(fd, "FF", 2);
...@@ -825,146 +825,146 @@ subdir(void) ...@@ -825,146 +825,146 @@ subdir(void)
fd = open("dd/dd/../ff", 0); fd = open("dd/dd/../ff", 0);
if(fd < 0){ if(fd < 0){
printf(1, "open dd/dd/../ff failed\n"); fprintf(1, "open dd/dd/../ff failed\n");
exit(); exit();
} }
cc = read(fd, buf, sizeof(buf)); cc = read(fd, buf, sizeof(buf));
if(cc != 2 || buf[0] != 'f'){ if(cc != 2 || buf[0] != 'f'){
printf(1, "dd/dd/../ff wrong content\n"); fprintf(1, "dd/dd/../ff wrong content\n");
exit(); exit();
} }
close(fd); close(fd);
if(link("dd/dd/ff", "dd/dd/ffff") != 0){ if(link("dd/dd/ff", "dd/dd/ffff") != 0){
printf(1, "link dd/dd/ff dd/dd/ffff failed\n"); fprintf(1, "link dd/dd/ff dd/dd/ffff failed\n");
exit(); exit();
} }
if(unlink("dd/dd/ff") != 0){ if(unlink("dd/dd/ff") != 0){
printf(1, "unlink dd/dd/ff failed\n"); fprintf(1, "unlink dd/dd/ff failed\n");
exit(); exit();
} }
if(open("dd/dd/ff", O_RDONLY) >= 0){ if(open("dd/dd/ff", O_RDONLY) >= 0){
printf(1, "open (unlinked) dd/dd/ff succeeded\n"); fprintf(1, "open (unlinked) dd/dd/ff succeeded\n");
exit(); exit();
} }
if(chdir("dd") != 0){ if(chdir("dd") != 0){
printf(1, "chdir dd failed\n"); fprintf(1, "chdir dd failed\n");
exit(); exit();
} }
if(chdir("dd/../../dd") != 0){ if(chdir("dd/../../dd") != 0){
printf(1, "chdir dd/../../dd failed\n"); fprintf(1, "chdir dd/../../dd failed\n");
exit(); exit();
} }
if(chdir("dd/../../../dd") != 0){ if(chdir("dd/../../../dd") != 0){
printf(1, "chdir dd/../../dd failed\n"); fprintf(1, "chdir dd/../../dd failed\n");
exit(); exit();
} }
if(chdir("./..") != 0){ if(chdir("./..") != 0){
printf(1, "chdir ./.. failed\n"); fprintf(1, "chdir ./.. failed\n");
exit(); exit();
} }
fd = open("dd/dd/ffff", 0); fd = open("dd/dd/ffff", 0);
if(fd < 0){ if(fd < 0){
printf(1, "open dd/dd/ffff failed\n"); fprintf(1, "open dd/dd/ffff failed\n");
exit(); exit();
} }
if(read(fd, buf, sizeof(buf)) != 2){ if(read(fd, buf, sizeof(buf)) != 2){
printf(1, "read dd/dd/ffff wrong len\n"); fprintf(1, "read dd/dd/ffff wrong len\n");
exit(); exit();
} }
close(fd); close(fd);
if(open("dd/dd/ff", O_RDONLY) >= 0){ if(open("dd/dd/ff", O_RDONLY) >= 0){
printf(1, "open (unlinked) dd/dd/ff succeeded!\n"); fprintf(1, "open (unlinked) dd/dd/ff succeeded!\n");
exit(); exit();
} }
if(open("dd/ff/ff", O_CREATE|O_RDWR) >= 0){ if(open("dd/ff/ff", O_CREATE|O_RDWR) >= 0){
printf(1, "create dd/ff/ff succeeded!\n"); fprintf(1, "create dd/ff/ff succeeded!\n");
exit(); exit();
} }
if(open("dd/xx/ff", O_CREATE|O_RDWR) >= 0){ if(open("dd/xx/ff", O_CREATE|O_RDWR) >= 0){
printf(1, "create dd/xx/ff succeeded!\n"); fprintf(1, "create dd/xx/ff succeeded!\n");
exit(); exit();
} }
if(open("dd", O_CREATE) >= 0){ if(open("dd", O_CREATE) >= 0){
printf(1, "create dd succeeded!\n"); fprintf(1, "create dd succeeded!\n");
exit(); exit();
} }
if(open("dd", O_RDWR) >= 0){ if(open("dd", O_RDWR) >= 0){
printf(1, "open dd rdwr succeeded!\n"); fprintf(1, "open dd rdwr succeeded!\n");
exit(); exit();
} }
if(open("dd", O_WRONLY) >= 0){ if(open("dd", O_WRONLY) >= 0){
printf(1, "open dd wronly succeeded!\n"); fprintf(1, "open dd wronly succeeded!\n");
exit(); exit();
} }
if(link("dd/ff/ff", "dd/dd/xx") == 0){ if(link("dd/ff/ff", "dd/dd/xx") == 0){
printf(1, "link dd/ff/ff dd/dd/xx succeeded!\n"); fprintf(1, "link dd/ff/ff dd/dd/xx succeeded!\n");
exit(); exit();
} }
if(link("dd/xx/ff", "dd/dd/xx") == 0){ if(link("dd/xx/ff", "dd/dd/xx") == 0){
printf(1, "link dd/xx/ff dd/dd/xx succeeded!\n"); fprintf(1, "link dd/xx/ff dd/dd/xx succeeded!\n");
exit(); exit();
} }
if(link("dd/ff", "dd/dd/ffff") == 0){ if(link("dd/ff", "dd/dd/ffff") == 0){
printf(1, "link dd/ff dd/dd/ffff succeeded!\n"); fprintf(1, "link dd/ff dd/dd/ffff succeeded!\n");
exit(); exit();
} }
if(mkdir("dd/ff/ff") == 0){ if(mkdir("dd/ff/ff") == 0){
printf(1, "mkdir dd/ff/ff succeeded!\n"); fprintf(1, "mkdir dd/ff/ff succeeded!\n");
exit(); exit();
} }
if(mkdir("dd/xx/ff") == 0){ if(mkdir("dd/xx/ff") == 0){
printf(1, "mkdir dd/xx/ff succeeded!\n"); fprintf(1, "mkdir dd/xx/ff succeeded!\n");
exit(); exit();
} }
if(mkdir("dd/dd/ffff") == 0){ if(mkdir("dd/dd/ffff") == 0){
printf(1, "mkdir dd/dd/ffff succeeded!\n"); fprintf(1, "mkdir dd/dd/ffff succeeded!\n");
exit(); exit();
} }
if(unlink("dd/xx/ff") == 0){ if(unlink("dd/xx/ff") == 0){
printf(1, "unlink dd/xx/ff succeeded!\n"); fprintf(1, "unlink dd/xx/ff succeeded!\n");
exit(); exit();
} }
if(unlink("dd/ff/ff") == 0){ if(unlink("dd/ff/ff") == 0){
printf(1, "unlink dd/ff/ff succeeded!\n"); fprintf(1, "unlink dd/ff/ff succeeded!\n");
exit(); exit();
} }
if(chdir("dd/ff") == 0){ if(chdir("dd/ff") == 0){
printf(1, "chdir dd/ff succeeded!\n"); fprintf(1, "chdir dd/ff succeeded!\n");
exit(); exit();
} }
if(chdir("dd/xx") == 0){ if(chdir("dd/xx") == 0){
printf(1, "chdir dd/xx succeeded!\n"); fprintf(1, "chdir dd/xx succeeded!\n");
exit(); exit();
} }
if(unlink("dd/dd/ffff") != 0){ if(unlink("dd/dd/ffff") != 0){
printf(1, "unlink dd/dd/ff failed\n"); fprintf(1, "unlink dd/dd/ff failed\n");
exit(); exit();
} }
if(unlink("dd/ff") != 0){ if(unlink("dd/ff") != 0){
printf(1, "unlink dd/ff failed\n"); fprintf(1, "unlink dd/ff failed\n");
exit(); exit();
} }
if(unlink("dd") == 0){ if(unlink("dd") == 0){
printf(1, "unlink non-empty dd succeeded!\n"); fprintf(1, "unlink non-empty dd succeeded!\n");
exit(); exit();
} }
if(unlink("dd/dd") < 0){ if(unlink("dd/dd") < 0){
printf(1, "unlink dd/dd failed\n"); fprintf(1, "unlink dd/dd failed\n");
exit(); exit();
} }
if(unlink("dd") < 0){ if(unlink("dd") < 0){
printf(1, "unlink dd failed\n"); fprintf(1, "unlink dd failed\n");
exit(); exit();
} }
printf(1, "subdir ok\n"); fprintf(1, "subdir ok\n");
} }
void void
...@@ -972,18 +972,18 @@ bigfile(void) ...@@ -972,18 +972,18 @@ bigfile(void)
{ {
int fd, i, total, cc; int fd, i, total, cc;
printf(1, "bigfile test\n"); fprintf(1, "bigfile test\n");
unlink("bigfile"); unlink("bigfile");
fd = open("bigfile", O_CREATE | O_RDWR); fd = open("bigfile", O_CREATE | O_RDWR);
if(fd < 0){ if(fd < 0){
printf(1, "cannot create bigfile"); fprintf(1, "cannot create bigfile");
exit(); exit();
} }
for(i = 0; i < 20; i++){ for(i = 0; i < 20; i++){
memset(buf, i, 600); memset(buf, i, 600);
if(write(fd, buf, 600) != 600){ if(write(fd, buf, 600) != 600){
printf(1, "write bigfile failed\n"); fprintf(1, "write bigfile failed\n");
exit(); exit();
} }
} }
...@@ -991,36 +991,36 @@ bigfile(void) ...@@ -991,36 +991,36 @@ bigfile(void)
fd = open("bigfile", 0); fd = open("bigfile", 0);
if(fd < 0){ if(fd < 0){
printf(1, "cannot open bigfile\n"); fprintf(1, "cannot open bigfile\n");
exit(); exit();
} }
total = 0; total = 0;
for(i = 0; ; i++){ for(i = 0; ; i++){
cc = read(fd, buf, 300); cc = read(fd, buf, 300);
if(cc < 0){ if(cc < 0){
printf(1, "read bigfile failed\n"); fprintf(1, "read bigfile failed\n");
exit(); exit();
} }
if(cc == 0) if(cc == 0)
break; break;
if(cc != 300){ if(cc != 300){
printf(1, "short read bigfile\n"); fprintf(1, "short read bigfile\n");
exit(); exit();
} }
if(buf[0] != i/2 || buf[299] != i/2){ if(buf[0] != i/2 || buf[299] != i/2){
printf(1, "read bigfile wrong data\n"); fprintf(1, "read bigfile wrong data\n");
exit(); exit();
} }
total += cc; total += cc;
} }
close(fd); close(fd);
if(total != 20*600){ if(total != 20*600){
printf(1, "read bigfile wrong total\n"); fprintf(1, "read bigfile wrong total\n");
exit(); exit();
} }
unlink("bigfile"); unlink("bigfile");
printf(1, "bigfile test ok\n"); fprintf(1, "bigfile test ok\n");
} }
void void
...@@ -1029,95 +1029,95 @@ thirteen(void) ...@@ -1029,95 +1029,95 @@ thirteen(void)
int fd; int fd;
// DIRSIZ is 14. // DIRSIZ is 14.
printf(1, "thirteen test\n"); fprintf(1, "thirteen test\n");
if(mkdir("1234567890123") != 0){ if(mkdir("1234567890123") != 0){
printf(1, "mkdir 1234567890123 failed\n"); fprintf(1, "mkdir 1234567890123 failed\n");
exit(); exit();
} }
if(mkdir("1234567890123/1234567890123") != 0){ if(mkdir("1234567890123/1234567890123") != 0){
printf(1, "mkdir 1234567890123/1234567890123 failed\n"); fprintf(1, "mkdir 1234567890123/1234567890123 failed\n");
exit(); exit();
} }
fd = open("1234567890123/1234567890123/1234567890123", O_CREATE); fd = open("1234567890123/1234567890123/1234567890123", O_CREATE);
if(fd < 0){ if(fd < 0){
printf(1, "create 1234567890123/1234567890123/1234567890123 failed\n"); fprintf(1, "create 1234567890123/1234567890123/1234567890123 failed\n");
exit(); exit();
} }
close(fd); close(fd);
fd = open("1234567890123/1234567890123/1234567890123", 0); fd = open("1234567890123/1234567890123/1234567890123", 0);
if(fd < 0){ if(fd < 0){
printf(1, "open 1234567890123/1234567890123/1234567890123 failed\n"); fprintf(1, "open 1234567890123/1234567890123/1234567890123 failed\n");
exit(); exit();
} }
close(fd); close(fd);
if(mkdir("1234567890123/1234567890123") == 0){ if(mkdir("1234567890123/1234567890123") == 0){
printf(1, "mkdir 1234567890123/1234567890123 succeeded!\n"); fprintf(1, "mkdir 1234567890123/1234567890123 succeeded!\n");
exit(); exit();
} }
if(mkdir("1234567890123/1234567890123") == 0){ if(mkdir("1234567890123/1234567890123") == 0){
printf(1, "mkdir 1234567890123/1234567890123 succeeded!\n"); fprintf(1, "mkdir 1234567890123/1234567890123 succeeded!\n");
exit(); exit();
} }
printf(1, "thirteen ok\n"); fprintf(1, "thirteen ok\n");
} }
void void
longname(void) longname(void)
{ {
printf(stdout, "longname\n"); fprintf(stdout, "longname\n");
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
if (open("12345678901234", O_CREATE) != -1) { if (open("12345678901234", O_CREATE) != -1) {
printf(stdout, "open 12345678901234, O_CREATE succeeded!\n"); fprintf(stdout, "open 12345678901234, O_CREATE succeeded!\n");
exit(); exit();
} }
if (mkdir("12345678901234") != -1) { if (mkdir("12345678901234") != -1) {
printf(stdout, "mkdir 12345678901234 succeeded!\n"); fprintf(stdout, "mkdir 12345678901234 succeeded!\n");
exit(); exit();
} }
} }
printf(stdout, "longname ok\n"); fprintf(stdout, "longname ok\n");
} }
void void
rmdot(void) rmdot(void)
{ {
printf(1, "rmdot test\n"); fprintf(1, "rmdot test\n");
if(mkdir("dots") != 0){ if(mkdir("dots") != 0){
printf(1, "mkdir dots failed\n"); fprintf(1, "mkdir dots failed\n");
exit(); exit();
} }
if(chdir("dots") != 0){ if(chdir("dots") != 0){
printf(1, "chdir dots failed\n"); fprintf(1, "chdir dots failed\n");
exit(); exit();
} }
if(unlink(".") == 0){ if(unlink(".") == 0){
printf(1, "rm . worked!\n"); fprintf(1, "rm . worked!\n");
exit(); exit();
} }
if(unlink("..") == 0){ if(unlink("..") == 0){
printf(1, "rm .. worked!\n"); fprintf(1, "rm .. worked!\n");
exit(); exit();
} }
if(chdir("/") != 0){ if(chdir("/") != 0){
printf(1, "chdir / failed\n"); fprintf(1, "chdir / failed\n");
exit(); exit();
} }
if(unlink("dots/.") == 0){ if(unlink("dots/.") == 0){
printf(1, "unlink dots/. worked!\n"); fprintf(1, "unlink dots/. worked!\n");
exit(); exit();
} }
if(unlink("dots/..") == 0){ if(unlink("dots/..") == 0){
printf(1, "unlink dots/.. worked!\n"); fprintf(1, "unlink dots/.. worked!\n");
exit(); exit();
} }
if(unlink("dots") != 0){ if(unlink("dots") != 0){
printf(1, "unlink dots failed!\n"); fprintf(1, "unlink dots failed!\n");
exit(); exit();
} }
printf(1, "rmdot ok\n"); fprintf(1, "rmdot ok\n");
} }
void void
...@@ -1125,58 +1125,58 @@ dirfile(void) ...@@ -1125,58 +1125,58 @@ dirfile(void)
{ {
int fd; int fd;
printf(1, "dir vs file\n"); fprintf(1, "dir vs file\n");
fd = open("dirfile", O_CREATE); fd = open("dirfile", O_CREATE);
if(fd < 0){ if(fd < 0){
printf(1, "create dirfile failed\n"); fprintf(1, "create dirfile failed\n");
exit(); exit();
} }
close(fd); close(fd);
if(chdir("dirfile") == 0){ if(chdir("dirfile") == 0){
printf(1, "chdir dirfile succeeded!\n"); fprintf(1, "chdir dirfile succeeded!\n");
exit(); exit();
} }
fd = open("dirfile/xx", 0); fd = open("dirfile/xx", 0);
if(fd >= 0){ if(fd >= 0){
printf(1, "create dirfile/xx succeeded!\n"); fprintf(1, "create dirfile/xx succeeded!\n");
exit(); exit();
} }
fd = open("dirfile/xx", O_CREATE); fd = open("dirfile/xx", O_CREATE);
if(fd >= 0){ if(fd >= 0){
printf(1, "create dirfile/xx succeeded!\n"); fprintf(1, "create dirfile/xx succeeded!\n");
exit(); exit();
} }
if(mkdir("dirfile/xx") == 0){ if(mkdir("dirfile/xx") == 0){
printf(1, "mkdir dirfile/xx succeeded!\n"); fprintf(1, "mkdir dirfile/xx succeeded!\n");
exit(); exit();
} }
if(unlink("dirfile/xx") == 0){ if(unlink("dirfile/xx") == 0){
printf(1, "unlink dirfile/xx succeeded!\n"); fprintf(1, "unlink dirfile/xx succeeded!\n");
exit(); exit();
} }
if(link("README", "dirfile/xx") == 0){ if(link("README", "dirfile/xx") == 0){
printf(1, "link to dirfile/xx succeeded!\n"); fprintf(1, "link to dirfile/xx succeeded!\n");
exit(); exit();
} }
if(unlink("dirfile") != 0){ if(unlink("dirfile") != 0){
printf(1, "unlink dirfile failed!\n"); fprintf(1, "unlink dirfile failed!\n");
exit(); exit();
} }
fd = open(".", O_RDWR); fd = open(".", O_RDWR);
if(fd >= 0){ if(fd >= 0){
printf(1, "open . for writing succeeded!\n"); fprintf(1, "open . for writing succeeded!\n");
exit(); exit();
} }
fd = open(".", 0); fd = open(".", 0);
if(write(fd, "x", 1) > 0){ if(write(fd, "x", 1) > 0){
printf(1, "write . succeeded!\n"); fprintf(1, "write . succeeded!\n");
exit(); exit();
} }
close(fd); close(fd);
printf(1, "dir vs file OK\n"); fprintf(1, "dir vs file OK\n");
} }
// test that iput() is called at the end of _namei() // test that iput() is called at the end of _namei()
...@@ -1185,16 +1185,16 @@ iref(void) ...@@ -1185,16 +1185,16 @@ iref(void)
{ {
int i, fd; int i, fd;
printf(1, "empty file name\n"); fprintf(1, "empty file name\n");
// the 50 is NINODE // the 50 is NINODE
for(i = 0; i < 50 + 1; i++){ for(i = 0; i < 50 + 1; i++){
if(mkdir("irefd") != 0){ if(mkdir("irefd") != 0){
printf(1, "mkdir irefd failed\n"); fprintf(1, "mkdir irefd failed\n");
exit(); exit();
} }
if(chdir("irefd") != 0){ if(chdir("irefd") != 0){
printf(1, "chdir irefd failed\n"); fprintf(1, "chdir irefd failed\n");
exit(); exit();
} }
...@@ -1210,7 +1210,7 @@ iref(void) ...@@ -1210,7 +1210,7 @@ iref(void)
} }
chdir("/"); chdir("/");
printf(1, "empty file name OK\n"); fprintf(1, "empty file name OK\n");
} }
// test that fork fails gracefully // test that fork fails gracefully
...@@ -1221,7 +1221,7 @@ forktest(void) ...@@ -1221,7 +1221,7 @@ forktest(void)
{ {
int n, pid; int n, pid;
printf(1, "fork test\n"); fprintf(1, "fork test\n");
for(n=0; n<1000; n++){ for(n=0; n<1000; n++){
pid = fork(0); pid = fork(0);
...@@ -1233,17 +1233,17 @@ forktest(void) ...@@ -1233,17 +1233,17 @@ forktest(void)
for(; n > 0; n--){ for(; n > 0; n--){
if(wait() < 0){ if(wait() < 0){
printf(1, "wait stopped early\n"); fprintf(1, "wait stopped early\n");
exit(); exit();
} }
} }
if(wait() != -1){ if(wait() != -1){
printf(1, "wait got too many\n"); fprintf(1, "wait got too many\n");
exit(); exit();
} }
printf(1, "fork test OK\n"); fprintf(1, "fork test OK\n");
} }
void void
...@@ -1253,7 +1253,7 @@ sbrktest(void) ...@@ -1253,7 +1253,7 @@ sbrktest(void)
char *a, *b, *c, *lastaddr, *oldbrk, *p, scratch; char *a, *b, *c, *lastaddr, *oldbrk, *p, scratch;
uptr amt; uptr amt;
printf(stdout, "sbrk test\n"); fprintf(stdout, "sbrk test\n");
oldbrk = sbrk(0); oldbrk = sbrk(0);
// can one sbrk() less than a page? // can one sbrk() less than a page?
...@@ -1262,7 +1262,7 @@ sbrktest(void) ...@@ -1262,7 +1262,7 @@ sbrktest(void)
for(i = 0; i < 5000; i++){ for(i = 0; i < 5000; i++){
b = sbrk(1); b = sbrk(1);
if(b != a){ if(b != a){
printf(stdout, "sbrk test failed %d %x %x\n", i, a, b); fprintf(stdout, "sbrk test failed %d %x %x\n", i, a, b);
exit(); exit();
} }
*b = 1; *b = 1;
...@@ -1270,13 +1270,13 @@ sbrktest(void) ...@@ -1270,13 +1270,13 @@ sbrktest(void)
} }
pid = fork(0); pid = fork(0);
if(pid < 0){ if(pid < 0){
printf(stdout, "sbrk test fork failed\n"); fprintf(stdout, "sbrk test fork failed\n");
exit(); exit();
} }
c = sbrk(1); c = sbrk(1);
c = sbrk(1); c = sbrk(1);
if(c != a + 1){ if(c != a + 1){
printf(stdout, "sbrk test failed post-fork\n"); fprintf(stdout, "sbrk test failed post-fork\n");
exit(); exit();
} }
if(pid == 0) if(pid == 0)
...@@ -1289,7 +1289,7 @@ sbrktest(void) ...@@ -1289,7 +1289,7 @@ sbrktest(void)
amt = (632 * 1024) - (uptr)a; amt = (632 * 1024) - (uptr)a;
p = sbrk(amt); p = sbrk(amt);
if(p != a){ if(p != a){
printf(stdout, "sbrk test failed 632K test, p %x a %x\n", p, a); fprintf(stdout, "sbrk test failed 632K test, p %x a %x\n", p, a);
exit(); exit();
} }
lastaddr = (char*)(632 * 1024 - 1); lastaddr = (char*)(632 * 1024 - 1);
...@@ -1298,7 +1298,7 @@ sbrktest(void) ...@@ -1298,7 +1298,7 @@ sbrktest(void)
// is one forbidden from allocating more than 632K? // is one forbidden from allocating more than 632K?
c = sbrk(4096); c = sbrk(4096);
if(c != (char*)0xffffffff){ if(c != (char*)0xffffffff){
printf(stdout, "sbrk allocated more than 632K, c %x\n", c); fprintf(stdout, "sbrk allocated more than 632K, c %x\n", c);
exit(); exit();
} }
...@@ -1306,12 +1306,12 @@ sbrktest(void) ...@@ -1306,12 +1306,12 @@ sbrktest(void)
a = sbrk(0); a = sbrk(0);
c = sbrk(-4096); c = sbrk(-4096);
if(c == (char*)0xffffffff){ if(c == (char*)0xffffffff){
printf(stdout, "sbrk could not deallocate\n"); fprintf(stdout, "sbrk could not deallocate\n");
exit(); exit();
} }
c = sbrk(0); c = sbrk(0);
if(c != a - 4096){ if(c != a - 4096){
printf(stdout, "sbrk deallocation produced wrong address, a %x c %x\n", a, c); fprintf(stdout, "sbrk deallocation produced wrong address, a %x c %x\n", a, c);
exit(); exit();
} }
...@@ -1319,20 +1319,20 @@ sbrktest(void) ...@@ -1319,20 +1319,20 @@ sbrktest(void)
a = sbrk(0); a = sbrk(0);
c = sbrk(4096); c = sbrk(4096);
if(c != a || sbrk(0) != a + 4096){ if(c != a || sbrk(0) != a + 4096){
printf(stdout, "sbrk re-allocation failed, a %x c %x\n", a, c); fprintf(stdout, "sbrk re-allocation failed, a %x c %x\n", a, c);
exit(); exit();
} }
#if 0 #if 0
if(*lastaddr == 99){ if(*lastaddr == 99){
// should be zero // should be zero
printf(stdout, "sbrk de-allocation didn't really deallocate\n"); fprintf(stdout, "sbrk de-allocation didn't really deallocate\n");
exit(); exit();
} }
#endif #endif
c = sbrk(4096); c = sbrk(4096);
if(c != (char*)0xffffffff){ if(c != (char*)0xffffffff){
printf(stdout, "sbrk was able to re-allocate beyond 632K, c %x\n", c); fprintf(stdout, "sbrk was able to re-allocate beyond 632K, c %x\n", c);
exit(); exit();
} }
...@@ -1341,11 +1341,11 @@ sbrktest(void) ...@@ -1341,11 +1341,11 @@ sbrktest(void)
ppid = getpid(); ppid = getpid();
pid = fork(0); pid = fork(0);
if(pid < 0){ if(pid < 0){
printf(stdout, "fork failed\n"); fprintf(stdout, "fork failed\n");
exit(); exit();
} }
if(pid == 0){ if(pid == 0){
printf(stdout, "oops could read %x = %x\n", a, *a); fprintf(stdout, "oops could read %x = %x\n", a, *a);
kill(ppid); kill(ppid);
exit(); exit();
} }
...@@ -1356,7 +1356,7 @@ sbrktest(void) ...@@ -1356,7 +1356,7 @@ sbrktest(void)
// failed allocation? // failed allocation?
sbrk(-(sbrk(0) - oldbrk)); sbrk(-(sbrk(0) - oldbrk));
if(pipe(fds) != 0){ if(pipe(fds) != 0){
printf(1, "pipe() failed\n"); fprintf(1, "pipe() failed\n");
exit(); exit();
} }
for(i = 0; i < sizeof(pids)/sizeof(pids[0]); i++){ for(i = 0; i < sizeof(pids)/sizeof(pids[0]); i++){
...@@ -1380,14 +1380,14 @@ sbrktest(void) ...@@ -1380,14 +1380,14 @@ sbrktest(void)
wait(); wait();
} }
if(c == (char*)0xffffffff){ if(c == (char*)0xffffffff){
printf(stdout, "failed sbrk leaked memory\n"); fprintf(stdout, "failed sbrk leaked memory\n");
exit(); exit();
} }
if(sbrk(0) > oldbrk) if(sbrk(0) > oldbrk)
sbrk(-(sbrk(0) - oldbrk)); sbrk(-(sbrk(0) - oldbrk));
printf(stdout, "sbrk test OK\n"); fprintf(stdout, "sbrk test OK\n");
} }
void void
...@@ -1396,7 +1396,7 @@ validatetest(void) ...@@ -1396,7 +1396,7 @@ validatetest(void)
int pid; int pid;
uptr lo, hi, p; uptr lo, hi, p;
printf(stdout, "validate test\n"); fprintf(stdout, "validate test\n");
// Do 16 pages below the bottom of userspace and 16 pages above, // Do 16 pages below the bottom of userspace and 16 pages above,
// which should be code pages and read-only // which should be code pages and read-only
lo = (1024*1024) - 16*4096; lo = (1024*1024) - 16*4096;
...@@ -1406,7 +1406,7 @@ validatetest(void) ...@@ -1406,7 +1406,7 @@ validatetest(void)
if((pid = fork(0)) == 0){ if((pid = fork(0)) == 0){
// try to crash the kernel by passing in a badly placed integer // try to crash the kernel by passing in a badly placed integer
if (pipe((int*)p) == 0) if (pipe((int*)p) == 0)
printf(stdout, "validatetest failed (pipe succeeded)\n"); fprintf(stdout, "validatetest failed (pipe succeeded)\n");
exit(); exit();
} }
sleep(0); sleep(0);
...@@ -1416,12 +1416,12 @@ validatetest(void) ...@@ -1416,12 +1416,12 @@ validatetest(void)
// try to crash the kernel by passing in a bad string pointer // try to crash the kernel by passing in a bad string pointer
if(link("nosuchfile", (char*)p) != -1){ if(link("nosuchfile", (char*)p) != -1){
printf(stdout, "link should not succeed\n"); fprintf(stdout, "link should not succeed\n");
exit(); exit();
} }
} }
printf(stdout, "validate ok\n"); fprintf(stdout, "validate ok\n");
} }
// does unintialized data start out zero? // does unintialized data start out zero?
...@@ -1431,14 +1431,14 @@ bsstest(void) ...@@ -1431,14 +1431,14 @@ bsstest(void)
{ {
int i; int i;
printf(stdout, "bss test\n"); fprintf(stdout, "bss test\n");
for(i = 0; i < sizeof(uninit); i++){ for(i = 0; i < sizeof(uninit); i++){
if(uninit[i] != '\0'){ if(uninit[i] != '\0'){
printf(stdout, "bss test failed\n"); fprintf(stdout, "bss test failed\n");
exit(); exit();
} }
} }
printf(stdout, "bss test ok\n"); fprintf(stdout, "bss test ok\n");
} }
// does exec do something sensible if the arguments // does exec do something sensible if the arguments
...@@ -1455,12 +1455,12 @@ bigargtest(void) ...@@ -1455,12 +1455,12 @@ bigargtest(void)
for(i = 0; i < 32; i++) for(i = 0; i < 32; i++)
args[i] = "bigargs test: failed\n "; args[i] = "bigargs test: failed\n ";
args[32] = 0; args[32] = 0;
printf(stdout, "bigarg test\n"); fprintf(stdout, "bigarg test\n");
exec("echo", args); exec("echo", args);
printf(stdout, "bigarg test ok\n"); fprintf(stdout, "bigarg test ok\n");
exit(); exit();
} else if(pid < 0){ } else if(pid < 0){
printf(stdout, "bigargtest: fork failed\n"); fprintf(stdout, "bigargtest: fork failed\n");
exit(); exit();
} }
wait(); wait();
...@@ -1471,11 +1471,11 @@ uox(char *name, const char *data) ...@@ -1471,11 +1471,11 @@ uox(char *name, const char *data)
{ {
int fd = open(name, O_CREATE|O_RDWR); int fd = open(name, O_CREATE|O_RDWR);
if(fd < 0){ if(fd < 0){
printf(stdout, "creat %s failed\n", name); fprintf(stdout, "creat %s failed\n", name);
exit(); exit();
} }
if(write(fd, "xx", 2) != 2){ if(write(fd, "xx", 2) != 2){
printf(stdout, "write failed\n"); fprintf(stdout, "write failed\n");
exit(); exit();
} }
close(fd); close(fd);
...@@ -1485,7 +1485,7 @@ uox(char *name, const char *data) ...@@ -1485,7 +1485,7 @@ uox(char *name, const char *data)
void void
unopentest(void) unopentest(void)
{ {
printf(stdout, "concurrent unlink/open\n"); fprintf(stdout, "concurrent unlink/open\n");
int pid = fork(0); int pid = fork(0);
if(pid == 0){ if(pid == 0){
...@@ -1501,7 +1501,7 @@ unopentest(void) ...@@ -1501,7 +1501,7 @@ unopentest(void)
fd = open(name, O_RDWR); fd = open(name, O_RDWR);
if(fd >= 0){ if(fd >= 0){
if(write(fd, "y", 1) != 1){ if(write(fd, "y", 1) != 1){
printf(stdout, "write %s failed\n", name); fprintf(stdout, "write %s failed\n", name);
exit(); exit();
} }
close(fd); close(fd);
...@@ -1518,13 +1518,13 @@ unopentest(void) ...@@ -1518,13 +1518,13 @@ unopentest(void)
name[2] = '\0'; name[2] = '\0';
uox(name, "xxx"); uox(name, "xxx");
if(unlink(name) < 0){ if(unlink(name) < 0){
printf(stdout, "unlink %s failed\n", name); fprintf(stdout, "unlink %s failed\n", name);
exit(); exit();
} }
// reallocate that inode // reallocate that inode
name[0] = 'g'; name[0] = 'g';
if(mkdir(name) != 0){ if(mkdir(name) != 0){
printf(stdout, "mkdir %s failed\n", name); fprintf(stdout, "mkdir %s failed\n", name);
exit(); exit();
} }
} }
...@@ -1541,7 +1541,7 @@ unopentest(void) ...@@ -1541,7 +1541,7 @@ unopentest(void)
kill(pid); kill(pid);
wait(); wait();
printf(stdout, "concurrent unlink/open ok\n"); fprintf(stdout, "concurrent unlink/open ok\n");
} }
void void
...@@ -1555,7 +1555,7 @@ preads(void) ...@@ -1555,7 +1555,7 @@ preads(void)
int fd; int fd;
int pid; int pid;
printf(1, "concurrent preads\n"); fprintf(1, "concurrent preads\n");
fd = open("preads.x", O_CREATE|O_RDWR); fd = open("preads.x", O_CREATE|O_RDWR);
if (fd < 0) if (fd < 0)
...@@ -1585,16 +1585,16 @@ preads(void) ...@@ -1585,16 +1585,16 @@ preads(void)
if (pid == 0) if (pid == 0)
exit(); exit();
printf(1, "concurrent preads OK\n"); fprintf(1, "concurrent preads OK\n");
} }
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
printf(1, "usertests starting\n"); fprintf(1, "usertests starting\n");
if(open("usertests.ran", 0) >= 0){ if(open("usertests.ran", 0) >= 0){
printf(1, "already ran user tests -- rebuild fs.img\n"); fprintf(1, "already ran user tests -- rebuild fs.img\n");
exit(); exit();
} }
close(open("usertests.ran", O_CREATE)); close(open("usertests.ran", O_CREATE));
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论