diff options
author | cinap_lenrek <cinap_lenrek@centraldogma> | 2011-04-28 19:40:57 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@centraldogma> | 2011-04-28 19:40:57 +0000 |
commit | d1a1034cbe1492a5b4cfdac5c3190dd5d069bc4f (patch) | |
tree | 716c15fb5221aa4180a82df3c791f9846f2832ce | |
parent | c67c29952af0a50c265bf34fc317518fd43a8950 (diff) | |
download | plan9front-d1a1034cbe1492a5b4cfdac5c3190dd5d069bc4f.tar.xz |
cwfs: reduce verbosity, added -d options if you want it anyway
-rw-r--r-- | sys/src/cmd/cwfs/auth.c | 10 | ||||
-rw-r--r-- | sys/src/cmd/cwfs/config.c | 47 | ||||
-rw-r--r-- | sys/src/cmd/cwfs/cw.c | 144 | ||||
-rw-r--r-- | sys/src/cmd/cwfs/fworm.c | 19 | ||||
-rw-r--r-- | sys/src/cmd/cwfs/iobuf.c | 62 | ||||
-rw-r--r-- | sys/src/cmd/cwfs/juke.c | 168 | ||||
-rw-r--r-- | sys/src/cmd/cwfs/main.c | 39 | ||||
-rw-r--r-- | sys/src/cmd/cwfs/malloc.c | 12 | ||||
-rw-r--r-- | sys/src/cmd/cwfs/portdat.h | 1 | ||||
-rw-r--r-- | sys/src/cmd/cwfs/srv.c | 11 | ||||
-rw-r--r-- | sys/src/cmd/cwfs/sub.c | 45 | ||||
-rw-r--r-- | sys/src/cmd/cwfs/wren.c | 25 |
12 files changed, 275 insertions, 308 deletions
diff --git a/sys/src/cmd/cwfs/auth.c b/sys/src/cmd/cwfs/auth.c index f55717c8e..d54a40dee 100644 --- a/sys/src/cmd/cwfs/auth.c +++ b/sys/src/cmd/cwfs/auth.c @@ -24,16 +24,18 @@ nvrcheck(void) uchar csum; if (readnvram(&nvr, NVread) < 0) { - print("nvrcheck: can't read nvram\n"); + fprint(2, "nvrcheck: can't read nvram\n"); return 1; } else gotnvr = 1; - print("nvr read\n"); + + if(chatty) + print("nvr read\n"); csum = nvcsum(nvr.machkey, sizeof nvr.machkey); if(csum != nvr.machsum) { - print("\n\n ** NVR key checksum is incorrect **\n"); - print(" ** set password to allow attaches **\n\n"); + fprint(2, "\n\n ** NVR key checksum is incorrect **\n"); + fprint(2, " ** set password to allow attaches **\n\n"); memset(nvr.machkey, 0, sizeof nvr.machkey); return 1; } diff --git a/sys/src/cmd/cwfs/config.c b/sys/src/cmd/cwfs/config.c index d11944747..45f99aa2a 100644 --- a/sys/src/cmd/cwfs/config.c +++ b/sys/src/cmd/cwfs/config.c @@ -41,7 +41,7 @@ devcmpr(Device *d1, Device *d2) switch(d1->type) { default: - print("can't compare dev: %Z\n", d1); + fprint(2, "can't compare dev: %Z\n", d1); panic("devcmp"); return 1; @@ -208,17 +208,16 @@ map(Device *d) break; if (map == nil) return; - if (access(map->to, AEXIST) >= 0) -{ print("map: mapped wren %Z to existing file %s\n", d, map->to); // DEBUG + if (access(map->to, AEXIST) >= 0){ + if(chatty) + print("map: mapped wren %Z to existing file %s\n", d, map->to); d->wren.file = map->to; /* wren -> file mapping */ -} - else if (map->tdev != nil) -{ print("map: mapped wren %Z to dev %Z\n", d, map->tdev); // DEBUG + } else if (map->tdev != nil){ + if(chatty) + print("map: mapped wren %Z to dev %Z\n", d, map->tdev); *d = *map->tdev; /* wren -> wren mapping */ -} - else - print("bad mapping %Z to %s; no such file or device", - d, map->to); + } else + fprint(2, "bad mapping %Z to %s; no such file or device", d, map->to); d->wren.mapped = 1; } @@ -476,7 +475,7 @@ mergeconf(Iobuf *p) } else if ((fsp = getpar(word)) != nil) { cp = getwrd(word, cp); if (!isascii(word[0]) || !isdigit(word[0])) - print("bad %s value: %s", fsp->name, word); + fprint(2, "bad %s value: %s", fsp->name, word); else fsp->declared = atol(word); } else { @@ -539,7 +538,8 @@ start: devnone = iconfig("n"); cp = nvrgetconfig(); - print("config %s\n", cp); + if(chatty) + print("config %s\n", cp); confdev = d = iconfig(cp); devinit(d); @@ -568,7 +568,7 @@ start: } /* warn if declared value is not our compiled-in value */ if (fsp->declared != fsp->actual) - print("warning: config %s %ld != compiled-in %ld\n", + fprint(2, "warning: config %s %ld != compiled-in %ld\n", fsp->name, fsp->declared, fsp->actual); } @@ -593,12 +593,12 @@ start: putbuf(p); f.modconf = f.newconf = 0; - print("config block written\n"); goto start; } putbuf(p); - print("service %s\n", service); + if(chatty) + print("service %s\n", service); loop: /* @@ -618,7 +618,8 @@ loop: */ error = 0; for(fs=filsys; fs->name; fs++) { - print("filsys %s %s\n", fs->name, fs->conf); + if(chatty) + print("filsys %s %s\n", fs->name, fs->conf); fs->dev = iconfig(fs->conf); if(f.error) { error = 1; @@ -633,7 +634,8 @@ loop: */ for(fs=filsys; fs->name; fs++) { delay(3000); - print("sysinit: %s\n", fs->name); + if(chatty) + print("sysinit: %s\n", fs->name); if(fs->flags & FREAM) devream(fs->dev, 1); if(fs->flags & FRECOVER) @@ -669,7 +671,7 @@ blockok(Device *d, Off a) Iobuf *p = getbuf(d, a, Brd); if (p == 0) { - print("i/o error reading %Z block %lld\n", d, (Wideoff)a); + fprint(2, "i/o error reading %Z block %lld\n", d, (Wideoff)a); return 0; } putbuf(p); @@ -695,7 +697,6 @@ wormof(Device *dev) if (cw != nil && cw->type == Devcw) worm = cw->cw.w; } - // print("wormof(%Z)=%Z\n", dev, worm); return worm; } @@ -709,7 +710,8 @@ writtensize(Device *worm) Devsize lim = devsize(worm); Iobuf *p; - print("devsize(%Z) = %lld\n", worm, (Wideoff)lim); + if(chatty) + print("devsize(%Z) = %lld\n", worm, (Wideoff)lim); if (!blockok(worm, 0) || !blockok(worm, lim-1)) return 0; delay(5*1000); @@ -729,7 +731,8 @@ writtensize(Device *worm) break; } } - print("limit(%Z) = %lld\n", worm, (Wideoff)lim); + if(chatty) + print("limit(%Z) = %lld\n", worm, (Wideoff)lim); if (lim <= 0) return 0; return lim + 1; @@ -898,7 +901,7 @@ dodevcopy(void) * be contiguous. */ if (p == 0) { - print("%lld not written yet; can't read\n", (Wideoff)a); + fprint(2, "%lld not written yet; can't read\n", (Wideoff)a); continue; } if (to != 0 && devwrite(to, p->addr, p->iobuf) != 0) { diff --git a/sys/src/cmd/cwfs/cw.c b/sys/src/cmd/cwfs/cw.c index f52112732..05a400c2d 100644 --- a/sys/src/cmd/cwfs/cw.c +++ b/sys/src/cmd/cwfs/cw.c @@ -8,7 +8,6 @@ #define RDEV(d) ((d)->cw.ro) enum { - DEBUG = 0, FIRST = SUPER_ADDR, ADDFREE = 100, @@ -194,9 +193,6 @@ cmd_statw(int, char*[]) /* print stats in terms of (first-)disc sides */ dsize = wormsizeside(dev, 0); if (dsize < 1) { - if (DEBUG) - print("wormsizeside returned size %lld for %Z side 0\n", - (Wideoff)dsize, dev); dsize = h->wsize; /* it's probably a fake worm */ if (dsize < 1) dsize = 1000; /* don't divide by zero */ @@ -297,8 +293,9 @@ dumpblock(Device *dev) } putbuf(p); } - if(cw->ncopy) { - print("%lld blocks copied to worm\n", (Wideoff)cw->ncopy); + if(cw->ncopy){ + if(chatty) + print("%lld blocks copied to worm\n", (Wideoff)cw->ncopy); cw->ncopy = 0; } cw->nodump = 1; @@ -342,7 +339,7 @@ retry: if(s1) goto stop1; if(memcmp(p1->iobuf, p2->iobuf, RBUFSIZE)) { - print("reread C%lld W%lld didnt compare\n", + fprint(2, "reread C%lld W%lld didnt compare\n", (Wideoff)a, (Wideoff)m); goto stop1; } @@ -429,8 +426,9 @@ cwinit(Device *dev) h->time = time(nil); m = h->wsize; if(l != m) { - print("wdev changed size %lld to %lld\n", - (Wideoff)m, (Wideoff)l); + if(chatty) + print("wdev changed size %lld to %lld\n", + (Wideoff)m, (Wideoff)l); h->wsize = l; cb->flags |= Bmod; } @@ -464,7 +462,7 @@ cwraddr(Device *dev) switch(dev->type) { default: - print("unknown dev in cwraddr %Z\n", dev); + fprint(2, "unknown dev in cwraddr %Z\n", dev); return 1; case Devcw: @@ -517,7 +515,7 @@ roread(Device *dev, Off b, void *c) d = dev->ro.parent; if(d == 0 || d->type != Devcw || d->private == 0 || RDEV(d) != dev) { - print("bad rodev %Z\n", dev); + fprint(2, "bad rodev %Z\n", dev); return 1; } s = cwio(d, b, 0, Onone); @@ -581,7 +579,7 @@ cwio(Device *dev, Off addr, void *buf, int opcode) c = getcentry(b, addr); if(c == 0) { putbuf(p); - print("%Z disk cache bucket %lld is full\n", + fprint(2, "%Z disk cache bucket %lld is full\n", cw->cdev, (Wideoff)a1); return Cerror; } @@ -646,7 +644,7 @@ cwio(Device *dev, Off addr, void *buf, int opcode) p1 = getbuf(devnone, Cwio1, 0); if(devread(cw->cdev, a2, p1->iobuf)) { putbuf(p1); - print("cwio: write induced dump error - r cache\n"); + fprint(2, "cwio: write induced dump error - r cache\n"); casenone: if(devwrite(cw->cdev, a2, buf)) { @@ -661,13 +659,13 @@ cwio(Device *dev, Off addr, void *buf, int opcode) if(devread(cw->wdev, addr, p2->iobuf)) { putbuf(p1); putbuf(p2); - print("cwio: write induced dump error - r+w worm\n"); + fprint(2, "cwio: write induced dump error - r+w worm\n"); goto casenone; } if(memcmp(p1->iobuf, p2->iobuf, RBUFSIZE)) { putbuf(p1); putbuf(p2); - print("cwio: write induced dump error - w worm\n"); + fprint(2, "cwio: write induced dump error - w worm\n"); goto casenone; } putbuf(p2); @@ -697,7 +695,7 @@ cwio(Device *dev, Off addr, void *buf, int opcode) case Ogrow: if(state != Cnone) { - print("%Z for block %lld cwgrow with state = %s\n", + fprint(2, "%Z for block %lld cwgrow with state = %s\n", cw->cdev, (Wideoff)addr, cwnames[state]); break; } @@ -706,7 +704,7 @@ cwio(Device *dev, Off addr, void *buf, int opcode) case Odump: if(state != Cdirty) { /* BOTCH */ - print("%Z for block %lld cwdump with state = %s\n", + fprint(2, "%Z for block %lld cwdump with state = %s\n", cw->cdev, (Wideoff)addr, cwnames[state]); break; } @@ -717,7 +715,7 @@ cwio(Device *dev, Off addr, void *buf, int opcode) case Orele: if(state != Cwrite) { if(state != Cdump1) - print("%Z for block %lld cwrele with state = %s\n", + fprint(2, "%Z for block %lld cwrele with state = %s\n", cw->cdev, (Wideoff)addr, cwnames[state]); break; } @@ -729,7 +727,7 @@ cwio(Device *dev, Off addr, void *buf, int opcode) c->state = Cnone; break; } - if(DEBUG) + if(chatty > 1) print("cwio: %Z %lld s=%s o=%s ns=%s\n", dev, (Wideoff)addr, cwnames[state], cwnames[opcode], @@ -745,7 +743,7 @@ cwio(Device *dev, Off addr, void *buf, int opcode) return state; bad: - print("%Z block %lld cw state = %s; cw opcode = %s", + fprint(2, "%Z block %lld cw state = %s; cw opcode = %s", dev, (Wideoff)addr, cwnames[state], cwnames[opcode]); return Cerror; } @@ -942,7 +940,8 @@ cacheinit(Device *dev) Device *cdev; Off m; - print("cache init %Z\n", dev); + if(chatty) + print("cache init %Z\n", dev); cdev = CDEV(dev); devinit(cdev); @@ -980,7 +979,6 @@ cacheinit(Device *dev) settag(p, Tbuck, m); putbuf(p); } - print("done cacheinit\n"); return cb; } @@ -990,17 +988,17 @@ getstartsb(Device *dev) Filsys *f; Startsb *s; - for(f=filsys; f->name; f++) + for(f=filsys; f->name; f++){ if(devcmpr(f->dev, dev) == 0) { for(s=startsb; s->name; s++) if(strcmp(f->name, s->name) == 0) return s->startsb; - print( - "getstartsb: no special starting superblock for %Z %s\n", + fprint(2, "getstartsb: no special starting superblock for %Z %s\n", dev, f->name); return FIRST; } - print("getstartsb: no filsys for device %Z\n", dev); + } + fprint(2, "getstartsb: no filsys for device %Z\n", dev); return FIRST; } @@ -1019,7 +1017,8 @@ cwrecover(Device *dev) Off m, baddr; Device *wdev; -// print("cwrecover %Z\n", dev); // DEBUG + if(chatty) + print("cwrecover %Z\n", dev); cwinit1(dev); wdev = WDEV(dev); @@ -1037,7 +1036,8 @@ cwrecover(Device *dev) break; baddr = m; m = s->next; - print("dump %lld is good; %lld next\n", (Wideoff)baddr, (Wideoff)m); + if(chatty) + print("dump %lld is good; %lld next\n", (Wideoff)baddr, (Wideoff)m); if(baddr == conf.recovsb) break; } @@ -1075,7 +1075,6 @@ cwrecover(Device *dev) s->roraddr = conf.recovro; putbuf(p); - print("done recover\n"); } /* @@ -1092,7 +1091,8 @@ cwream(Device *dev) Off m, baddr; Device *cdev; - print("cwream %Z\n", dev); + if(chatty) + print("cwream %Z\n", dev); cwinit1(dev); cdev = CDEV(dev); devinit(cdev); @@ -1148,19 +1148,19 @@ rewalk1(Cw *cw, Off addr, int slot, Wpath *up) p = getbuf(cw->dev, up->addr, Brd|Bmod); d = getdir(p, up->slot); if(!d || !(d->mode & DALLOC)) { - print("rewalk1 1\n"); + fprint(2, "rewalk1 1\n"); if(p) putbuf(p); return addr; } p1 = dnodebuf(p, d, slot/DIRPERBUF, 0, 0); if(!p1) { - print("rewalk1 2\n"); + fprint(2, "rewalk1 2\n"); if(p) putbuf(p); return addr; } - if(DEBUG) + if(chatty > 1) print("rewalk1 %lld to %lld \"%s\"\n", (Wideoff)addr, (Wideoff)p1->addr, d->name); addr = p1->addr; @@ -1182,19 +1182,19 @@ rewalk2(Cw *cw, Off addr, int slot, Wpath *up) p = getbuf(cw->rodev, up->addr, Brd); d = getdir(p, up->slot); if(!d || !(d->mode & DALLOC)) { - print("rewalk2 1\n"); + fprint(2, "rewalk2 1\n"); if(p) putbuf(p); return addr; } p1 = dnodebuf(p, d, slot/DIRPERBUF, 0, 0); if(!p1) { - print("rewalk2 2\n"); + fprint(2, "rewalk2 2\n"); if(p) putbuf(p); return addr; } - if(DEBUG) + if(chatty > 1) print("rewalk2 %lld to %lld \"%s\"\n", (Wideoff)addr, (Wideoff)p1->addr, d->name); addr = p1->addr; @@ -1251,8 +1251,8 @@ split(Cw *cw, Iobuf *p, Off addr) */ if(!p) { p = getbuf(cw->dev, addr, Brd); - if(!p) { - print("split: null getbuf\n"); + if(p == nil) { + fprint(2, "split: null getbuf\n"); break; } } @@ -1303,7 +1303,7 @@ cwrecur(Cw *cw, Off addr, int tag, int tag1, long qp) p = getbuf(cw->dev, addr, Bprobe); if(!isdirty(cw, p, addr, tag)) { if(!cw->all) { - if(DEBUG) + if(chatty > 1) print("cwrecur: %lld t=%s not dirty %s\n", (Wideoff)addr, tagnames[tag], cw->name); if(p) @@ -1312,11 +1312,11 @@ cwrecur(Cw *cw, Off addr, int tag, int tag1, long qp) } shouldstop = 1; } - if(DEBUG) + if(chatty > 1) print("cwrecur: %lld t=%s %s\n", (Wideoff)addr, tagnames[tag], cw->name); if(cw->depth >= 100) { - print("dump depth too great %s\n", cw->name); + fprint(2, "dump depth too great %s\n", cw->name); if(p) putbuf(p); return 0; @@ -1325,7 +1325,7 @@ cwrecur(Cw *cw, Off addr, int tag, int tag1, long qp) switch(tag) { default: - print("cwrecur: unknown tag %d %s\n", tag, cw->name); + fprint(2, "cwrecur: unknown tag %d %s\n", tag, cw->name); case Tfile: break; @@ -1334,8 +1334,8 @@ cwrecur(Cw *cw, Off addr, int tag, int tag1, long qp) case Tdir: if(!p) { p = getbuf(cw->dev, addr, Brd); - if(!p) { - print("cwrecur: Tdir p null %s\n", + if(p == nil) { + fprint(2, "cwrecur: Tdir p null %s\n", cw->name); break; } @@ -1358,7 +1358,7 @@ cwrecur(Cw *cw, Off addr, int tag, int tag1, long qp) strncpy(np, d->name, NAMELEN); else if(i > 0) - print("cwrecur: root with >1 directory\n"); + fprint(2, "cwrecur: root with >1 directory\n"); tag1 = Tfile; if(d->mode & DDIR) tag1 = Tdir; @@ -1400,8 +1400,8 @@ cwrecur(Cw *cw, Off addr, int tag, int tag1, long qp) tind: if(!p) { p = getbuf(cw->dev, addr, Brd); - if(!p) { - print("cwrecur: Tind p null %s\n", cw->name); + if(p == nil) { + fprint(2, "cwrecur: Tind p null %s\n", cw->name); break; } } @@ -1421,7 +1421,7 @@ cwrecur(Cw *cw, Off addr, int tag, int tag1, long qp) cw->depth--; if(na && shouldstop) { if(cw->falsehits < 10) - print("shouldstop %lld %lld t=%s %s\n", + fprint(2, "shouldstop %lld %lld t=%s %s\n", (Wideoff)addr, (Wideoff)na, tagnames[tag], cw->name); cw->falsehits++; @@ -1445,12 +1445,12 @@ cfsdump(Filsys *fs) Cw *cw; if(fs->dev->type != Devcw) { - print("cant dump; not cw device: %Z\n", fs->dev); + fprint(2, "cant dump; not cw device: %Z\n", fs->dev); return; } cw = fs->dev->private; if(cw == 0) { - print("cant dump: has not been inited: %Z\n", fs->dev); + fprint(2, "cant dump: has not been inited: %Z\n", fs->dev); return; } @@ -1471,13 +1471,15 @@ cfsdump(Filsys *fs) sync("before dump"); cw->fsize = cwsize(cw->dev); orba = cwraddr(cw->dev); - print("cwroot %lld", (Wideoff)orba); + if(chatty) + print("cwroot %lld", (Wideoff)orba); cons.noage = 1; cw->all = cw->allflag; rba = cwrecur(cw, orba, Tsuper, 0, QPROOT); if(rba == 0) rba = orba; - print("->%lld\n", (Wideoff)rba); + if(chatty) + print("->%lld\n", (Wideoff)rba); sync("after cw"); /* @@ -1586,23 +1588,24 @@ found: cw->fsize = cwsize(cw->dev); oroa = cwraddr(cw->rodev); /* probably redundant */ - print("roroot %lld", (Wideoff)oroa); + if(chatty) + print("roroot %lld", (Wideoff)oroa); cons.noage = 0; cw->all = 0; roa = cwrecur(cw, oroa, Tsuper, 0, QPROOT); - if(roa == 0) { - print("[same]"); + if(roa == 0) roa = oroa; - } - print("->%lld /%.4s/%s\n", (Wideoff)roa, tstr, tstr+4); + if(chatty) + print("->%lld /%.4s/%s\n", (Wideoff)roa, tstr, tstr+4); sync("after ro"); /* * final super block */ a = cwsaddr(cw->dev); - print("sblock %lld", (Wideoff)a); + if(chatty) + print("sblock %lld", (Wideoff)a); p = getbuf(cw->dev, a, Brd|Bmod|Bimm); s = (Superb*)p->iobuf; s->last = a; @@ -1615,7 +1618,8 @@ found: cwio(cw->dev, sba, 0, Ogrow); cwio(cw->dev, sba, p->iobuf, Owrite); cwio(cw->dev, sba, 0, Odump); - print("->%lld (->%lld)\n", (Wideoff)sba, (Wideoff)s->next); + if(chatty) + print("->%lld (->%lld)\n", (Wideoff)sba, (Wideoff)s->next); putbuf(p); @@ -1632,8 +1636,10 @@ found: rewalk(cw); sync("all done"); - print("%lld blocks queued for worm\n", (Wideoff)cw->ndump); - print("%lld falsehits\n", (Wideoff)cw->falsehits); + if(chatty){ + print("%lld blocks queued for worm\n", (Wideoff)cw->ndump); + print("%lld falsehits\n", (Wideoff)cw->falsehits); + } cw->nodump = 0; /* @@ -1746,9 +1752,9 @@ touchsb(Device *dev) memset(p->iobuf, 0, RBUFSIZE); if(devread(WDEV(dev), m, p->iobuf) || checktag(p, Tsuper, QPSUPER)) - print("%Z block %lld WORM SUPER BLOCK READ FAILED\n", + fprint(2, "%Z block %lld WORM SUPER BLOCK READ FAILED\n", WDEV(dev), (Wideoff)m); - else + else if(chatty) print("%Z touch superblock %lld\n", WDEV(dev), (Wideoff)m); putbuf(p); } @@ -1765,7 +1771,7 @@ storesb(Device *dev, Off last, int doit) ps = getbuf(devnone, Cwxx2, 0); if(!ps) { - print("sbstore: getbuf\n"); + fprint(2, "sbstore: getbuf\n"); return; } @@ -1851,7 +1857,7 @@ savecache(Device *dev) Device *cdev; if(walkto("/adm/cache") || con_open(FID2, OWRITE|OTRUNC)) { - print("cant open /adm/cache\n"); + fprint(2, "cant open /adm/cache\n"); return; } cdev = CDEV(dev); @@ -1905,7 +1911,7 @@ loadcache(Device *dev, int dskno) Sidestarts ss; if(walkto("/adm/cache") || con_open(FID2, OREAD)) { - print("cant open /adm/cache\n"); + fprint(2, "cant open /adm/cache\n"); return; } @@ -1981,13 +1987,13 @@ blockcmp(Device *dev, Off wa, Off ca) p1 = getbuf(WDEV(dev), wa, Brd); if(!p1) { - print("blockcmp: wdev error\n"); + fprint(2, "blockcmp: wdev error\n"); return; } p2 = getbuf(CDEV(dev), ca, Brd); if(!p2) { - print("blockcmp: cdev error\n"); + fprint(2, "blockcmp: cdev error\n"); putbuf(p1); return; } @@ -2004,8 +2010,6 @@ blockcmp(Device *dev, Off wa, Off ca) break; } - if(c == 0) - print("no error\n"); putbuf(p1); putbuf(p2); } diff --git a/sys/src/cmd/cwfs/fworm.c b/sys/src/cmd/cwfs/fworm.c index 270ec06c2..ccfd53410 100644 --- a/sys/src/cmd/cwfs/fworm.c +++ b/sys/src/cmd/cwfs/fworm.c @@ -2,8 +2,6 @@ #define FDEV(d) ((d)->fw.fw) -enum { DEBUG = 0 }; - Devsize fwormsize(Device *d) { @@ -21,13 +19,16 @@ fwormream(Device *d) Device *fdev; Off a, b; - print("fworm ream\n"); + if(chatty) + print("fworm ream\n"); devinit(d); fdev = FDEV(d); a = fwormsize(d); b = devsize(fdev); - print("\tfwsize = %lld\n", (Wideoff)a); - print("\tbwsize = %lld\n", (Wideoff)b-a); + if(chatty){ + print("\tfwsize = %lld\n", (Wideoff)a); + print("\tbwsize = %lld\n", (Wideoff)b-a); + } for(; a < b; a++) { p = getbuf(fdev, a, Bmod|Bres); if(!p) @@ -52,7 +53,7 @@ fwormread(Device *d, Off b, void *c) Device *fdev; Devsize l; - if(DEBUG) + if(chatty > 1) print("fworm read %lld\n", (Wideoff)b); fdev = FDEV(d); l = devsize(fdev); @@ -67,7 +68,7 @@ fwormread(Device *d, Off b, void *c) l = b % (BUFSIZE*8); if(!(p->iobuf[l/8] & (1<<(l%8)))) { putbuf(p); - print("fworm: read %lld\n", (Wideoff)b); + fprint(2, "fworm: read %lld\n", (Wideoff)b); return 1; } putbuf(p); @@ -81,7 +82,7 @@ fwormwrite(Device *d, Off b, void *c) Device *fdev; Devsize l; - if(DEBUG) + if(chatty > 1) print("fworm write %lld\n", (Wideoff)b); fdev = FDEV(d); l = devsize(fdev); @@ -96,7 +97,7 @@ fwormwrite(Device *d, Off b, void *c) l = b % (BUFSIZE*8); if((p->iobuf[l/8] & (1<<(l%8)))) { putbuf(p); - print("fworm: write %lld\n", (Wideoff)b); + fprint(2, "fworm: write %lld\n", (Wideoff)b); return 1; } p->iobuf[l/8] |= 1<<(l%8); diff --git a/sys/src/cmd/cwfs/iobuf.c b/sys/src/cmd/cwfs/iobuf.c index 577cc7c38..c73f65aed 100644 --- a/sys/src/cmd/cwfs/iobuf.c +++ b/sys/src/cmd/cwfs/iobuf.c @@ -1,8 +1,6 @@ #include "all.h" #include "io.h" -enum { DEBUG = 0 }; - extern long nhiob; extern Hiob *hiob; @@ -13,7 +11,7 @@ getbuf(Device *d, Off addr, int flag) Hiob *hp; Off h; - if(DEBUG) + if(chatty > 1) print("getbuf %Z(%lld) f=%x\n", d, (Wideoff)addr, flag); h = addr + (Off)(uintptr)d*1009; if(h < 0) @@ -66,7 +64,7 @@ xloop: if(!canqlock(p)) { if(p == hp->link) { unlock(hp); - print("iobuf all locked\n"); + fprint(2, "iobuf all locked\n"); goto loop; } s = p; @@ -82,7 +80,7 @@ xloop: qunlock(p); if(p == hp->link) { unlock(hp); - print("iobuf all reserved\n"); + fprint(2, "iobuf all reserved\n"); goto loop; } s = p; @@ -102,7 +100,6 @@ xloop: p->addr = addr; p->dev = d; p->flags = flag; -// p->pc = getcallerpc(&d); unlock(hp); if(iobufmap(p)) if(flag & Brd) { @@ -112,7 +109,7 @@ xloop: } else return p; else - print("iobuf cant map buffer\n"); + fprint(2, "iobuf cant map buffer %Z(%lld)\n", p->dev, (Wideoff)p->addr); p->flags = 0; p->dev = devnone; p->addr = -1; @@ -176,11 +173,11 @@ sync(char *reason) { long i; - print("sync: %s\n", reason); + if(chatty) + print("sync: %s\n", reason); for(i=10*nhiob; i>0; i--) if(!syncblock()) return; - print("sync shorted\n"); } void @@ -188,10 +185,10 @@ putbuf(Iobuf *p) { if(canqlock(p)) - print("buffer not locked %Z(%lld)\n", p->dev, (Wideoff)p->addr); + fprint(2, "buffer not locked %Z(%lld)\n", p->dev, (Wideoff)p->addr); if(p->flags & Bimm) { if(!(p->flags & Bmod)) - print("imm and no mod %Z(%lld)\n", + fprint(2, "imm and no mod %Z(%lld)\n", p->dev, (Wideoff)p->addr); if(!devwrite(p->dev, p->addr, p->iobuf)) p->flags &= ~(Bmod|Bimm); @@ -212,43 +209,14 @@ checktag(Iobuf *p, int tag, Off qpath) pc = getcallerpc(&p); if(qpath == QPNONE){ - print("checktag pc=%lux %Z(%llux) tag/path=%G/%llud; expected %G\n", + fprint(2, "checktag pc=%lux %Z(%llux) tag/path=%G/%llud; expected %G\n", pc, p->dev, (Wideoff)p->addr, t->tag, (Wideoff)t->path, tag); } else { - print("checktag pc=%lux %Z(%llux) tag/path=%G/%llud; expected %G/%llud\n", + fprint(2, "checktag pc=%lux %Z(%llux) tag/path=%G/%llud; expected %G/%llud\n", pc, p->dev, (Wideoff)p->addr, t->tag, (Wideoff)t->path, tag, qpath); } return 1; - } - - /* - if(t->tag != tag) { - if(p->flags & Bmod) { - print("\t%llux: tag = %G/%llud; expected %G/%d -- not flushed\n", - t->tag, (Wideoff)t->path, (Wideoff)qpath, tag); - return 2; - } - if(p->dev != nil && p->dev->type == Devcw) - cwfree(p->dev, p->addr); - if(p->addr != lastaddr) - print("\t%llux: tag = %G/%llud; expected %G/%lld -- flushed\n", - (Wideoff)p->addr, t->tag, (Wideoff)t->path, tag, (Wideoff)qpath); - - lastaddr = p->addr; - p->dev = devnone; - p->addr = -1; - p->flags = 0; - return 2; - } - if(qpath != QPNONE) { - if(qpath ^ t->path) { - print("\t%llux: tag/path = %G/%llud; expected %G/%llux\n", - (Wideoff)p->addr, t->tag, (Wideoff)t->path, tag, (Wideoff)qpath); - return 0; - } - } - */ - + } return 0; } @@ -276,9 +244,7 @@ iobufql(QLock *q) { Iobuf *p, *s; Hiob *hp; - Tag *t; long h; - int tag; for(h=0; h<nhiob; h++) { hp = &hiob[h]; @@ -286,12 +252,6 @@ iobufql(QLock *q) s = hp->link; for(p=s;;) { if(qlmatch(q, p)) { - t = (Tag*)(p->iobuf+BUFSIZE); - tag = t->tag; - if(tag < 0 || tag >= MAXTAG) - tag = Tnone; - print("\tIobuf %Z(%lld) t=%s\n", - p->dev, (Wideoff)p->addr, tagnames[tag]); unlock(hp); return 1; } diff --git a/sys/src/cmd/cwfs/juke.c b/sys/src/cmd/cwfs/juke.c index 51eb71dac..d552a324b 100644 --- a/sys/src/cmd/cwfs/juke.c +++ b/sys/src/cmd/cwfs/juke.c @@ -103,8 +103,8 @@ newlabel(Device *d, Off labelblk, char *labelbuf, unsigned vord) print("NOT writing new label\n"); else if (wormwrite(d, labelblk, labelbuf)) /* wormwrite will have complained in detail */ - print("can't write new label on side %d\n", vord); - else + fprint(2, "can't write new label on side %d\n", vord); + else if (chatty) print("wrote new label on side %d\n", vord); } @@ -129,13 +129,12 @@ wormlabel(Device *d, Side *v) * no need to repeat most of that detail. * probably an unwritten WORM-disc label; write a new one. */ - print("error reading label block of side %d\n", vord); + fprint(2, "error reading label block of side %d\n", vord); newlabel(d, labelblk, labelbuf, vord); } else if (label->magic != Labmagic) { swab8(&label->magic); if (label->magic == Labmagic) { - print( -"side %d's label magic byte-swapped; filsys should be configured with xD", + fprint(2, "side %d's label magic byte-swapped; filsys should be configured with xD", vord); swab2(&label->ord); /* could look for Devswab in Juke's filsys */ @@ -145,7 +144,7 @@ wormlabel(Device *d, Side *v) * probably the label is empty on RW media, * so create a new one and try to write it. */ - print("bad magic number in label of side %d\n", vord); + fprint(2, "bad magic number in label of side %d\n", vord); newlabel(d, labelblk, labelbuf, vord); } } @@ -155,15 +154,14 @@ wormlabel(Device *d, Side *v) panic("wormlabel: side %d switched ordinal to %d underfoot", vord, v->ord); if (label->ord != vord) { - print( - "labelled worm side %Z has wrong ordinal in label (%d, want %d)", + fprint(2, "labelled worm side %Z has wrong ordinal in label (%d, want %d)", d, label->ord, vord); qunlock(v); cmd_wormreset(0, nil); /* put discs away */ panic("wrong ordinal in label"); } - - print("label %Z ordinal %d\n", d, v->ord); + if(chatty) + print("label %Z ordinal %d\n", d, v->ord); qunlock(v); /* * wormunit should return without calling us again, @@ -213,7 +211,8 @@ wormunit(Device *d) /* d is l0 or r2 (e.g.) */ qunlock(w); delay(100); } - print("\tload r%ld drive %Z\n", v-w->side, w->drive[drive]); + if(chatty) + print("\tload r%ld drive %Z\n", v-w->side, w->drive[drive]); if(mmove(w, w->mt0, v->elem, w->dt0+drive, v->rot)) { qunlock(w); goto sbad; @@ -230,9 +229,9 @@ wormunit(Device *d) /* d is l0 or r2 (e.g.) */ dr = w->drive[v->drive]; if(v->status != Sstart) { if(v->status == Sempty) - print("worm: unit empty %Z\n", d); + fprint(2, "worm: unit empty %Z\n", d); else - print("worm: not started %Z\n", d); + fprint(2, "worm: not started %Z\n", d); goto sbad; } @@ -259,14 +258,15 @@ wormunit(Device *d) /* d is l0 or r2 (e.g.) */ if (dr->wren.fd == 0) dr->wren.fd = open(dr->wren.sddata, ORDWR); if (dr->wren.fd < 0) { - print("wormunit: can't open %s for %Z: %r\n", dr->wren.sddata, d); + fprint(2, "wormunit: can't open %s for %Z: %r\n", dr->wren.sddata, d); goto sbad; } v->block = inqsize(dr->wren.sddata); if(v->block <= 0) { - print("\twormunit %Z block size %ld, setting to %d\n", - d, v->block, Sectorsz); + if(chatty) + print("\twormunit %Z block size %ld, setting to %d\n", + d, v->block, Sectorsz); v->block = Sectorsz; } @@ -277,11 +277,13 @@ wormunit(Device *d) /* d is l0 or r2 (e.g.) */ v->mult = (RBUFSIZE + v->block - 1) / v->block; v->max = (v->nblock + 1) / v->mult; - print("\tworm %Z: drive %Z (juke drive %d)\n", - d, w->drive[v->drive], v->drive); - print("\t\t%,ld %ld-byte sectors, ", v->nblock, v->block); - print("%,ld %d-byte blocks\n", v->max, RBUFSIZE); - print("\t\t%ld multiplier\n", v->mult); + if(chatty){ + print("\tworm %Z: drive %Z (juke drive %d)\n", + d, w->drive[v->drive], v->drive); + print("\t\t%,ld %ld-byte sectors, ", v->nblock, v->block); + print("%,ld %d-byte blocks\n", v->max, RBUFSIZE); + print("\t\t%ld multiplier\n", v->mult); + } if(d->type == Devlworm) return wormlabel(d, v); else @@ -303,7 +305,7 @@ waitready(Juke *w, Device *d) panic("waitready: bad magic in Juke (d->private) for %Z", d); p = d->wren.targ; if(p < 0 || p >= w->nside) { - print("waitready: target %d out of range for %Z\n", p, d); + fprint(2, "waitready: target %d out of range for %Z\n", p, d); return 0; } @@ -322,16 +324,16 @@ waitready(Juke *w, Device *d) rv = 0; for(e=0; e < 100; e++) { - if (e == 10) - print("waitready: waiting for %s to exist\n", datanm); // DEBUG - if (access(datanm, AEXIST) >= 0) { + if(e == 10 && chatty) + print("waitready: waiting for %s to exist\n", datanm); + if(access(datanm, AEXIST) >= 0){ rv = 1; break; } delay(200); } - if (rv == 0) - print("waitready: %s for %Z didn't come ready\n", datanm, d); + if(rv == 0) + fprint(2, "waitready: %s for %Z didn't come ready\n", datanm, d); free(datanm); return rv; } @@ -395,8 +397,9 @@ loop: qunlock(v); goto loop; } - print("\tunload r%ld drive %Z\n", - v-w->side, w->drive[drive]); + if(chatty) + print("\tunload r%ld drive %Z\n", + v-w->side, w->drive[drive]); if(mmove(w, w->mt0, w->dt0+drive, v->elem, v->rot)) { qunlock(v); goto loop; @@ -417,7 +420,7 @@ wormsize(Device *d) w = d->private; if (w->magic != Jukemagic) - print("wormsize: bad magic in Juke (d->private) for %Z\n", d); + fprint(2, "wormsize: bad magic in Juke (d->private) for %Z\n", d); if(w->isfixedsize && w->fixedsize != 0) size = w->fixedsize; /* fixed size is now known */ else { @@ -450,8 +453,7 @@ devtojuke(Device *d, Device *top) while (d != nil) switch(d->type) { default: - print("devtojuke: type of device %Z of %Z unknown\n", - d, top); + fprint(2, "devtojuke: type of device %Z of %Z unknown\n", d, top); return nil; case Devjuke: @@ -469,8 +471,8 @@ devtojuke(Device *d, Device *top) * d->private is a (Juke *) with nside, etc., * but we're not supposed to get here. */ - print("devtojuke: (l)worm %Z of %Z encountered\n", - d, top); + if(chatty) + print("devtojuke: (l)worm %Z of %Z encountered\n", d, top); /* FALL THROUGH */ case Devwren: return nil; @@ -509,7 +511,7 @@ findside(Device *juke, int side, Device *top) for (x = mcat->cat.first; x != nil; x = x->link) { if (!devisside(x)) { - print("wormsizeside: %Z of %Z of %Z type not (l)worm\n", + fprint(2, "wormsizeside: %Z of %Z of %Z type not (l)worm\n", x, mcat, top); return nil; } @@ -523,7 +525,7 @@ findside(Device *juke, int side, Device *top) if (x == nil) return nil; if (w->side[i].time == 0) { - print("wormsizeside: side %d not in jukebox %Z\n", i, juke); + fprint(2, "wormsizeside: side %d not in jukebox %Z\n", i, juke); return nil; } return x; @@ -581,7 +583,7 @@ visitsides(Device *d, Device *parentj, Visit *vp) */ x = d->cat.first; if (x == nil) { - print("visitsides: %Z of %Z: empty mcat\n", d, vp->topdev); + fprint(2, "visitsides: %Z of %Z: empty mcat\n", d, vp->topdev); return 0; } if (!devisside(x)) { @@ -592,7 +594,7 @@ visitsides(Device *d, Device *parentj, Visit *vp) /* the side we want is in this jukebox, thus this mcat (d) */ if (parentj == nil) { - print("visitsides: no parent juke for sides mcat %Z\n", d); + fprint(2, "visitsides: no parent juke for sides mcat %Z\n", d); vp->sleft = -1; return 0; } @@ -628,7 +630,7 @@ wormsizeside(Device *d, int side) visit.topdev = d; size = visitsides(d, nil, &visit); if (visit.sawjuke && (visit.sleft != 0 || !visit.sized)) { - print("wormsizeside: fewer than %d sides in %Z\n", side, d); + fprint(2, "wormsizeside: fewer than %d sides in %Z\n", side, d); return 0; } return size; @@ -667,11 +669,11 @@ wormread(Device *d, Off b, void *c) panic("wormread: unopened fd for %Z", d); max = (d->type == Devlworm? v->max + 1: v->max); if(b >= max) { - print("wormread: block out of range %Z(%lld)\n", d, (Wideoff)b); + fprint(2, "wormread: block out of range %Z(%lld)\n", d, (Wideoff)b); r = 0x071; } else if (pread(dr->wren.fd, c, RBUFSIZE, (vlong)b*RBUFSIZE) != RBUFSIZE) { fd2path(dr->wren.fd, name, sizeof name); - print("wormread: error on %Z(%lld) on %s in %s: %r\n", + fprint(2, "wormread: error on %Z(%lld) on %s in %s: %r\n", d, (Wideoff)b, name, dr->wren.sddir); cons.nwormre++; r = 1; @@ -697,12 +699,11 @@ wormwrite(Device *d, Off b, void *c) panic("wormwrite: unopened fd for %Z", d); max = (d->type == Devlworm? v->max + 1: v->max); if(b >= max) { - print("wormwrite: block out of range %Z(%lld)\n", - d, (Wideoff)b); + fprint(2, "wormwrite: block out of range %Z(%lld)\n", d, (Wideoff)b); r = 0x071; } else if (pwrite(dr->wren.fd, c, RBUFSIZE, (vlong)b*RBUFSIZE) != RBUFSIZE) { fd2path(dr->wren.fd, name, sizeof name); - print("wormwrwite: error on %Z(%lld) on %s in %s: %r\n", + fprint(2, "wormwrwite: error on %Z(%lld) on %s in %s: %r\n", d, (Wideoff)b, name, dr->wren.sddir); cons.nwormwe++; r = 1; @@ -814,35 +815,35 @@ element(Juke *w, int e) s = scsiio(w->juke, SCSIread, cmd, sizeof cmd, buf, sizeof buf); /* read elem sts */ if(s) { - print("scsiio #%x\n", s); + fprint(2, "scsiio #%x\n", s); goto bad; } s = (buf[0]<<8) | buf[1]; if(s != e) { - print("element = %d\n", s); + fprint(2, "element = %d\n", s); goto bad; } if(buf[3] != 1) { - print("number reported = %d\n", buf[3]); + fprint(2, "number reported = %d\n", buf[3]); goto bad; } s = (buf[8+8+0]<<8) | buf[8+8+1]; if(s != e) { - print("element1 = %d\n", s); + fprint(2, "element1 = %d\n", s); goto bad; } switch(buf[8+0]) { /* element type */ default: - print("unknown element %d: %d\n", e, buf[8+0]); + fprint(2, "unknown element %d: %d\n", e, buf[8+0]); goto bad; case 1: /* transport */ s = e - w->mt0; if(s < 0 || s >= w->nmt) goto bad; if(buf[8+8+2] & 1) - print("transport %d full %d.%d\n", s, + fprint(2, "transport %d full %d.%d\n", s, (buf[8+8+10]<<8) | buf[8+8+11], (buf[8+8+9]>>6) & 1); break; @@ -860,25 +861,26 @@ element(Juke *w, int e) s = e - w->ie0; if(s < 0 || s >= w->nie) goto bad; - print("import/export %d #%.2x %d.%d\n", s, - buf[8+8+2], - (buf[8+8+10]<<8) | buf[8+8+11], - (buf[8+8+9]>>6) & 1); + if(chatty) + print("import/export %d #%.2x %d.%d\n", s, + buf[8+8+2], + (buf[8+8+10]<<8) | buf[8+8+11], + (buf[8+8+9]>>6) & 1); break; case 4: /* data transfer */ s = e - w->dt0; if(s < 0 || s >= w->ndt) goto bad; - print("data transfer %d #%.2x %d.%d\n", s, - buf[8+8+2], - (buf[8+8+10]<<8) | buf[8+8+11], - (buf[8+8+9]>>6) & 1); + if(chatty) + print("data transfer %d #%.2x %d.%d\n", s, + buf[8+8+2], + (buf[8+8+10]<<8) | buf[8+8+11], + (buf[8+8+9]>>6) & 1); if(buf[8+8+2] & 1) { t = ((buf[8+8+10]<<8) | buf[8+8+11]) - w->se0; if (t < 0 || t >= w->nse || t >= MAXSIDE || s >= MAXDRIVE) { - print( - "element: juke %Z lies; claims side %d is in drive %d\n", + fprint(2, "element: juke %Z lies; claims side %d is in drive %d\n", w->juke, t, s); /* lying sack of ... */ /* * at minimum, we've avoided corrupting our @@ -890,18 +892,18 @@ element(Juke *w, int e) */ goto bad; } - print("r%d in drive %d\n", t, s); - if(mmove(w, w->mt0, w->dt0+s, w->se0+t, - (buf[8+8+9]>>6) & 1)) { - print("mmove initial unload\n"); + if(chatty) + print("r%d in drive %d\n", t, s); + if(mmove(w, w->mt0, w->dt0+s, w->se0+t,(buf[8+8+9]>>6) & 1)){ + fprint(2, "mmove initial unload\n"); goto bad; } w->side[t].status = Sunload; if(w->rot) w->side[w->nse+t].status = Sunload; } - if(buf[8+8+2] & 4) { - print("drive w%d has exception #%.2x #%.2x\n", s, + if(buf[8+8+2] & 4){ + fprint(2, "drive w%d has exception #%.2x #%.2x\n", s, buf[8+8+4], buf[8+8+5]); goto bad; } @@ -956,7 +958,7 @@ jinit(Juke *w, Device *d, int o) switch(d->type) { default: - print("juke platter not (devmcat of) dev(l)worm: %Z\n", d); + fprint(2, "juke platter not (devmcat of) dev(l)worm: %Z\n", d); panic("jinit: type"); case Devmcat: @@ -977,7 +979,7 @@ jinit(Juke *w, Device *d, int o) /* FALL THROUGH */ case Devworm: if(d->private) { - print("juke platter private pointer set %p\n", + fprint(2, "juke platter private pointer set %p\n", d->private); panic("jinit: private"); } @@ -996,7 +998,7 @@ wormi(char *arg) i = number(arg, -1, 10) - 1; w = jukelist; if(i < 0 || i >= w->nside) { - print("bad unit number %s (%d)\n", arg, i+1); + fprint(2, "bad unit number %s (%d)\n", arg, i+1); return 0; } j = i; @@ -1045,7 +1047,7 @@ cmd_wormoffline(int argc, char *argv[]) u = number(argv[1], -1, 10); w = jukelist; if(u < 0 || u >= w->ndrive) { - print("bad drive %s (0<=%d<%d)\n", argv[1], u, w->ndrive); + fprint(2, "bad drive %s (0<=%d<%d)\n", argv[1], u, w->ndrive); return; } if(w->offline[u]) @@ -1154,7 +1156,7 @@ querychanger(Device *xdev) if (xdev == nil) panic("querychanger: nil Device"); if(xdev->type != Devwren) { - print("juke changer not wren %Z\n", xdev); + fprint(2, "juke changer not wren %Z\n", xdev); goto bad; } for(w=jukelist; w; w=w->link) @@ -1171,7 +1173,9 @@ querychanger(Device *xdev) w->link = jukelist; jukelist = w; - print("alloc juke %Z\n", xdev); + if(chatty) + print("alloc juke %Z\n", xdev); + qlock(w); qunlock(w); // w->name = "juke"; @@ -1190,7 +1194,7 @@ querychanger(Device *xdev) if(w->rot) w->nside += w->nside; if(w->nside > MAXSIDE) { - print("too many sides: %d max %d\n", w->nside, MAXSIDE); + fprint(2, "too many sides: %d max %d\n", w->nside, MAXSIDE); goto bad; } for(i=0; i < w->nse; i++) { @@ -1203,7 +1207,8 @@ querychanger(Device *xdev) w->ndrive = w->ndt; if(w->ndrive > MAXDRIVE) { - print("ndrives truncated to %d\n", MAXDRIVE); + if(chatty) + print("ndrives truncated to %d\n", MAXDRIVE); w->ndrive = MAXDRIVE; } @@ -1231,7 +1236,7 @@ jukeinit(Device *d) panic("jukeinit: nil Device"); xdev = d->j.j; if(xdev == nil || xdev->type != Devmcat) { - print("juke union not mcat\n"); + fprint(2, "juke union not mcat\n"); goto bad; } @@ -1260,24 +1265,24 @@ jukeinit(Device *d) i = 0; while(xdev = xdev->link) { if(xdev->type != Devwren) { - print("drive not devwren: %Z\n", xdev); + fprint(2, "drive not devwren: %Z\n", xdev); goto bad; } if(w->drive[i]->type != Devnone && xdev != w->drive[i]) { - print("double init drive %d %Z %Z\n", + fprint(2, "double init drive %d %Z %Z\n", i, w->drive[i], xdev); goto bad; } if(i >= w->ndrive) { - print("too many drives %Z\n", xdev); + fprint(2, "too many drives %Z\n", xdev); goto bad; } w->drive[i++] = xdev; } if(i <= 0) { - print("no drives\n"); + fprint(2, "no drives\n"); goto bad; } @@ -1314,8 +1319,9 @@ wormprobe(void) continue; if(v->status == Sstart && t > v->time) { drive = v->drive; - print("\ttime r%ld drive %Z\n", - v-w->side, w->drive[drive]); + if(chatty) + print("\ttime r%ld drive %Z\n", + v-w->side, w->drive[drive]); mmove(w, w->mt0, w->dt0+drive, v->elem, v->rot); v->status = Sunload; } diff --git a/sys/src/cmd/cwfs/main.c b/sys/src/cmd/cwfs/main.c index e9037a671..c6a07cb35 100644 --- a/sys/src/cmd/cwfs/main.c +++ b/sys/src/cmd/cwfs/main.c @@ -9,6 +9,7 @@ Map *devmap; int sfd, rfd; Biobuf bin; +int chatty = 0; void machinit(void) @@ -59,7 +60,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 +93,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 +110,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. @@ -291,7 +292,7 @@ main(int argc, char **argv) rfork(RFNOTEG); formatinit(); machinit(); - conf.confdev = "/dev/sdC0/cwfs"; + conf.confdev = "/dev/sdC0/fscache"; rfd = sfd = -1; @@ -330,6 +331,9 @@ main(int argc, char **argv) case 'm': /* name device-map file */ conf.devmap = EARGF(usage()); break; + case 'd': + chatty++; + break; default: usage(); break; @@ -341,9 +345,11 @@ 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); @@ -364,15 +370,12 @@ main(int argc, char **argv) uid = malloc(conf.nuid * sizeof(*uid)); gidspace = malloc(conf.gidspace * sizeof(*gidspace)); - print("iobufinit\n"); iobufinit(); arginit(); boottime = time(nil); - print("sysinit\n"); sysinit(); - srvinit(); /* @@ -509,11 +512,9 @@ serve(void *) cp->protocol = fsprotocol[i]; break; } - if(cp->protocol == nil){ + if(cp->protocol == nil && (chatty > 1)){ print("no protocol for message\n"); - for(i = 0; i < 12; i++) - print(" %2.2uX", mb->data[i]); - print("\n"); + hexdump(mb->data, 12); } } else /* process the request, generate an answer and reply */ @@ -551,7 +552,7 @@ nextdump(Timet t) { Timet nddate = nextime(t+MINUTE(100), DUMPTIME, WEEKMASK); - if(!conf.nodump) + if(!conf.nodump && chatty) print("next dump at %T\n", nddate); return nddate; } @@ -578,10 +579,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; } diff --git a/sys/src/cmd/cwfs/malloc.c b/sys/src/cmd/cwfs/malloc.c index b7014f770..369ae4ab5 100644 --- a/sys/src/cmd/cwfs/malloc.c +++ b/sys/src/cmd/cwfs/malloc.c @@ -57,7 +57,9 @@ iobufinit(void) wlock(&mainlock); /* init */ wunlock(&mainlock); - prbanks(); + if(chatty) + prbanks(); + m = 0; for(mbp = mconf.bank; mbp < &mconf.bank[mconf.nbank]; mbp++) m += mbp->limit - mbp->base; @@ -66,7 +68,8 @@ iobufinit(void) nhiob = niob / HWIDTH; while(!prime(nhiob)) nhiob++; - print("\t%ld buffers; %ld hashes\n", niob, nhiob); + if(chatty) + print("\t%ld buffers; %ld hashes\n", niob, nhiob); hiob = ialloc(nhiob * sizeof(Hiob), 0); hp = hiob; for(i=0; i<nhiob; i++) { @@ -78,7 +81,6 @@ iobufinit(void) xiop = ialloc(niob * RBUFSIZE, 0); hp = hiob; for(i=0; i < niob; i++) { -// p->name = "buf"; qlock(p); qunlock(p); if(hp == hiob) @@ -97,7 +99,6 @@ iobufinit(void) } p->dev = devnone; p->addr = -1; -// p->xiobuf = ialloc(RBUFSIZE, RBUFSIZE); p->xiobuf = xiop; p->iobuf = (char*)-1; p++; @@ -112,7 +113,8 @@ iobufinit(void) i = 0; for(mbp = mconf.bank; mbp < &mconf.bank[mconf.nbank]; mbp++) i += mbp->limit - mbp->base; - print("\tmem left = %,d, out of %,ld\n", i, conf.mem); + if(chatty) + print("\tmem left = %,d, out of %,ld\n", i, conf.mem); /* paranoia: add this command as late as is easy */ cmd_install("memory", "-- print ranges of memory banks", cmd_memory); } diff --git a/sys/src/cmd/cwfs/portdat.h b/sys/src/cmd/cwfs/portdat.h index 901e8abca..820cb99a2 100644 --- a/sys/src/cmd/cwfs/portdat.h +++ b/sys/src/cmd/cwfs/portdat.h @@ -768,3 +768,4 @@ extern char *annstrs[]; extern Biobuf bin; extern Map *devmap; extern int (*fsprotocol[])(Msgbuf*); +extern int chatty; diff --git a/sys/src/cmd/cwfs/srv.c b/sys/src/cmd/cwfs/srv.c index 0cfafbb41..52d32ffa5 100644 --- a/sys/src/cmd/cwfs/srv.c +++ b/sys/src/cmd/cwfs/srv.c @@ -52,7 +52,8 @@ srvput(Srv *srv) if(decref(srv)) return; - print("%s closed\n", srv->name); + if(chatty) + print("%s closed\n", srv->name); chanhangup(srv->chan, "", 0); memset(srv->buf, 0, sizeof(srv->buf)); @@ -70,8 +71,6 @@ srvo(void *) Msgbuf *mb; char buf[ERRMAX]; - print("srvo\n"); - for(;;){ mb = fs_recv(srvoq, 0); if(mb == nil) @@ -87,7 +86,7 @@ srvo(void *) if(strstr(buf, "interrupt")) continue; - if(buf[0]) + if(buf[0] && chatty) print("srvo %s: %s\n", srv->name, buf); chanhangup(srv->chan, buf, 0); break; @@ -106,8 +105,6 @@ srvi(void *aux) int n, m; char buf[ERRMAX]; - print("srvi %s\n", srv->name); - if((mb = mballoc(IOHDRSZ+Maxfdata, srv->chan, Mbeth1)) == nil) panic("srvi %s: mballoc failed", srv->name); b = mb->data; @@ -154,7 +151,7 @@ Error: if(strstr(buf, "interrupt")) goto Read; - if(buf[0]) + if(buf[0] && chatty) print("srvi %s: %s\n", srv->name, buf); chanhangup(srv->chan, buf, 0); srvput(srv); diff --git a/sys/src/cmd/cwfs/sub.c b/sys/src/cmd/cwfs/sub.c index bca9e5264..619c7d22d 100644 --- a/sys/src/cmd/cwfs/sub.c +++ b/sys/src/cmd/cwfs/sub.c @@ -187,7 +187,7 @@ newfp(void) return f; } while(i != start); - print("out of files\n"); + fprint(2, "out of files\n"); return 0; } @@ -328,7 +328,7 @@ newwp(void) if(w >= ew) w = &wpaths[0]; if(w == sw) { - print("out of wpaths\n"); + fprint(2, "out of wpaths\n"); return 0; } if(w->refs) @@ -466,7 +466,7 @@ bufalloc(Device *dev, int tag, long qid, int uid) p = getbuf(dev, superaddr(dev), Brd|Bmod); if(!p || checktag(p, Tsuper, QPSUPER)) { - print("bufalloc: super block\n"); + fprint(2, "bufalloc: super block\n"); if(p) putbuf(p); return 0; @@ -477,7 +477,7 @@ loop: n = --sb->fbuf.nfree; sb->tfree--; if(n < 0 || n >= FEPERBUF) { - print("bufalloc: %Z: bad freelist\n", dev); + fprint(2, "bufalloc: %Z: bad freelist\n", dev); n = 0; sb->fbuf.free[0] = 0; } @@ -495,7 +495,7 @@ loop: goto loop; } putbuf(p); - print("fs %Z full uid=%d\n", dev, uid); + fprint(2, "fs %Z full uid=%d\n", dev, uid); return 0; } bp = getbuf(dev, a, Brd); @@ -955,7 +955,7 @@ fs_send(Queue *q, void *a) sleep(1000); if(!q->waitedfor) { /* likely a bug; don't wait forever */ - print("no readers yet for %s q\n", q->name); + fprint(2, "no readers yet for %s q\n", q->name); abort(); } } @@ -1029,7 +1029,7 @@ devread(Device *d, Off b, void *c) return e; case Devnone: - print("read from device none(%lld)\n", (Wideoff)b); + fprint(2, "read from device none(%lld)\n", (Wideoff)b); return 1; default: panic("illegal device in devread: %Z %lld", @@ -1059,7 +1059,7 @@ devwrite(Device *d, Off b, void *c) break; case Devro: - print("write to ro device %Z(%lld)\n", d, (Wideoff)b); + fprint(2, "write to ro device %Z(%lld)\n", d, (Wideoff)b); return 1; case Devwren: @@ -1206,10 +1206,11 @@ devream(Device *d, int top) Device *l; loop: - print("\tdevream: %Z %d\n", d, top); + if(chatty) + print("\tdevream %Z %d\n", d, top); switch(d->type) { default: - print("ream: unknown dev type %Z\n", d); + fprint(2, "devream: unknown dev type %Z\n", d); return; case Devcw: @@ -1262,10 +1263,11 @@ void devrecover(Device *d) { for (;;) { - print("recover: %Z\n", d); + if(chatty) + print("recover %Z\n", d); switch(d->type) { default: - print("recover: unknown dev type %Z\n", d); + fprint(2, "devrecover: unknown dev type %Z\n", d); return; case Devcw: @@ -1288,10 +1290,11 @@ devinit(Device *d) if(d->init) return; d->init = 1; - print("\tdevinit %Z\n", d); + if(chatty) + print("\tdevinit %Z\n", d); switch(d->type) { default: - print("devinit unknown device %Z\n", d); + fprint(2, "devinit: unknown device %Z\n", d); return; case Devro: @@ -1339,7 +1342,6 @@ devinit(Device *d) break; case Devnone: - print("devinit of Devnone\n"); return; } } @@ -1429,18 +1431,9 @@ swab(void *c, int flag) /* swab each block type */ switch(t->tag) { - default: - print("no swab for tag=%G rw=%d\n", t->tag, flag); - for(j=0; j<16; j++) - print(" %.2x", p[BUFSIZE+j]); - print("\n"); - for(i=0; i<16; i++) { - print("%.4x", i*16); - for(j=0; j<16; j++) - print(" %.2x", p[i*16+j]); - print("\n"); - } + fprint(2, "no swab for tag=%G rw=%d\n", t->tag, flag); + hexdump(p, 256); panic("swab"); break; diff --git a/sys/src/cmd/cwfs/wren.c b/sys/src/cmd/cwfs/wren.c index 9b8f09c8b..65338af8e 100644 --- a/sys/src/cmd/cwfs/wren.c +++ b/sys/src/cmd/cwfs/wren.c @@ -14,8 +14,6 @@ struct Wren Devsize nblock; /* number of blocks -- from config */ long mult; /* multiplier to get physical blocks */ Devsize max; /* number of logical blocks */ - -// char *sddir; /* /dev/sdXX name */ }; char * @@ -57,8 +55,9 @@ wreninit(Device *d) dr->block = inqsize(d->wren.sddata); if(dr->block <= 0 || dr->block >= 16*1024) { - print("\twreninit %Z block size %ld, setting to %d\n", - d, dr->block, Sectorsz); + if(chatty) + print("\twreninit %Z block size %ld, setting to %d\n", + d, dr->block, Sectorsz); dr->block = Sectorsz; } @@ -68,10 +67,12 @@ wreninit(Device *d) dr->mult = (RBUFSIZE + dr->block - 1) / dr->block; dr->max = (dr->nblock + 1) / dr->mult; - print("\tdisk drive %Z: %,lld %ld-byte sectors, ", - d, (Wideoff)dr->nblock, dr->block); - print("%,lld %d-byte blocks\n", (Wideoff)dr->max, RBUFSIZE); - print("\t\t%ld multiplier\n", dr->mult); + if(chatty){ + print("\tdisk drive %Z: %,lld %ld-byte sectors, ", + d, (Wideoff)dr->nblock, dr->block); + print("%,lld %d-byte blocks\n", (Wideoff)dr->max, RBUFSIZE); + print("\t\t%ld multiplier\n", dr->mult); + } } Devsize @@ -89,10 +90,10 @@ wrenread(Device *d, Off b, void *c) if (dr == nil) panic("wrenread: no drive (%Z) block %lld", d, (Wideoff)b); if(b >= dr->max) { - print("wrenread: block out of range %Z(%lld)\n", d, (Wideoff)b); + fprint(2, "wrenread: block out of range %Z(%lld)\n", d, (Wideoff)b); r = 0x040; } else if (pread(d->wren.fd, c, RBUFSIZE, (vlong)b*RBUFSIZE) != RBUFSIZE) { - print("wrenread: error on %Z(%lld): %r\n", d, (Wideoff)b); + fprint(2, "wrenread: error on %Z(%lld): %r\n", d, (Wideoff)b); cons.nwrenre++; r = 1; } @@ -108,11 +109,11 @@ wrenwrite(Device *d, Off b, void *c) if (dr == nil) panic("wrenwrite: no drive (%Z) block %lld", d, (Wideoff)b); if(b >= dr->max) { - print("wrenwrite: block out of range %Z(%lld)\n", + fprint(2, "wrenwrite: block out of range %Z(%lld)\n", d, (Wideoff)b); r = 0x040; } else if (pwrite(d->wren.fd, c, RBUFSIZE, (vlong)b*RBUFSIZE) != RBUFSIZE) { - print("wrenwrite: error on %Z(%lld): %r\n", d, (Wideoff)b); + fprint(2, "wrenwrite: error on %Z(%lld): %r\n", d, (Wideoff)b); cons.nwrenwe++; r = 1; } |