X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=sys%2Fsrc%2Fcmd%2Fcwfs%2Fmain.c;h=8cf0ebc79aa2899f62ee77b2afc056c4b926a800;hb=755108a1446fe9571717f9b28b731137755248e5;hp=9790ad0e8e12c95f06e055884cf3f4f4ab56c303;hpb=07fdda9725f1c3d6fc1f25e0c230ad38574f7b7e;p=plan9front.git diff --git a/sys/src/cmd/cwfs/main.c b/sys/src/cmd/cwfs/main.c index 9790ad0e8..8cf0ebc79 100644 --- a/sys/src/cmd/cwfs/main.c +++ b/sys/src/cmd/cwfs/main.c @@ -3,12 +3,11 @@ #include "io.h" #include "9p1.h" -extern int oldcachefmt; - Map *devmap; -int sfd, rfd; Biobuf bin; +int chatty = 0; +int sfd = -1; void machinit(void) @@ -16,38 +15,6 @@ machinit(void) active.exiting = 0; } -/* - * Put a string on the console. - */ -void -puts(char *s, int n) -{ - print("%.*s", n, s); -} - -void -prflush(void) -{ -} - -/* - * Print a string on the console. - */ -void -putstrn(char *str, int n) -{ - puts(str, n); -} - -/* - * get a character from the console - */ -int -getc(void) -{ - return Bgetrune(&bin); -} - void panic(char *fmt, ...) { @@ -59,7 +26,7 @@ panic(char *fmt, ...) n = vseprint(buf, buf + sizeof buf, fmt, arg) - buf; va_end(arg); buf[n] = '\0'; - print("panic: %s\n", buf); + fprint(2, "panic: %s\n", buf); exit(); } @@ -92,12 +59,12 @@ mapinit(char *mapfile) if (bp == nil) sysfatal("can't read %s", mapfile); devmap = nil; - while ((ln = Brdline(bp, '\n')) != nil) { + while((ln = Brdline(bp, '\n')) != nil) { ln[Blinelen(bp)-1] = '\0'; - if (*ln == '\0' || *ln == '#') + if(*ln == '\0' || *ln == '#') continue; nf = tokenize(ln, fields, nelem(fields)); - if (nf != 2) + if(nf != 2) continue; if(testconfig(fields[0]) != 0) { print("bad `from' device %s in %s\n", @@ -109,7 +76,7 @@ mapinit(char *mapfile) map->to = strdup(fields[1]); map->fdev = iconfig(fields[0]); map->tdev = nil; - if (access(map->to, AEXIST) < 0) { + if(access(map->to, AEXIST) < 0) { /* * map->to isn't an existing file, so it had better be * a config string for a device. @@ -129,8 +96,6 @@ confinit(void) { conf.nmach = 1; - conf.mem = meminit(); - conf.nuid = 1000; conf.nserve = 15; /* tunable */ conf.nfile = 30000; @@ -140,7 +105,6 @@ confinit(void) localconfinit(); conf.nwpath = conf.nfile*8; - conf.nauth = conf.nfile/10; conf.gidspace = conf.nuid*3; cons.flags = 0; @@ -177,25 +141,25 @@ postservice(void) if(service[0] == 0) panic("no service name"); - if(sfd < 0){ - if(pipe(p) < 0) - panic("can't make a pipe"); - sfd = p[0]; - rfd = p[1]; + /* serve 9p for -s */ + if(sfd >= 0){ + srvchan(sfd, "stdio"); + sfd = -1; } /* post 9p service */ - snprint(buf, sizeof(buf), "#s/%s", service); - srvfd(buf, 0666, sfd); - close(sfd); - srvchan(rfd, buf); - if(pipe(p) < 0) panic("can't make a pipe"); + snprint(buf, sizeof(buf), "#s/%s", service); + srvfd(buf, 0666, p[0]); + close(p[0]); + srvchan(p[1], buf); /* post cmd service */ + if(pipe(p) < 0) + panic("can't make a pipe"); snprint(buf, sizeof(buf), "#s/%s.cmd", service); - srvfd(buf, 0222, p[0]); + srvfd(buf, 0660, p[0]); close(p[0]); /* use it as stdin */ @@ -204,7 +168,7 @@ postservice(void) } /* - * compute BUFSIZE*(NDBLOCK+INDPERBUF+INDPERBUF⁲+INDPERBUF⁳+INDPERBUF⁴) + * compute BUFSIZE*(NDBLOCK+INDPERBUF+INDPERBUF²+INDPERBUF³+INDPERBUF⁴) * while watching for overflow; in that case, return 0. */ @@ -246,8 +210,8 @@ maxsize(void) } enum { - INDPERBUF⁲ = ((uvlong)INDPERBUF *INDPERBUF), - INDPERBUF⁴ = ((uvlong)INDPERBUF⁲*INDPERBUF⁲), + INDPERBUF² = ((uvlong)INDPERBUF*INDPERBUF), + INDPERBUF⁴ = ((uvlong)INDPERBUF²*INDPERBUF²), }; static void @@ -265,9 +229,9 @@ printsizes(void) max = offlim - 1; print("max file size = %,llud\n", (Wideoff)max); } - if (INDPERBUF⁲/INDPERBUF != INDPERBUF) - print("overflow computing INDPERBUF⁲\n"); - if (INDPERBUF⁴/INDPERBUF⁲ != INDPERBUF⁲) + if (INDPERBUF²/INDPERBUF != INDPERBUF) + print("overflow computing INDPERBUF²\n"); + if (INDPERBUF⁴/INDPERBUF² != INDPERBUF²) print("overflow computing INDPERBUF⁴\n"); print("\tINDPERBUF = %d, INDPERBUF^4 = %,lld, ", INDPERBUF, (Wideoff)INDPERBUF⁴); @@ -279,7 +243,7 @@ printsizes(void) void usage(void) { - fprint(2, "usage: %s [ -csC ] [ -a ann-str ] [ -m dev-map ] [-f config-dev ]\n", argv0); + fprint(2, "usage: %s [ -csC ] [-n service] [ -a ann-str ] [ -m dev-map ] [-f config-dev ]\n", argv0); exits("usage"); } @@ -292,10 +256,8 @@ main(int argc, char **argv) rfork(RFNOTEG); formatinit(); machinit(); - conf.confdev = "/dev/sdC0/cwfs"; - strcpy(service, "cwfs"); - - rfd = sfd = -1; + conf.confdev = "/dev/sdC0/fscache"; + conf.newcache = 0; ARGBEGIN{ case 'a': /* announce on this net */ @@ -307,9 +269,12 @@ main(int argc, char **argv) } annstrs[nets++] = ann; break; + case 'n': + strcpy(service, EARGF(usage())); + break; case 's': - sfd = dup(0, -1); - rfd = dup(1, -1); + dup(0, -1); + sfd = dup(1, -1); close(0); if(open("/dev/cons", OREAD) < 0) open("#c/cons", OREAD); @@ -318,7 +283,7 @@ main(int argc, char **argv) open("#c/cons", OWRITE); break; case 'C': /* use new, faster cache layout */ - oldcachefmt = 0; + conf.newcache = 1; break; case 'c': conf.configfirst++; @@ -329,6 +294,9 @@ main(int argc, char **argv) case 'm': /* name device-map file */ conf.devmap = EARGF(usage()); break; + case 'd': + chatty++; + break; default: usage(); break; @@ -340,12 +308,12 @@ main(int argc, char **argv) Binit(&bin, 0, OREAD); confinit(); - print("\nPlan 9 %d-bit cached-worm file server with %d-deep indir blks\n", - sizeof(Off)*8 - 1, NIBLOCK); - printsizes(); + if(chatty){ + print("\nPlan 9 %d-bit cached-worm file server with %d-deep indir blks\n", + sizeof(Off)*8 - 1, NIBLOCK); + printsizes(); + } - qlock(&reflock); - qunlock(&reflock); serveq = newqueue(1000, "9P service"); /* tunable */ raheadq = newqueue(1000, "readahead"); /* tunable */ @@ -362,17 +330,13 @@ main(int argc, char **argv) wpaths = malloc(conf.nwpath * sizeof(*wpaths)); uid = malloc(conf.nuid * sizeof(*uid)); gidspace = malloc(conf.gidspace * sizeof(*gidspace)); - authinit(); - print("iobufinit\n"); iobufinit(); arginit(); boottime = time(nil); - print("sysinit\n"); sysinit(); - srvinit(); /* @@ -380,6 +344,11 @@ main(int argc, char **argv) */ postservice(); + /* + * processes to read the console + */ + consserve(); + /* * Ethernet i/o processes */ @@ -406,10 +375,8 @@ main(int argc, char **argv) */ newproc(synccopy, 0, "scp"); - /* - * processes to read the console - */ - consserve(); + /* success */ + exits(nil); } /* @@ -482,7 +449,6 @@ serve(void *) Msgbuf *mb; for (;;) { - qlock(&reflock); /* read 9P request from a network input process */ mb = fs_recv(serveq, 0); assert(mb->magic == Mbmagic); @@ -491,7 +457,6 @@ serve(void *) if (cp == nil) panic("serve: nil mb->chan"); rlock(&cp->reflock); - qunlock(&reflock); rlock(&mainlock); @@ -506,11 +471,9 @@ serve(void *) cp->protocol = fsprotocol[i]; break; } - if(cp->protocol == nil){ - print("no protocol for message\n"); - for(i = 0; i < 12; i++) - print(" %2.2uX", mb->data[i]); - print("\n"); + if(cp->protocol == nil && (chatty > 1)){ + fprint(2, "no protocol for message\n"); + hexdump(mb->data, 12); } } else /* process the request, generate an answer and reply */ @@ -529,7 +492,7 @@ exit(void) active.exiting = 1; unlock(&active); - print("halted at %T.\n", time(nil)); + fprint(2, "halted at %T.\n", time(nil)); postnote(PNGROUP, getpid(), "die"); exits(nil); } @@ -548,8 +511,8 @@ nextdump(Timet t) { Timet nddate = nextime(t+MINUTE(100), DUMPTIME, WEEKMASK); - if(!conf.nodump) - print("next dump at %T\n", nddate); + if(!conf.nodump && chatty) + fprint(2, "next dump at %T\n", nddate); return nddate; } @@ -575,10 +538,6 @@ wormcopy(void *) } dt = time(nil) - t; if(dt < 0 || dt > MINUTE(100)) { - if(dt < 0) - print("time went back\n"); - else - print("time jumped ahead\n"); dorecalc = 1; continue; } @@ -588,7 +547,7 @@ wormcopy(void *) ntoytime = time(nil) + HOUR(1); else if(t > nddate) { if(!conf.nodump) { - print("automatic dump %T\n", t); + fprint(2, "automatic dump %T\n", t); for(fs=filsys; fs->name; fs++) if(fs->dev->type == Devcw) cfsdump(fs);