diff --git a/doc/FU540-C000-v1.0.pdf b/doc/FU540-C000-v1.0.pdf index 5322d67..1a8cc69 100644 Binary files a/doc/FU540-C000-v1.0.pdf and b/doc/FU540-C000-v1.0.pdf differ diff --git a/user/alarmtest.c b/user/alarmtest.c index c6da547..ca3db23 100644 --- a/user/alarmtest.c +++ b/user/alarmtest.c @@ -30,7 +30,7 @@ void periodic() { count = count + 1; - printf(1, "alarm!\n"); + printf("alarm!\n"); sigreturn(); } @@ -40,7 +40,7 @@ void test0() { int i; - printf(1, "test0 start\n"); + printf("test0 start\n"); count = 0; sigalarm(2, periodic); for(i = 0; i < 1000*500000; i++){ @@ -51,9 +51,9 @@ test0() } sigalarm(0, 0); if(count > 0){ - printf(1, "test0 passed\n"); + printf("test0 passed\n"); } else { - printf(1, "test0 failed\n"); + printf("test0 failed\n"); } } @@ -70,7 +70,7 @@ test1() int i; int j; - printf(1, "test1 start\n"); + printf("test1 start\n"); count = 0; j = 0; sigalarm(2, periodic); @@ -81,8 +81,8 @@ test1() } if(i != j || count < 10){ // i should equal j - printf(1, "test1 failed\n"); + printf("test1 failed\n"); } else { - printf(1, "test1 passed\n"); + printf("test1 passed\n"); } } diff --git a/user/cat.c b/user/cat.c index d3d16c4..52909da 100644 --- a/user/cat.c +++ b/user/cat.c @@ -11,12 +11,12 @@ cat(int fd) while((n = read(fd, buf, sizeof(buf))) > 0) { if (write(1, buf, n) != n) { - printf(1, "cat: write error\n"); + printf("cat: write error\n"); exit(); } } if(n < 0){ - printf(1, "cat: read error\n"); + printf("cat: read error\n"); exit(); } } @@ -33,7 +33,7 @@ main(int argc, char *argv[]) for(i = 1; i < argc; i++){ if((fd = open(argv[i], 0)) < 0){ - printf(1, "cat: cannot open %s\n", argv[i]); + printf("cat: cannot open %s\n", argv[i]); exit(); } cat(fd); diff --git a/user/echo.c b/user/echo.c index ef744ab..bb98e97 100644 --- a/user/echo.c +++ b/user/echo.c @@ -8,6 +8,6 @@ main(int argc, char *argv[]) int i; for(i = 1; i < argc; i++) - printf(1, "%s%s", argv[i], i+1 < argc ? " " : "\n"); + printf("%s%s", argv[i], i+1 < argc ? " " : "\n"); exit(); } diff --git a/user/forktest.c b/user/forktest.c index be4915e..fa072ca 100644 --- a/user/forktest.c +++ b/user/forktest.c @@ -8,9 +8,9 @@ #define N 1000 void -printf(int fd, const char *s, ...) +print(const char *s) { - write(fd, s, strlen(s)); + write(1, s, strlen(s)); } void @@ -18,7 +18,7 @@ forktest(void) { int n, pid; - printf(1, "fork test\n"); + print("fork test\n"); for(n=0; n 0; n--){ if(wait() < 0){ - printf(1, "wait stopped early\n"); + print("wait stopped early\n"); exit(); } } if(wait() != -1){ - printf(1, "wait got too many\n"); + print("wait got too many\n"); exit(); } - printf(1, "fork test OK\n"); + print("fork test OK\n"); } int diff --git a/user/grep.c b/user/grep.c index b5fdfc2..152c8a8 100644 --- a/user/grep.c +++ b/user/grep.c @@ -42,7 +42,7 @@ main(int argc, char *argv[]) char *pattern; if(argc <= 1){ - printf(2, "usage: grep pattern [file ...]\n"); + fprintf(2, "usage: grep pattern [file ...]\n"); exit(); } pattern = argv[1]; @@ -54,7 +54,7 @@ main(int argc, char *argv[]) for(i = 2; i < argc; i++){ if((fd = open(argv[i], 0)) < 0){ - printf(1, "grep: cannot open %s\n", argv[i]); + printf("grep: cannot open %s\n", argv[i]); exit(); } grep(pattern, fd); diff --git a/user/init.c b/user/init.c index 03e60da..01bb445 100644 --- a/user/init.c +++ b/user/init.c @@ -20,19 +20,19 @@ main(void) dup(0); // stderr for(;;){ - printf(1, "init: starting sh\n"); + printf("init: starting sh\n"); pid = fork(); if(pid < 0){ - printf(1, "init: fork failed\n"); + printf("init: fork failed\n"); exit(); } if(pid == 0){ exec("sh", argv); - printf(1, "init: exec sh failed\n"); + printf("init: exec sh failed\n"); exit(); } while((wpid=wait()) >= 0 && wpid != pid){ - //printf(1, "zombie!\n"); + //printf("zombie!\n"); } } } diff --git a/user/kill.c b/user/kill.c index 4b19d3c..3e29cd0 100644 --- a/user/kill.c +++ b/user/kill.c @@ -8,7 +8,7 @@ main(int argc, char **argv) int i; if(argc < 2){ - printf(2, "usage: kill pid...\n"); + fprintf(2, "usage: kill pid...\n"); exit(); } for(i=1; i sizeof buf){ - printf(1, "ls: path too long\n"); + printf("ls: path too long\n"); break; } strcpy(buf, path); @@ -60,10 +60,10 @@ ls(char *path) memmove(p, de.name, DIRSIZ); p[DIRSIZ] = 0; if(stat(buf, &st) < 0){ - printf(1, "ls: cannot stat %s\n", buf); + printf("ls: cannot stat %s\n", buf); continue; } - printf(1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size); + printf("%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size); } break; } diff --git a/user/mkdir.c b/user/mkdir.c index 5f1e155..6996ee9 100644 --- a/user/mkdir.c +++ b/user/mkdir.c @@ -8,13 +8,13 @@ main(int argc, char *argv[]) int i; if(argc < 2){ - printf(2, "Usage: mkdir files...\n"); + fprintf(2, "Usage: mkdir files...\n"); exit(); } for(i = 1; i < argc; i++){ if(mkdir(argv[i]) < 0){ - printf(2, "mkdir: %s failed to create\n", argv[i]); + fprintf(2, "mkdir: %s failed to create\n", argv[i]); break; } } diff --git a/user/printf.c b/user/printf.c index f3b3282..5c5c782 100644 --- a/user/printf.c +++ b/user/printf.c @@ -49,13 +49,11 @@ printptr(int fd, uint64 x) { // Print to the given fd. Only understands %d, %x, %p, %s. void -printf(int fd, const char *fmt, ...) +vprintf(int fd, const char *fmt, va_list ap) { - va_list ap; char *s; int c, i, state; - va_start(ap, fmt); state = 0; for(i = 0; fmt[i]; i++){ c = fmt[i] & 0xff; @@ -95,3 +93,21 @@ printf(int fd, const char *fmt, ...) } } } + +void +fprintf(int fd, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vprintf(fd, fmt, ap); +} + +void +printf(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vprintf(1, fmt, ap); +} diff --git a/user/rm.c b/user/rm.c index 3076d83..4abe295 100644 --- a/user/rm.c +++ b/user/rm.c @@ -8,13 +8,13 @@ main(int argc, char *argv[]) int i; if(argc < 2){ - printf(2, "Usage: rm files...\n"); + fprintf(2, "Usage: rm files...\n"); exit(); } for(i = 1; i < argc; i++){ if(unlink(argv[i]) < 0){ - printf(2, "rm: %s failed to delete\n", argv[i]); + fprintf(2, "rm: %s failed to delete\n", argv[i]); break; } } diff --git a/user/sh.c b/user/sh.c index 13c7883..c573c99 100644 --- a/user/sh.c +++ b/user/sh.c @@ -76,14 +76,14 @@ runcmd(struct cmd *cmd) if(ecmd->argv[0] == 0) exit(); 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; case REDIR: rcmd = (struct redircmd*)cmd; close(rcmd->fd); if(open(rcmd->file, rcmd->mode) < 0){ - printf(2, "open %s failed\n", rcmd->file); + fprintf(2, "open %s failed\n", rcmd->file); exit(); } runcmd(rcmd->cmd); @@ -133,7 +133,7 @@ runcmd(struct cmd *cmd) int getcmd(char *buf, int nbuf) { - printf(2, "$ "); + fprintf(2, "$ "); memset(buf, 0, nbuf); gets(buf, nbuf); if(buf[0] == 0) // EOF @@ -161,7 +161,7 @@ main(void) // Chdir must be called by the parent, not the child. buf[strlen(buf)-1] = 0; // chop \n if(chdir(buf+3) < 0) - printf(2, "cannot cd %s\n", buf+3); + fprintf(2, "cannot cd %s\n", buf+3); continue; } if(fork1() == 0) @@ -174,7 +174,7 @@ main(void) void panic(char *s) { - printf(2, "%s\n", s); + fprintf(2, "%s\n", s); exit(); } @@ -334,7 +334,7 @@ parsecmd(char *s) cmd = parseline(&s, es); peek(&s, es, ""); if(s != es){ - printf(2, "leftovers: %s\n", s); + fprintf(2, "leftovers: %s\n", s); panic("syntax"); } nulterminate(cmd); diff --git a/user/stressfs.c b/user/stressfs.c index ef8f1cd..5edd7aa 100644 --- a/user/stressfs.c +++ b/user/stressfs.c @@ -20,14 +20,14 @@ main(int argc, char *argv[]) char path[] = "stressfs0"; char data[512]; - printf(1, "stressfs starting\n"); + printf("stressfs starting\n"); memset(data, 'a', sizeof(data)); for(i = 0; i < 4; i++) if(fork() > 0) break; - printf(1, "write %d\n", i); + printf("write %d\n", i); path[8] += i; fd = open(path, O_CREATE | O_RDWR); @@ -36,7 +36,7 @@ main(int argc, char *argv[]) write(fd, data, sizeof(data)); close(fd); - printf(1, "read\n"); + printf("read\n"); fd = open(path, O_RDONLY); for (i = 0; i < 20; i++) diff --git a/user/user.h b/user/user.h index 4f99c52..0e01b85 100644 --- a/user/user.h +++ b/user/user.h @@ -30,7 +30,8 @@ char* strcpy(char*, const char*); void *memmove(void*, const void*, int); char* strchr(const char*, char c); int strcmp(const char*, const char*); -void printf(int, const char*, ...); +void fprintf(int, const char*, ...); +void printf(const char*, ...); char* gets(char*, int max); uint strlen(const char*); void* memset(void*, int, uint); diff --git a/user/usertests.c b/user/usertests.c index 285f161..641ac1c 100644 --- a/user/usertests.c +++ b/user/usertests.c @@ -13,31 +13,30 @@ char buf[BUFSZ]; char name[3]; char *echoargv[] = { "echo", "ALL", "TESTS", "PASSED", 0 }; -int stdout = 1; // does chdir() call iput(p->cwd) in a transaction? void iputtest(void) { - printf(stdout, "iput test\n"); + printf("iput test\n"); if(mkdir("iputdir") < 0){ - printf(stdout, "mkdir failed\n"); + printf("mkdir failed\n"); exit(); } if(chdir("iputdir") < 0){ - printf(stdout, "chdir iputdir failed\n"); + printf("chdir iputdir failed\n"); exit(); } if(unlink("../iputdir") < 0){ - printf(stdout, "unlink ../iputdir failed\n"); + printf("unlink ../iputdir failed\n"); exit(); } if(chdir("/") < 0){ - printf(stdout, "chdir / failed\n"); + printf("chdir / failed\n"); exit(); } - printf(stdout, "iput test ok\n"); + printf("iput test ok\n"); } // does exit() call iput(p->cwd) in a transaction? @@ -46,30 +45,30 @@ exitiputtest(void) { int pid; - printf(stdout, "exitiput test\n"); + printf("exitiput test\n"); pid = fork(); if(pid < 0){ - printf(stdout, "fork failed\n"); + printf("fork failed\n"); exit(); } if(pid == 0){ if(mkdir("iputdir") < 0){ - printf(stdout, "mkdir failed\n"); + printf("mkdir failed\n"); exit(); } if(chdir("iputdir") < 0){ - printf(stdout, "child chdir failed\n"); + printf("child chdir failed\n"); exit(); } if(unlink("../iputdir") < 0){ - printf(stdout, "unlink ../iputdir failed\n"); + printf("unlink ../iputdir failed\n"); exit(); } exit(); } wait(); - printf(stdout, "exitiput test ok\n"); + printf("exitiput test ok\n"); } // does the error path in open() for attempt to write a @@ -88,31 +87,31 @@ openiputtest(void) { int pid; - printf(stdout, "openiput test\n"); + printf("openiput test\n"); if(mkdir("oidir") < 0){ - printf(stdout, "mkdir oidir failed\n"); + printf("mkdir oidir failed\n"); exit(); } pid = fork(); if(pid < 0){ - printf(stdout, "fork failed\n"); + printf("fork failed\n"); exit(); } if(pid == 0){ int fd = open("oidir", O_RDWR); if(fd >= 0){ - printf(stdout, "open directory for write succeeded\n"); + printf("open directory for write succeeded\n"); exit(); } exit(); } sleep(1); if(unlink("oidir") != 0){ - printf(stdout, "unlink failed\n"); + printf("unlink failed\n"); exit(); } wait(); - printf(stdout, "openiput test ok\n"); + printf("openiput test ok\n"); } // simple file system tests @@ -122,19 +121,19 @@ opentest(void) { int fd; - printf(stdout, "open test\n"); + printf("open test\n"); fd = open("echo", 0); if(fd < 0){ - printf(stdout, "open echo failed!\n"); + printf("open echo failed!\n"); exit(); } close(fd); fd = open("doesnotexist", 0); if(fd >= 0){ - printf(stdout, "open doesnotexist succeeded!\n"); + printf("open doesnotexist succeeded!\n"); exit(); } - printf(stdout, "open test ok\n"); + printf("open test ok\n"); } void @@ -144,47 +143,47 @@ writetest(void) int i; enum { N=100, SZ=10 }; - printf(stdout, "small file test\n"); + printf("small file test\n"); fd = open("small", O_CREATE|O_RDWR); if(fd >= 0){ - printf(stdout, "creat small succeeded; ok\n"); + printf("creat small succeeded; ok\n"); } else { - printf(stdout, "error: creat small failed!\n"); + printf("error: creat small failed!\n"); exit(); } for(i = 0; i < N; i++){ if(write(fd, "aaaaaaaaaa", SZ) != SZ){ - printf(stdout, "error: write aa %d new file failed\n", i); + printf("error: write aa %d new file failed\n", i); exit(); } if(write(fd, "bbbbbbbbbb", SZ) != SZ){ - printf(stdout, "error: write bb %d new file failed\n", i); + printf("error: write bb %d new file failed\n", i); exit(); } } - printf(stdout, "writes ok\n"); + printf("writes ok\n"); close(fd); fd = open("small", O_RDONLY); if(fd >= 0){ - printf(stdout, "open small succeeded ok\n"); + printf("open small succeeded ok\n"); } else { - printf(stdout, "error: open small failed!\n"); + printf("error: open small failed!\n"); exit(); } i = read(fd, buf, N*SZ*2); if(i == N*SZ*2){ - printf(stdout, "read succeeded ok\n"); + printf("read succeeded ok\n"); } else { - printf(stdout, "read failed\n"); + printf("read failed\n"); exit(); } close(fd); if(unlink("small") < 0){ - printf(stdout, "unlink small failed\n"); + printf("unlink small failed\n"); exit(); } - printf(stdout, "small file test ok\n"); + printf("small file test ok\n"); } void @@ -192,18 +191,18 @@ writetest1(void) { int i, fd, n; - printf(stdout, "big files test\n"); + printf("big files test\n"); fd = open("big", O_CREATE|O_RDWR); if(fd < 0){ - printf(stdout, "error: creat big failed!\n"); + printf("error: creat big failed!\n"); exit(); } for(i = 0; i < MAXFILE; i++){ ((int*)buf)[0] = i; if(write(fd, buf, BSIZE) != BSIZE){ - printf(stdout, "error: write big file failed\n", i); + printf("error: write big file failed\n", i); exit(); } } @@ -212,7 +211,7 @@ writetest1(void) fd = open("big", O_RDONLY); if(fd < 0){ - printf(stdout, "error: open big failed!\n"); + printf("error: open big failed!\n"); exit(); } @@ -221,16 +220,16 @@ writetest1(void) i = read(fd, buf, BSIZE); if(i == 0){ if(n == MAXFILE - 1){ - printf(stdout, "read only %d blocks from big", n); + printf("read only %d blocks from big", n); exit(); } break; } else if(i != BSIZE){ - printf(stdout, "read failed %d\n", i); + printf("read failed %d\n", i); exit(); } if(((int*)buf)[0] != n){ - printf(stdout, "read content of block %d is %d\n", + printf("read content of block %d is %d\n", n, ((int*)buf)[0]); exit(); } @@ -238,10 +237,10 @@ writetest1(void) } close(fd); if(unlink("big") < 0){ - printf(stdout, "unlink big failed\n"); + printf("unlink big failed\n"); exit(); } - printf(stdout, "big files ok\n"); + printf("big files ok\n"); } void @@ -250,7 +249,7 @@ createtest(void) int i, fd; enum { N=52 }; - printf(stdout, "many creates, followed by unlink test\n"); + printf("many creates, followed by unlink test\n"); name[0] = 'a'; name[2] = '\0'; @@ -265,41 +264,41 @@ createtest(void) name[1] = '0' + i; unlink(name); } - printf(stdout, "many creates, followed by unlink; ok\n"); + printf("many creates, followed by unlink; ok\n"); } void dirtest(void) { - printf(stdout, "mkdir test\n"); + printf("mkdir test\n"); if(mkdir("dir0") < 0){ - printf(stdout, "mkdir failed\n"); + printf("mkdir failed\n"); exit(); } if(chdir("dir0") < 0){ - printf(stdout, "chdir dir0 failed\n"); + printf("chdir dir0 failed\n"); exit(); } if(chdir("..") < 0){ - printf(stdout, "chdir .. failed\n"); + printf("chdir .. failed\n"); exit(); } if(unlink("dir0") < 0){ - printf(stdout, "unlink dir0 failed\n"); + printf("unlink dir0 failed\n"); exit(); } - printf(stdout, "mkdir test ok\n"); + printf("mkdir test ok\n"); } void exectest(void) { - printf(stdout, "exec test\n"); + printf("exec test\n"); if(exec("echo", echoargv) < 0){ - printf(stdout, "exec echo failed\n"); + printf("exec echo failed\n"); exit(); } } @@ -314,7 +313,7 @@ pipe1(void) enum { N=5, SZ=1033 }; if(pipe(fds) != 0){ - printf(1, "pipe() failed\n"); + printf("pipe() failed\n"); exit(); } pid = fork(); @@ -325,7 +324,7 @@ pipe1(void) for(i = 0; i < SZ; i++) buf[i] = seq++; if(write(fds[1], buf, SZ) != SZ){ - printf(1, "pipe1 oops 1\n"); + printf("pipe1 oops 1\n"); exit(); } } @@ -337,7 +336,7 @@ pipe1(void) while((n = read(fds[0], buf, cc)) > 0){ for(i = 0; i < n; i++){ if((buf[i] & 0xff) != (seq++ & 0xff)){ - printf(1, "pipe1 oops 2\n"); + printf("pipe1 oops 2\n"); return; } } @@ -347,16 +346,16 @@ pipe1(void) cc = sizeof(buf); } if(total != N * SZ){ - printf(1, "pipe1 oops 3 total %d\n", total); + printf("pipe1 oops 3 total %d\n", total); exit(); } close(fds[0]); wait(); } else { - printf(1, "fork() failed\n"); + printf("fork() failed\n"); exit(); } - printf(1, "pipe1 ok\n"); + printf("pipe1 ok\n"); } // meant to be run w/ at most two CPUs @@ -366,10 +365,10 @@ preempt(void) int pid1, pid2, pid3; int pfds[2]; - printf(1, "preempt: "); + printf("preempt: "); pid1 = fork(); if(pid1 < 0) { - printf(1, "fork failed"); + printf("fork failed"); exit(); } if(pid1 == 0) @@ -378,7 +377,7 @@ preempt(void) pid2 = fork(); if(pid2 < 0) { - printf(1, "fork failed\n"); + printf("fork failed\n"); exit(); } if(pid2 == 0) @@ -388,13 +387,13 @@ preempt(void) pipe(pfds); pid3 = fork(); if(pid3 < 0) { - printf(1, "fork failed\n"); + printf("fork failed\n"); exit(); } if(pid3 == 0){ close(pfds[0]); if(write(pfds[1], "x", 1) != 1) - printf(1, "preempt write error"); + printf("preempt write error"); close(pfds[1]); for(;;) ; @@ -402,19 +401,19 @@ preempt(void) close(pfds[1]); if(read(pfds[0], buf, sizeof(buf)) != 1){ - printf(1, "preempt read error"); + printf("preempt read error"); return; } close(pfds[0]); - printf(1, "kill... "); + printf("kill... "); kill(pid1); kill(pid2); kill(pid3); - printf(1, "wait... "); + printf("wait... "); wait(); wait(); wait(); - printf(1, "preempt ok\n"); + printf("preempt ok\n"); } // try to find any races between exit and wait @@ -423,24 +422,24 @@ exitwait(void) { int i, pid; - printf(1, "exitwait test\n"); + printf("exitwait test\n"); for(i = 0; i < 100; i++){ pid = fork(); if(pid < 0){ - printf(1, "fork failed\n"); + printf("fork failed\n"); exit(); } if(pid){ if(wait() != pid){ - printf(1, "wait wrong pid\n"); + printf("wait wrong pid\n"); exit(); } } else { exit(); } } - printf(1, "exitwait ok\n"); + printf("exitwait ok\n"); } // try to find races in the reparenting @@ -451,23 +450,23 @@ reparent(void) { int master_pid = getpid(); - printf(1, "reparent test\n"); + printf("reparent test\n"); for(int i = 0; i < 200; i++){ int pid = fork(); if(pid < 0){ - printf(1, "fork failed\n"); + printf("fork failed\n"); exit(); } if(pid){ if(wait() != pid){ - printf(1, "wait wrong pid\n"); + printf("wait wrong pid\n"); exit(); } } else { int pid2 = fork(); if(pid2 < 0){ - printf(1, "fork failed\n"); + printf("fork failed\n"); kill(master_pid); exit(); } @@ -478,19 +477,19 @@ reparent(void) } } } - printf(1, "reparent ok\n"); + printf("reparent ok\n"); } // what if two children exit() at the same time? void twochildren(void) { - printf(1, "twochildren test\n"); + printf("twochildren test\n"); for(int i = 0; i < 1000; i++){ int pid1 = fork(); if(pid1 < 0){ - printf(1, "fork failed\n"); + printf("fork failed\n"); exit(); } if(pid1 == 0){ @@ -498,7 +497,7 @@ twochildren(void) } else { int pid2 = fork(); if(pid2 < 0){ - printf(1, "fork failed\n"); + printf("fork failed\n"); exit(); } if(pid2 == 0){ @@ -509,7 +508,7 @@ twochildren(void) } } } - printf(1, "twochildren ok\n"); + printf("twochildren ok\n"); } // concurrent forks to try to expose locking bugs. @@ -519,19 +518,19 @@ forkfork(void) int ppid = getpid(); enum { N=2 }; - printf(1, "forkfork test\n"); + printf("forkfork test\n"); for(int i = 0; i < N; i++){ int pid = fork(); if(pid < 0){ - printf(1, "fork failed"); + printf("fork failed"); exit(); } if(pid == 0){ for(int j = 0; j < 200; j++){ int pid1 = fork(); if(pid1 < 0){ - printf(1, "fork failed\n"); + printf("fork failed\n"); kill(ppid); exit(); } @@ -548,19 +547,19 @@ forkfork(void) wait(); } - printf(1, "forkfork ok\n"); + printf("forkfork ok\n"); } void forkforkfork(void) { - printf(1, "forkforkfork test\n"); + printf("forkforkfork test\n"); unlink("stopforking"); int pid = fork(); if(pid < 0){ - printf(1, "fork failed"); + printf("fork failed"); exit(); } if(pid == 0){ @@ -582,7 +581,7 @@ forkforkfork(void) wait(); sleep(10); // one second - printf(1, "forkforkfork ok\n"); + printf("forkforkfork ok\n"); } void @@ -591,7 +590,7 @@ mem(void) void *m1, *m2; int pid, ppid; - printf(1, "mem test\n"); + printf("mem test\n"); ppid = getpid(); if((pid = fork()) == 0){ m1 = 0; @@ -606,12 +605,12 @@ mem(void) } m1 = malloc(1024*20); if(m1 == 0){ - printf(1, "couldn't allocate mem?!!\n"); + printf("couldn't allocate mem?!!\n"); kill(ppid); exit(); } free(m1); - printf(1, "mem ok\n"); + printf("mem ok\n"); exit(); } else { wait(); @@ -629,19 +628,19 @@ sharedfd(void) enum { N = 1000, SZ=10}; char buf[SZ]; - printf(1, "sharedfd test\n"); + printf("sharedfd test\n"); unlink("sharedfd"); fd = open("sharedfd", O_CREATE|O_RDWR); if(fd < 0){ - printf(1, "fstests: cannot open sharedfd for writing"); + printf("fstests: cannot open sharedfd for writing"); return; } pid = fork(); memset(buf, pid==0?'c':'p', sizeof(buf)); for(i = 0; i < N; i++){ if(write(fd, buf, sizeof(buf)) != sizeof(buf)){ - printf(1, "fstests: write sharedfd failed\n"); + printf("fstests: write sharedfd failed\n"); break; } } @@ -652,7 +651,7 @@ sharedfd(void) close(fd); fd = open("sharedfd", 0); if(fd < 0){ - printf(1, "fstests: cannot open sharedfd for reading\n"); + printf("fstests: cannot open sharedfd for reading\n"); return; } nc = np = 0; @@ -667,9 +666,9 @@ sharedfd(void) close(fd); unlink("sharedfd"); if(nc == N*SZ && np == N*SZ){ - printf(1, "sharedfd ok\n"); + printf("sharedfd ok\n"); } else { - printf(1, "sharedfd oops %d %d\n", nc, np); + printf("sharedfd oops %d %d\n", nc, np); exit(); } } @@ -684,7 +683,7 @@ fourfiles(void) char *fname; enum { N=12, NCHILD=4, SZ=500 }; - printf(1, "fourfiles test\n"); + printf("fourfiles test\n"); for(pi = 0; pi < NCHILD; pi++){ fname = names[pi]; @@ -692,21 +691,21 @@ fourfiles(void) pid = fork(); if(pid < 0){ - printf(1, "fork failed\n"); + printf("fork failed\n"); exit(); } if(pid == 0){ fd = open(fname, O_CREATE | O_RDWR); if(fd < 0){ - printf(1, "create failed\n"); + printf("create failed\n"); exit(); } memset(buf, '0'+pi, SZ); for(i = 0; i < N; i++){ if((n = write(fd, buf, SZ)) != SZ){ - printf(1, "write failed %d\n", n); + printf("write failed %d\n", n); exit(); } } @@ -725,7 +724,7 @@ fourfiles(void) while((n = read(fd, buf, sizeof(buf))) > 0){ for(j = 0; j < n; j++){ if(buf[j] != '0'+i){ - printf(1, "wrong char\n"); + printf("wrong char\n"); exit(); } } @@ -733,13 +732,13 @@ fourfiles(void) } close(fd); if(total != N*SZ){ - printf(1, "wrong length %d\n", total); + printf("wrong length %d\n", total); exit(); } unlink(fname); } - printf(1, "fourfiles ok\n"); + printf("fourfiles ok\n"); } // four processes create and delete different files in same directory @@ -750,12 +749,12 @@ createdelete(void) int pid, i, fd, pi; char name[32]; - printf(1, "createdelete test\n"); + printf("createdelete test\n"); for(pi = 0; pi < NCHILD; pi++){ pid = fork(); if(pid < 0){ - printf(1, "fork failed\n"); + printf("fork failed\n"); exit(); } @@ -766,14 +765,14 @@ createdelete(void) name[1] = '0' + i; fd = open(name, O_CREATE | O_RDWR); if(fd < 0){ - printf(1, "create failed\n"); + printf("create failed\n"); exit(); } close(fd); if(i > 0 && (i % 2 ) == 0){ name[1] = '0' + (i / 2); if(unlink(name) < 0){ - printf(1, "unlink failed\n"); + printf("unlink failed\n"); exit(); } } @@ -793,10 +792,10 @@ createdelete(void) name[1] = '0' + i; fd = open(name, 0); if((i == 0 || i >= N/2) && fd < 0){ - printf(1, "oops createdelete %s didn't exist\n", name); + printf("oops createdelete %s didn't exist\n", name); exit(); } else if((i >= 1 && i < N/2) && fd >= 0){ - printf(1, "oops createdelete %s did exist\n", name); + printf("oops createdelete %s did exist\n", name); exit(); } if(fd >= 0) @@ -812,7 +811,7 @@ createdelete(void) } } - printf(1, "createdelete ok\n"); + printf("createdelete ok\n"); } // can I unlink a file and still read it? @@ -822,10 +821,10 @@ unlinkread(void) enum { SZ = 5 }; int fd, fd1; - printf(1, "unlinkread test\n"); + printf("unlinkread test\n"); fd = open("unlinkread", O_CREATE | O_RDWR); if(fd < 0){ - printf(1, "create unlinkread failed\n"); + printf("create unlinkread failed\n"); exit(); } write(fd, "hello", SZ); @@ -833,11 +832,11 @@ unlinkread(void) fd = open("unlinkread", O_RDWR); if(fd < 0){ - printf(1, "open unlinkread failed\n"); + printf("open unlinkread failed\n"); exit(); } if(unlink("unlinkread") != 0){ - printf(1, "unlink unlinkread failed\n"); + printf("unlink unlinkread failed\n"); exit(); } @@ -846,20 +845,20 @@ unlinkread(void) close(fd1); if(read(fd, buf, sizeof(buf)) != SZ){ - printf(1, "unlinkread read failed"); + printf("unlinkread read failed"); exit(); } if(buf[0] != 'h'){ - printf(1, "unlinkread wrong data\n"); + printf("unlinkread wrong data\n"); exit(); } if(write(fd, buf, 10) != 10){ - printf(1, "unlinkread write failed\n"); + printf("unlinkread write failed\n"); exit(); } close(fd); unlink("unlinkread"); - printf(1, "unlinkread ok\n"); + printf("unlinkread ok\n"); } void @@ -868,61 +867,61 @@ linktest(void) enum { SZ = 5 }; int fd; - printf(1, "linktest\n"); + printf("linktest\n"); unlink("lf1"); unlink("lf2"); fd = open("lf1", O_CREATE|O_RDWR); if(fd < 0){ - printf(1, "create lf1 failed\n"); + printf("create lf1 failed\n"); exit(); } if(write(fd, "hello", SZ) != SZ){ - printf(1, "write lf1 failed\n"); + printf("write lf1 failed\n"); exit(); } close(fd); if(link("lf1", "lf2") < 0){ - printf(1, "link lf1 lf2 failed\n"); + printf("link lf1 lf2 failed\n"); exit(); } unlink("lf1"); if(open("lf1", 0) >= 0){ - printf(1, "unlinked lf1 but it is still there!\n"); + printf("unlinked lf1 but it is still there!\n"); exit(); } fd = open("lf2", 0); if(fd < 0){ - printf(1, "open lf2 failed\n"); + printf("open lf2 failed\n"); exit(); } if(read(fd, buf, sizeof(buf)) != SZ){ - printf(1, "read lf2 failed\n"); + printf("read lf2 failed\n"); exit(); } close(fd); if(link("lf2", "lf2") >= 0){ - printf(1, "link lf2 lf2 succeeded! oops\n"); + printf("link lf2 lf2 succeeded! oops\n"); exit(); } unlink("lf2"); if(link("lf2", "lf1") >= 0){ - printf(1, "link non-existant succeeded! oops\n"); + printf("link non-existant succeeded! oops\n"); exit(); } if(link(".", "lf1") >= 0){ - printf(1, "link . lf1 succeeded! oops\n"); + printf("link . lf1 succeeded! oops\n"); exit(); } - printf(1, "linktest ok\n"); + printf("linktest ok\n"); } // test concurrent create/link/unlink of the same file @@ -938,7 +937,7 @@ concreate(void) char name[DIRSIZ]; } de; - printf(1, "concreate test\n"); + printf("concreate test\n"); file[0] = 'C'; file[2] = '\0'; for(i = 0; i < N; i++){ @@ -952,7 +951,7 @@ concreate(void) } else { fd = open(file, O_CREATE | O_RDWR); if(fd < 0){ - printf(1, "concreate create %s failed\n", file); + printf("concreate create %s failed\n", file); exit(); } close(fd); @@ -972,11 +971,11 @@ concreate(void) if(de.name[0] == 'C' && de.name[2] == '\0'){ i = de.name[1] - '0'; if(i < 0 || i >= sizeof(fa)){ - printf(1, "concreate weird file %s\n", de.name); + printf("concreate weird file %s\n", de.name); exit(); } if(fa[i]){ - printf(1, "concreate duplicate file %s\n", de.name); + printf("concreate duplicate file %s\n", de.name); exit(); } fa[i] = 1; @@ -986,7 +985,7 @@ concreate(void) close(fd); if(n != N){ - printf(1, "concreate not enough files in directory listing\n"); + printf("concreate not enough files in directory listing\n"); exit(); } @@ -994,7 +993,7 @@ concreate(void) file[1] = '0' + i; pid = fork(); if(pid < 0){ - printf(1, "fork failed\n"); + printf("fork failed\n"); exit(); } if(((i % 3) == 0 && pid == 0) || @@ -1015,7 +1014,7 @@ concreate(void) wait(); } - printf(1, "concreate ok\n"); + printf("concreate ok\n"); } // another concurrent link/unlink/create test, @@ -1025,12 +1024,12 @@ linkunlink() { int pid, i; - printf(1, "linkunlink test\n"); + printf("linkunlink test\n"); unlink("x"); pid = fork(); if(pid < 0){ - printf(1, "fork failed\n"); + printf("fork failed\n"); exit(); } @@ -1051,7 +1050,7 @@ linkunlink() else exit(); - printf(1, "linkunlink ok\n"); + printf("linkunlink ok\n"); } // directory that uses indirect blocks @@ -1062,12 +1061,12 @@ bigdir(void) int i, fd; char name[10]; - printf(1, "bigdir test\n"); + printf("bigdir test\n"); unlink("bd"); fd = open("bd", O_CREATE); if(fd < 0){ - printf(1, "bigdir create failed\n"); + printf("bigdir create failed\n"); exit(); } close(fd); @@ -1078,7 +1077,7 @@ bigdir(void) name[2] = '0' + (i % 64); name[3] = '\0'; if(link("bd", name) != 0){ - printf(1, "bigdir link failed\n"); + printf("bigdir link failed\n"); exit(); } } @@ -1090,12 +1089,12 @@ bigdir(void) name[2] = '0' + (i % 64); name[3] = '\0'; if(unlink(name) != 0){ - printf(1, "bigdir unlink failed"); + printf("bigdir unlink failed"); exit(); } } - printf(1, "bigdir ok\n"); + printf("bigdir ok\n"); } void @@ -1103,35 +1102,35 @@ subdir(void) { int fd, cc; - printf(1, "subdir test\n"); + printf("subdir test\n"); unlink("ff"); if(mkdir("dd") != 0){ - printf(1, "subdir mkdir dd failed\n"); + printf("subdir mkdir dd failed\n"); exit(); } fd = open("dd/ff", O_CREATE | O_RDWR); if(fd < 0){ - printf(1, "create dd/ff failed\n"); + printf("create dd/ff failed\n"); exit(); } write(fd, "ff", 2); close(fd); if(unlink("dd") >= 0){ - printf(1, "unlink dd (non-empty dir) succeeded!\n"); + printf("unlink dd (non-empty dir) succeeded!\n"); exit(); } if(mkdir("/dd/dd") != 0){ - printf(1, "subdir mkdir dd/dd failed\n"); + printf("subdir mkdir dd/dd failed\n"); exit(); } fd = open("dd/dd/ff", O_CREATE | O_RDWR); if(fd < 0){ - printf(1, "create dd/dd/ff failed\n"); + printf("create dd/dd/ff failed\n"); exit(); } write(fd, "FF", 2); @@ -1139,146 +1138,146 @@ subdir(void) fd = open("dd/dd/../ff", 0); if(fd < 0){ - printf(1, "open dd/dd/../ff failed\n"); + printf("open dd/dd/../ff failed\n"); exit(); } cc = read(fd, buf, sizeof(buf)); if(cc != 2 || buf[0] != 'f'){ - printf(1, "dd/dd/../ff wrong content\n"); + printf("dd/dd/../ff wrong content\n"); exit(); } close(fd); if(link("dd/dd/ff", "dd/dd/ffff") != 0){ - printf(1, "link dd/dd/ff dd/dd/ffff failed\n"); + printf("link dd/dd/ff dd/dd/ffff failed\n"); exit(); } if(unlink("dd/dd/ff") != 0){ - printf(1, "unlink dd/dd/ff failed\n"); + printf("unlink dd/dd/ff failed\n"); exit(); } if(open("dd/dd/ff", O_RDONLY) >= 0){ - printf(1, "open (unlinked) dd/dd/ff succeeded\n"); + printf("open (unlinked) dd/dd/ff succeeded\n"); exit(); } if(chdir("dd") != 0){ - printf(1, "chdir dd failed\n"); + printf("chdir dd failed\n"); exit(); } if(chdir("dd/../../dd") != 0){ - printf(1, "chdir dd/../../dd failed\n"); + printf("chdir dd/../../dd failed\n"); exit(); } if(chdir("dd/../../../dd") != 0){ - printf(1, "chdir dd/../../dd failed\n"); + printf("chdir dd/../../dd failed\n"); exit(); } if(chdir("./..") != 0){ - printf(1, "chdir ./.. failed\n"); + printf("chdir ./.. failed\n"); exit(); } fd = open("dd/dd/ffff", 0); if(fd < 0){ - printf(1, "open dd/dd/ffff failed\n"); + printf("open dd/dd/ffff failed\n"); exit(); } if(read(fd, buf, sizeof(buf)) != 2){ - printf(1, "read dd/dd/ffff wrong len\n"); + printf("read dd/dd/ffff wrong len\n"); exit(); } close(fd); if(open("dd/dd/ff", O_RDONLY) >= 0){ - printf(1, "open (unlinked) dd/dd/ff succeeded!\n"); + printf("open (unlinked) dd/dd/ff succeeded!\n"); exit(); } if(open("dd/ff/ff", O_CREATE|O_RDWR) >= 0){ - printf(1, "create dd/ff/ff succeeded!\n"); + printf("create dd/ff/ff succeeded!\n"); exit(); } if(open("dd/xx/ff", O_CREATE|O_RDWR) >= 0){ - printf(1, "create dd/xx/ff succeeded!\n"); + printf("create dd/xx/ff succeeded!\n"); exit(); } if(open("dd", O_CREATE) >= 0){ - printf(1, "create dd succeeded!\n"); + printf("create dd succeeded!\n"); exit(); } if(open("dd", O_RDWR) >= 0){ - printf(1, "open dd rdwr succeeded!\n"); + printf("open dd rdwr succeeded!\n"); exit(); } if(open("dd", O_WRONLY) >= 0){ - printf(1, "open dd wronly succeeded!\n"); + printf("open dd wronly succeeded!\n"); exit(); } if(link("dd/ff/ff", "dd/dd/xx") == 0){ - printf(1, "link dd/ff/ff dd/dd/xx succeeded!\n"); + printf("link dd/ff/ff dd/dd/xx succeeded!\n"); exit(); } if(link("dd/xx/ff", "dd/dd/xx") == 0){ - printf(1, "link dd/xx/ff dd/dd/xx succeeded!\n"); + printf("link dd/xx/ff dd/dd/xx succeeded!\n"); exit(); } if(link("dd/ff", "dd/dd/ffff") == 0){ - printf(1, "link dd/ff dd/dd/ffff succeeded!\n"); + printf("link dd/ff dd/dd/ffff succeeded!\n"); exit(); } if(mkdir("dd/ff/ff") == 0){ - printf(1, "mkdir dd/ff/ff succeeded!\n"); + printf("mkdir dd/ff/ff succeeded!\n"); exit(); } if(mkdir("dd/xx/ff") == 0){ - printf(1, "mkdir dd/xx/ff succeeded!\n"); + printf("mkdir dd/xx/ff succeeded!\n"); exit(); } if(mkdir("dd/dd/ffff") == 0){ - printf(1, "mkdir dd/dd/ffff succeeded!\n"); + printf("mkdir dd/dd/ffff succeeded!\n"); exit(); } if(unlink("dd/xx/ff") == 0){ - printf(1, "unlink dd/xx/ff succeeded!\n"); + printf("unlink dd/xx/ff succeeded!\n"); exit(); } if(unlink("dd/ff/ff") == 0){ - printf(1, "unlink dd/ff/ff succeeded!\n"); + printf("unlink dd/ff/ff succeeded!\n"); exit(); } if(chdir("dd/ff") == 0){ - printf(1, "chdir dd/ff succeeded!\n"); + printf("chdir dd/ff succeeded!\n"); exit(); } if(chdir("dd/xx") == 0){ - printf(1, "chdir dd/xx succeeded!\n"); + printf("chdir dd/xx succeeded!\n"); exit(); } if(unlink("dd/dd/ffff") != 0){ - printf(1, "unlink dd/dd/ff failed\n"); + printf("unlink dd/dd/ff failed\n"); exit(); } if(unlink("dd/ff") != 0){ - printf(1, "unlink dd/ff failed\n"); + printf("unlink dd/ff failed\n"); exit(); } if(unlink("dd") == 0){ - printf(1, "unlink non-empty dd succeeded!\n"); + printf("unlink non-empty dd succeeded!\n"); exit(); } if(unlink("dd/dd") < 0){ - printf(1, "unlink dd/dd failed\n"); + printf("unlink dd/dd failed\n"); exit(); } if(unlink("dd") < 0){ - printf(1, "unlink dd failed\n"); + printf("unlink dd failed\n"); exit(); } - printf(1, "subdir ok\n"); + printf("subdir ok\n"); } // test writes that are larger than the log. @@ -1287,20 +1286,20 @@ bigwrite(void) { int fd, sz; - printf(1, "bigwrite test\n"); + printf("bigwrite test\n"); unlink("bigwrite"); for(sz = 499; sz < (MAXOPBLOCKS+2)*BSIZE; sz += 471){ fd = open("bigwrite", O_CREATE | O_RDWR); if(fd < 0){ - printf(1, "cannot create bigwrite\n"); + printf("cannot create bigwrite\n"); exit(); } int i; for(i = 0; i < 2; i++){ int cc = write(fd, buf, sz); if(cc != sz){ - printf(1, "write(%d) ret %d\n", sz, cc); + printf("write(%d) ret %d\n", sz, cc); exit(); } } @@ -1308,7 +1307,7 @@ bigwrite(void) unlink("bigwrite"); } - printf(1, "bigwrite ok\n"); + printf("bigwrite ok\n"); } void @@ -1317,18 +1316,18 @@ bigfile(void) enum { N = 20, SZ=600 }; int fd, i, total, cc; - printf(1, "bigfile test\n"); + printf("bigfile test\n"); unlink("bigfile"); fd = open("bigfile", O_CREATE | O_RDWR); if(fd < 0){ - printf(1, "cannot create bigfile"); + printf("cannot create bigfile"); exit(); } for(i = 0; i < N; i++){ memset(buf, i, SZ); if(write(fd, buf, SZ) != SZ){ - printf(1, "write bigfile failed\n"); + printf("write bigfile failed\n"); exit(); } } @@ -1336,36 +1335,36 @@ bigfile(void) fd = open("bigfile", 0); if(fd < 0){ - printf(1, "cannot open bigfile\n"); + printf("cannot open bigfile\n"); exit(); } total = 0; for(i = 0; ; i++){ cc = read(fd, buf, SZ/2); if(cc < 0){ - printf(1, "read bigfile failed\n"); + printf("read bigfile failed\n"); exit(); } if(cc == 0) break; if(cc != SZ/2){ - printf(1, "short read bigfile\n"); + printf("short read bigfile\n"); exit(); } if(buf[0] != i/2 || buf[SZ/2-1] != i/2){ - printf(1, "read bigfile wrong data\n"); + printf("read bigfile wrong data\n"); exit(); } total += cc; } close(fd); if(total != N*SZ){ - printf(1, "read bigfile wrong total\n"); + printf("read bigfile wrong total\n"); exit(); } unlink("bigfile"); - printf(1, "bigfile test ok\n"); + printf("bigfile test ok\n"); } void @@ -1374,78 +1373,78 @@ fourteen(void) int fd; // DIRSIZ is 14. - printf(1, "fourteen test\n"); + printf("fourteen test\n"); if(mkdir("12345678901234") != 0){ - printf(1, "mkdir 12345678901234 failed\n"); + printf("mkdir 12345678901234 failed\n"); exit(); } if(mkdir("12345678901234/123456789012345") != 0){ - printf(1, "mkdir 12345678901234/123456789012345 failed\n"); + printf("mkdir 12345678901234/123456789012345 failed\n"); exit(); } fd = open("123456789012345/123456789012345/123456789012345", O_CREATE); if(fd < 0){ - printf(1, "create 123456789012345/123456789012345/123456789012345 failed\n"); + printf("create 123456789012345/123456789012345/123456789012345 failed\n"); exit(); } close(fd); fd = open("12345678901234/12345678901234/12345678901234", 0); if(fd < 0){ - printf(1, "open 12345678901234/12345678901234/12345678901234 failed\n"); + printf("open 12345678901234/12345678901234/12345678901234 failed\n"); exit(); } close(fd); if(mkdir("12345678901234/12345678901234") == 0){ - printf(1, "mkdir 12345678901234/12345678901234 succeeded!\n"); + printf("mkdir 12345678901234/12345678901234 succeeded!\n"); exit(); } if(mkdir("123456789012345/12345678901234") == 0){ - printf(1, "mkdir 12345678901234/123456789012345 succeeded!\n"); + printf("mkdir 12345678901234/123456789012345 succeeded!\n"); exit(); } - printf(1, "fourteen ok\n"); + printf("fourteen ok\n"); } void rmdot(void) { - printf(1, "rmdot test\n"); + printf("rmdot test\n"); if(mkdir("dots") != 0){ - printf(1, "mkdir dots failed\n"); + printf("mkdir dots failed\n"); exit(); } if(chdir("dots") != 0){ - printf(1, "chdir dots failed\n"); + printf("chdir dots failed\n"); exit(); } if(unlink(".") == 0){ - printf(1, "rm . worked!\n"); + printf("rm . worked!\n"); exit(); } if(unlink("..") == 0){ - printf(1, "rm .. worked!\n"); + printf("rm .. worked!\n"); exit(); } if(chdir("/") != 0){ - printf(1, "chdir / failed\n"); + printf("chdir / failed\n"); exit(); } if(unlink("dots/.") == 0){ - printf(1, "unlink dots/. worked!\n"); + printf("unlink dots/. worked!\n"); exit(); } if(unlink("dots/..") == 0){ - printf(1, "unlink dots/.. worked!\n"); + printf("unlink dots/.. worked!\n"); exit(); } if(unlink("dots") != 0){ - printf(1, "unlink dots failed!\n"); + printf("unlink dots failed!\n"); exit(); } - printf(1, "rmdot ok\n"); + printf("rmdot ok\n"); } void @@ -1453,58 +1452,58 @@ dirfile(void) { int fd; - printf(1, "dir vs file\n"); + printf("dir vs file\n"); fd = open("dirfile", O_CREATE); if(fd < 0){ - printf(1, "create dirfile failed\n"); + printf("create dirfile failed\n"); exit(); } close(fd); if(chdir("dirfile") == 0){ - printf(1, "chdir dirfile succeeded!\n"); + printf("chdir dirfile succeeded!\n"); exit(); } fd = open("dirfile/xx", 0); if(fd >= 0){ - printf(1, "create dirfile/xx succeeded!\n"); + printf("create dirfile/xx succeeded!\n"); exit(); } fd = open("dirfile/xx", O_CREATE); if(fd >= 0){ - printf(1, "create dirfile/xx succeeded!\n"); + printf("create dirfile/xx succeeded!\n"); exit(); } if(mkdir("dirfile/xx") == 0){ - printf(1, "mkdir dirfile/xx succeeded!\n"); + printf("mkdir dirfile/xx succeeded!\n"); exit(); } if(unlink("dirfile/xx") == 0){ - printf(1, "unlink dirfile/xx succeeded!\n"); + printf("unlink dirfile/xx succeeded!\n"); exit(); } if(link("README", "dirfile/xx") == 0){ - printf(1, "link to dirfile/xx succeeded!\n"); + printf("link to dirfile/xx succeeded!\n"); exit(); } if(unlink("dirfile") != 0){ - printf(1, "unlink dirfile failed!\n"); + printf("unlink dirfile failed!\n"); exit(); } fd = open(".", O_RDWR); if(fd >= 0){ - printf(1, "open . for writing succeeded!\n"); + printf("open . for writing succeeded!\n"); exit(); } fd = open(".", 0); if(write(fd, "x", 1) > 0){ - printf(1, "write . succeeded!\n"); + printf("write . succeeded!\n"); exit(); } close(fd); - printf(1, "dir vs file OK\n"); + printf("dir vs file OK\n"); } // test that iput() is called at the end of _namei() @@ -1513,15 +1512,15 @@ iref(void) { int i, fd; - printf(1, "empty file name\n"); + printf("empty file name\n"); for(i = 0; i < NINODE + 1; i++){ if(mkdir("irefd") != 0){ - printf(1, "mkdir irefd failed\n"); + printf("mkdir irefd failed\n"); exit(); } if(chdir("irefd") != 0){ - printf(1, "chdir irefd failed\n"); + printf("chdir irefd failed\n"); exit(); } @@ -1537,7 +1536,7 @@ iref(void) } chdir("/"); - printf(1, "empty file name OK\n"); + printf("empty file name OK\n"); } // test that fork fails gracefully @@ -1549,7 +1548,7 @@ forktest(void) enum{ N = 1000 }; int n, pid; - printf(1, "fork test\n"); + printf("fork test\n"); for(n=0; n 0; n--){ if(wait() < 0){ - printf(1, "wait stopped early\n"); + printf("wait stopped early\n"); exit(); } } if(wait() != -1){ - printf(1, "wait got too many\n"); + printf("wait got too many\n"); exit(); } - printf(1, "fork test OK\n"); + printf("fork test OK\n"); } void @@ -1594,13 +1593,13 @@ sbrktest(void) int fd; int n; - printf(stdout, "sbrk test\n"); + printf("sbrk test\n"); oldbrk = sbrk(0); // does sbrk() return the expected failure value? a = sbrk(TOOMUCH); if(a != (char*)0xffffffffffffffffL){ - printf(stdout, "sbrk() returned %p\n", a); + printf("sbrk() returned %p\n", a); exit(); } @@ -1609,7 +1608,7 @@ sbrktest(void) for(i = 0; i < 5000; i++){ b = sbrk(1); if(b != a){ - printf(stdout, "sbrk test failed %d %x %x\n", i, a, b); + printf("sbrk test failed %d %x %x\n", i, a, b); exit(); } *b = 1; @@ -1617,13 +1616,13 @@ sbrktest(void) } pid = fork(); if(pid < 0){ - printf(stdout, "sbrk test fork failed\n"); + printf("sbrk test fork failed\n"); exit(); } c = sbrk(1); c = sbrk(1); if(c != a + 1){ - printf(stdout, "sbrk test failed post-fork\n"); + printf("sbrk test failed post-fork\n"); exit(); } if(pid == 0) @@ -1635,7 +1634,7 @@ sbrktest(void) amt = BIG - (uint64)a; p = sbrk(amt); if (p != a) { - printf(stdout, "sbrk test failed to grow big address space; enough phys mem?\n"); + printf("sbrk test failed to grow big address space; enough phys mem?\n"); exit(); } lastaddr = (char*) (BIG-1); @@ -1645,12 +1644,12 @@ sbrktest(void) a = sbrk(0); c = sbrk(-PGSIZE); if(c == (char*)0xffffffffffffffffL){ - printf(stdout, "sbrk could not deallocate\n"); + printf("sbrk could not deallocate\n"); exit(); } c = sbrk(0); if(c != a - PGSIZE){ - printf(stdout, "sbrk deallocation produced wrong address, a %x c %x\n", a, c); + printf("sbrk deallocation produced wrong address, a %x c %x\n", a, c); exit(); } @@ -1658,19 +1657,19 @@ sbrktest(void) a = sbrk(0); c = sbrk(PGSIZE); if(c != a || sbrk(0) != a + PGSIZE){ - printf(stdout, "sbrk re-allocation failed, a %x c %x\n", a, c); + printf("sbrk re-allocation failed, a %x c %x\n", a, c); exit(); } if(*lastaddr == 99){ // should be zero - printf(stdout, "sbrk de-allocation didn't really deallocate\n"); + printf("sbrk de-allocation didn't really deallocate\n"); exit(); } a = sbrk(0); c = sbrk(-(sbrk(0) - oldbrk)); if(c != a){ - printf(stdout, "sbrk downsize failed, a %x c %x\n", a, c); + printf("sbrk downsize failed, a %x c %x\n", a, c); exit(); } @@ -1679,11 +1678,11 @@ sbrktest(void) ppid = getpid(); pid = fork(); if(pid < 0){ - printf(stdout, "fork failed\n"); + printf("fork failed\n"); exit(); } if(pid == 0){ - printf(stdout, "oops could read %x = %x\n", a, *a); + printf("oops could read %x = %x\n", a, *a); kill(ppid); exit(); } @@ -1693,7 +1692,7 @@ sbrktest(void) // if we run the system out of memory, does it clean up the last // failed allocation? if(pipe(fds) != 0){ - printf(1, "pipe() failed\n"); + printf("pipe() failed\n"); exit(); } for(i = 0; i < sizeof(pids)/sizeof(pids[0]); i++){ @@ -1718,7 +1717,7 @@ sbrktest(void) wait(); } if(c == (char*)0xffffffffffffffffL){ - printf(stdout, "failed sbrk leaked memory\n"); + printf("failed sbrk leaked memory\n"); exit(); } @@ -1726,7 +1725,7 @@ sbrktest(void) ppid = getpid(); pid = fork(); if(pid < 0){ - printf(stdout, "fork failed\n"); + printf("fork failed\n"); exit(); } @@ -1739,7 +1738,7 @@ sbrktest(void) for (i = 0; i < 10*BIG; i += PGSIZE) { n += *(a+i); } - printf(stdout, "allocate a lot of memory succeeded %d\n", n); + printf("allocate a lot of memory succeeded %d\n", n); kill(ppid); exit(); } @@ -1750,11 +1749,11 @@ sbrktest(void) fd = open("sbrk", O_CREATE|O_WRONLY); unlink("sbrk"); if(fd < 0) { - printf(stdout, "open sbrk failed\n"); + printf("open sbrk failed\n"); exit(); } if ((n = write(fd, a, 10)) < 0) { - printf(stdout, "write sbrk failed\n"); + printf("write sbrk failed\n"); exit(); } close(fd); @@ -1762,14 +1761,14 @@ sbrktest(void) // test writes to allocated memory a = sbrk(PGSIZE); if(pipe((int *) a) != 0){ - printf(1, "pipe() failed\n"); + printf("pipe() failed\n"); exit(); } if(sbrk(0) > oldbrk) sbrk(-(sbrk(0) - oldbrk)); - printf(stdout, "sbrk test OK\n"); + printf("sbrk test OK\n"); } void @@ -1778,18 +1777,18 @@ validatetest(void) int hi; uint64 p; - printf(stdout, "validate test\n"); + printf("validate test\n"); hi = 1100*1024; for(p = 0; p <= (uint)hi; p += PGSIZE){ // try to crash the kernel by passing in a bad string pointer if(link("nosuchfile", (char*)p) != -1){ - printf(stdout, "link should not succeed\n"); + printf("link should not succeed\n"); exit(); } } - printf(stdout, "validate ok\n"); + printf("validate ok\n"); } // does unintialized data start out zero? @@ -1799,14 +1798,14 @@ bsstest(void) { int i; - printf(stdout, "bss test\n"); + printf("bss test\n"); for(i = 0; i < sizeof(uninit); i++){ if(uninit[i] != '\0'){ - printf(stdout, "bss test failed\n"); + printf("bss test failed\n"); exit(); } } - printf(stdout, "bss test ok\n"); + printf("bss test ok\n"); } // does exec return an error if the arguments @@ -1825,20 +1824,20 @@ bigargtest(void) for(i = 0; i < MAXARG-1; i++) args[i] = "bigargs test: failed\n "; args[MAXARG-1] = 0; - printf(stdout, "bigarg test\n"); + printf("bigarg test\n"); exec("echo", args); - printf(stdout, "bigarg test ok\n"); + printf("bigarg test ok\n"); fd = open("bigarg-ok", O_CREATE); close(fd); exit(); } else if(pid < 0){ - printf(stdout, "bigargtest: fork failed\n"); + printf("bigargtest: fork failed\n"); exit(); } wait(); fd = open("bigarg-ok", 0); if(fd < 0){ - printf(stdout, "bigarg test failed!\n"); + printf("bigarg test failed!\n"); exit(); } close(fd); @@ -1853,7 +1852,7 @@ fsfull() int nfiles; int fsblocks = 0; - printf(1, "fsfull test\n"); + printf("fsfull test\n"); for(nfiles = 0; ; nfiles++){ char name[64]; @@ -1863,10 +1862,10 @@ fsfull() name[3] = '0' + (nfiles % 100) / 10; name[4] = '0' + (nfiles % 10); name[5] = '\0'; - printf(1, "writing %s\n", name); + printf("writing %s\n", name); int fd = open(name, O_CREATE|O_RDWR); if(fd < 0){ - printf(1, "open %s failed\n", name); + printf("open %s failed\n", name); break; } int total = 0; @@ -1877,7 +1876,7 @@ fsfull() total += cc; fsblocks++; } - printf(1, "wrote %d bytes\n", total); + printf("wrote %d bytes\n", total); close(fd); if(total == 0) break; @@ -1895,7 +1894,7 @@ fsfull() nfiles--; } - printf(1, "fsfull test finished\n"); + printf("fsfull test finished\n"); } void argptest() @@ -1903,12 +1902,12 @@ void argptest() int fd; fd = open("init", O_RDONLY); if (fd < 0) { - printf(2, "open failed\n"); + fprintf(2, "open failed\n"); exit(); } read(fd, sbrk(0) - 1, -1); close(fd); - printf(1, "arg test passed\n"); + printf("arg test passed\n"); } unsigned long randstate = 1; @@ -1927,31 +1926,31 @@ stacktest() int pid; int ppid = getpid(); - printf(1, "stack guard test\n"); + printf("stack guard test\n"); pid = fork(); if(pid == 0) { char *sp = (char *) r_sp(); sp -= PGSIZE; // the *sp should cause a trap. - printf(1, "stacktest: read below stack %p\n", *sp); - printf(1, "stacktest: test FAILED\n"); + printf("stacktest: read below stack %p\n", *sp); + printf("stacktest: test FAILED\n"); kill(ppid); exit(); } else if(pid < 0){ - printf (1, "fork failed\n"); + printf("fork failed\n"); exit(); } wait(); - printf(1, "stack guard test ok\n"); + printf("stack guard test ok\n"); } int main(int argc, char *argv[]) { - printf(1, "usertests starting\n"); + printf("usertests starting\n"); if(open("usertests.ran", 0) >= 0){ - printf(1, "already ran user tests -- rebuild fs.img\n"); + printf("already ran user tests -- rebuild fs.img\n"); exit(); } close(open("usertests.ran", O_CREATE)); diff --git a/user/wc.c b/user/wc.c index e2543a6..43bbf16 100644 --- a/user/wc.c +++ b/user/wc.c @@ -26,10 +26,10 @@ wc(int fd, char *name) } } if(n < 0){ - printf(1, "wc: read error\n"); + printf("wc: read error\n"); exit(); } - printf(1, "%d %d %d %s\n", l, w, c, name); + printf("%d %d %d %s\n", l, w, c, name); } int @@ -44,7 +44,7 @@ main(int argc, char *argv[]) for(i = 1; i < argc; i++){ if((fd = open(argv[i], 0)) < 0){ - printf(1, "wc: cannot open %s\n", argv[i]); + printf("wc: cannot open %s\n", argv[i]); exit(); } wc(fd, argv[i]);