shithub: riscv

Download patch

ref: 3103efb8b06503825f3d14c5c5758a431794e4b3
parent: 2e64925b91b4fc19d770dc685c3182121ce6e551
author: spew <devnull@localhost>
date: Mon Mar 27 17:38:12 EDT 2017

hjfs: simplify dprinting

--- a/sys/src/cmd/hjfs/auth.c
+++ b/sys/src/cmd/hjfs/auth.c
@@ -455,7 +455,7 @@
 		}
 		continue;
 	erropt:
-		dprint("hjfs: newuser: ignoring erroneous option %s\n", argv[i]);
+		dprint("newuser: ignoring erroneous option %s\n", argv[i]);
 	}
 	if(resort)
 		qsort(fs->udata, fs->nudata, sizeof(User), usercomp);
--- a/sys/src/cmd/hjfs/buf.c
+++ b/sys/src/cmd/hjfs/buf.c
@@ -274,7 +274,7 @@
 	if(nodata)
 		b->type = type;
 	if(b->type != type && type != -1){
-		dprint("hjfs: type mismatch, dev %s, block %lld, got %T, want %T, caller %#p\n",
+		dprint("type mismatch, dev %s, block %lld, got %T, want %T, caller %#p\n",
 			d->name, off, b->type, type, getcallerpc(&d));
 		werrstr("phase error -- type mismatch");
 		putbuf(b);
--- a/sys/src/cmd/hjfs/cons.c
+++ b/sys/src/cmd/hjfs/cons.c
@@ -67,7 +67,7 @@
 cmdsync(int, char **)
 {
 	sync(1);
-	dprint("hjfs: sync\n");
+	dprint("sync\n");
 	return 0;
 }
 
@@ -82,7 +82,7 @@
 cmddump(int, char **)
 {
 	fsdump(fsmain);
-	dprint("hjfs: dumped\n");
+	dprint("dumped\n");
 	return 0;
 }
 
@@ -90,7 +90,7 @@
 cmdallow(int, char **)
 {
 	fsmain->flags |= FSNOPERM | FSCHOWN;
-	dprint("hjfs: allow\n");
+	dprint("allow\n");
 	return 0;
 }
 
@@ -123,15 +123,15 @@
 
 	for(i = 0; i < d->size; i++){
 		if(getblk(fsmain, l, b, i, &r, GBREAD) <= 0){
-			dprint("hjfs: %s in block %ulld at index %d has a bad block at index %ulld: %r\n", ftype, l->blk, l->deind, i);
+			dprint("%s in block %ulld at index %d has a bad block at index %ulld: %r\n", ftype, l->blk, l->deind, i);
 			continue;
 		}
 		c = getbuf(fsmain->d, r, btype, 0);
 		if(c == nil)
-			dprint("hjfs: %s in block %ulld at index %d has a bad block %ulld at directory index %ulld: %r\n", ftype, l->blk, l->deind, r, i);
+			dprint("%s in block %ulld at index %d has a bad block %ulld at directory index %ulld: %r\n", ftype, l->blk, l->deind, r, i);
 		putbuf(c);
 		if(chref(fsmain, r, 0) == 0)
-			dprint("hjfs: %s in block %ulld at index %d has a block %ulld at index %ulld whose reference count is 0", ftype, l->blk, l->deind, r, i);
+			dprint("%s in block %ulld at index %d has a block %ulld at index %ulld whose reference count is 0", ftype, l->blk, l->deind, r, i);
 	}
 }
 
@@ -148,7 +148,7 @@
 		return -1;
 	switch(type = b->type){
 	case TSUPERBLOCK:
-		dprint("hjfs: checkblk: should not have found superblock at %ulld\n", blk);
+		dprint("checkblk: should not have found superblock at %ulld\n", blk);
 		break;
 	case TDENTRY:
 		l.blk = blk;
@@ -214,11 +214,11 @@
 		putbuf(b);
 	}
 	wunlock(fsmain);
-	dprint("hjfs: %T block count %ulld\n", TDENTRY, ndentry);
-	dprint("hjfs: %T block count %ulld\n", TINDIR, nindir);
-	dprint("hjfs: %T block count %ulld\n", TRAW, nraw);
-	dprint("hjfs: %T block count %ulld\n", TREF, nref);
-	dprint("hjfs: %T block count %ulld\n", TSUPERBLOCK, nsuperblock);
+	dprint("%T block count %ulld\n", TDENTRY, ndentry);
+	dprint("%T block count %ulld\n", TINDIR, nindir);
+	dprint("%T block count %ulld\n", TRAW, nraw);
+	dprint("%T block count %ulld\n", TREF, nref);
+	dprint("%T block count %ulld\n", TSUPERBLOCK, nsuperblock);
 	return 1;
 }
 
@@ -226,7 +226,7 @@
 cmddisallow(int, char **)
 {
 	fsmain->flags &= ~(FSNOPERM | FSCHOWN);
-	dprint("hjfs: disallow\n");
+	dprint("disallow\n");
 	return 0;
 }
 
@@ -235,9 +235,9 @@
 {
 	fsmain->flags ^= FSNOAUTH;
 	if((fsmain->flags & FSNOAUTH) == 0)
-		dprint("hjfs: auth enabled\n");
+		dprint("auth enabled\n");
 	else
-		dprint("hjfs: auth disabled\n");
+		dprint("auth disabled\n");
 	return 1;
 }
 
@@ -317,8 +317,8 @@
 				n++;
 		putbuf(b);
 	}
-	dprint("hjfs: (blocks) free %ulld, used %ulld, total %ulld\n", n, sb->sb.size - n, sb->sb.size);
-	dprint("hjfs: (MB) free %ulld, used %ulld, total %ulld\n", n * BLOCK / 1048576, (sb->sb.size - n) * BLOCK / 1048576, sb->sb.size * BLOCK / 1048576);
+	dprint("(blocks) free %ulld, used %ulld, total %ulld\n", n, sb->sb.size - n, sb->sb.size);
+	dprint("(MB) free %ulld, used %ulld, total %ulld\n", n * BLOCK / 1048576, (sb->sb.size - n) * BLOCK / 1048576, sb->sb.size * BLOCK / 1048576);
 	putbuf(sb);
 	wunlock(fsmain);
 	return 1;
@@ -338,7 +338,7 @@
 	if(walkpath(ch, argv[1], nil) < 0)
 		goto error;
 	rlock(fsmain);
-	dprint("hjfs: loc %ulld / %uld, offset %ulld\n", ch->loc->blk, ch->loc->deind, BLOCK * ch->loc->blk + (RBLOCK - BLOCK) + DENTRYSIZ * ch->loc->deind);
+	dprint("loc %ulld / %uld, offset %ulld\n", ch->loc->blk, ch->loc->deind, BLOCK * ch->loc->blk + (RBLOCK - BLOCK) + DENTRYSIZ * ch->loc->deind);
 	b = getbuf(fsmain->d, ch->loc->blk, TDENTRY, 0);
 	if(b == nil){
 		runlock(fsmain);
@@ -345,11 +345,11 @@
 		goto error;
 	}
 	d = &b->de[ch->loc->deind];
-	dprint("hjfs: name %s\n", d->name);
-	dprint("hjfs: uid %d, muid %d, gid %d\n", d->uid, d->muid, d->gid);
-	dprint("hjfs: mode %#o, qid %ulld, type %#x, version %d\n", d->mode, d->path, d->type, d->vers);
-	dprint("hjfs: size %d\n", d->size);
-	dprint("hjfs: atime %ulld, mtime %ulld\n", d->atime, d->mtime);
+	dprint("name %s\n", d->name);
+	dprint("uid %d, muid %d, gid %d\n", d->uid, d->muid, d->gid);
+	dprint("mode %#o, qid %ulld, type %#x, version %d\n", d->mode, d->path, d->type, d->vers);
+	dprint("size %d\n", d->size);
+	dprint("atime %ulld, mtime %ulld\n", d->atime, d->mtime);
 	putbuf(b);
 	runlock(fsmain);
 	chanclunk(ch);
@@ -384,7 +384,7 @@
 		goto error;
 	}
 	c = (uchar *) &b->de[ch->loc->deind];
-	dprint("hjfs: loc %d, old value %#.2x, new value %#.2x\n", loc, c[loc], new);
+	dprint("loc %d, old value %#.2x, new value %#.2x\n", loc, c[loc], new);
 	c[loc] = new;
 	b->op |= BDELWRI;
 	putbuf(b);
@@ -426,11 +426,11 @@
 	for(i = start; i <= end; i++){
 		rc = getblk(fsmain, ch->loc, b, i, &r, GBREAD);
 		if(rc > 0)
-			dprint("hjfs: getblk %ulld = %ulld\n", i, r);
+			dprint("getblk %ulld = %ulld\n", i, r);
 		if(rc == 0)
-			dprint("hjfs: getblk %ulld not found\n", i);
+			dprint("getblk %ulld not found\n", i);
 		if(rc < 0)
-			dprint("hjfs: getblk %ulld: %r\n", i);
+			dprint("getblk %ulld: %r\n", i);
 	}
 	putbuf(b);
 	runlock(fsmain);
@@ -484,7 +484,7 @@
 		if(s == nil)
 			continue;
 		if(echo)
-			dprint("hjfs: >%s\n", s);
+			dprint(">%s\n", s);
 		rc = tokenize(s, args, MAXARGS);
 		if(rc == 0)
 			goto syntax;
@@ -497,12 +497,12 @@
 					if(rc == -9001)
 						goto syntax;
 					if(rc < 0)
-						dprint("hjfs: %r\n");
+						dprint("%r\n");
 					goto done;
 				}
 			}
 	syntax:
-		dprint("hjfs: syntax error\n");
+		dprint("syntax error\n");
 	done:
 		free(s);
 	}
--- a/sys/src/cmd/hjfs/dev.c
+++ b/sys/src/cmd/hjfs/dev.c
@@ -35,7 +35,7 @@
 			memset(buf, 0, sizeof(buf));
 			pack(b, buf);
 			if(pwrite(d->fd, buf, BLOCK, b->off*BLOCK) < BLOCK){
-				dprint("hjfs: write: %r\n");
+				dprint("write: %r\n");
 				b->error = Eio;
 			}
 		}else{
@@ -44,7 +44,7 @@
 			for(n = 0; n < BLOCK; n += m){
 				m = pread(d->fd, buf+n, BLOCK-n, b->off*BLOCK+n);
 				if(m < 0)
-					dprint("hjfs: read: %r\n");
+					dprint("read: %r\n");
 				if(m <= 0)
 					break;
 			}
--- a/sys/src/cmd/hjfs/dump.c
+++ b/sys/src/cmd/hjfs/dump.c
@@ -134,7 +134,7 @@
 	if(rc < 0)
 		goto err;
 	if(rc == 0){
-		dprint("hjfs: willmodify: block %lld has refcount 0\n", l->blk);
+		dprint("willmodify: block %lld has refcount 0\n", l->blk);
 		werrstr("phase error -- willmodify");
 		goto err;
 	}
--- a/sys/src/cmd/hjfs/fs1.c
+++ b/sys/src/cmd/hjfs/fs1.c
@@ -50,13 +50,13 @@
 
 	d = &b->de[l->deind];
 	if((d->mode & (DGONE | DALLOC)) == 0){
-		dprint("hjfs: getdent: file gone, d=%llux, l=%llud/%d %llux, callerpc %#p\n",
+		dprint("getdent: file gone, d=%llux, l=%llud/%d %llux, callerpc %#p\n",
 			d->path, l->blk, l->deind, l->path, getcallerpc(&l));
 		werrstr("phase error -- directory entry for nonexistent file");
 		return nil;
 	}
 	if(qidcmp(d, l) != 0){
-		dprint("hjfs: getdent: wrong qid d=%llux != l=%llud/%d %llux, callerpc %#p\n",
+		dprint("getdent: wrong qid d=%llux != l=%llud/%d %llux, callerpc %#p\n",
 			d->path, l->blk, l->deind, l->path, getcallerpc(&l));
 		werrstr("phase error -- qid mismatch");
 		return nil;
@@ -213,7 +213,7 @@
 error:
 	if(ch != nil)
 		chanclunk(ch);
-	dprint("hjfs: writeusers: %r\n");
+	dprint("writeusers: %r\n");
 }
 
 void
@@ -238,7 +238,7 @@
 err:
 	if(ch != nil)
 		chanclunk(ch);
-	dprint("hjfs: readusers: %r\nhjfs: using default user db\n");
+	dprint("readusers: %r\nhjfs: using default user db\n");
 }
 
 void
@@ -250,7 +250,7 @@
 	int j, je;
 	
 	d = fs->d;
-	dprint("hjfs: reaming %s\n", d->name);
+	dprint("reaming %s\n", d->name);
 	b = getbuf(d, SUPERBLK, TSUPERBLOCK, 1);
 	if(b == nil)
 	err:
@@ -292,7 +292,7 @@
 	putbuf(b);
 	createroot(fs);
 	sync(1);
-	dprint("hjfs: ream successful\n");
+	dprint("ream successful\n");
 }
 
 Fs *
@@ -326,7 +326,7 @@
 	if(doream)
 		writeusers(fs);
 	readusers(fs);
-	dprint("hjfs: fs is %s\n", d->name);
+	dprint("fs is %s\n", d->name);
 	return fs;
 
 error:
@@ -569,7 +569,7 @@
 	b = bd;
 	d = getdent(L, b);
 	if(d == nil){
-		dprint("hjfs: getblk: dirent gone\n");
+		dprint("getblk: dirent gone\n");
 		return -1;
 	}
 	if(blk < NDIRECT){
@@ -654,7 +654,7 @@
 		if(rc < 0)
 			goto end;
 		if(rc == 0){
-			dprint("hjfs: getblk: block %lld has refcount 0\n");
+			dprint("getblk: block %lld has refcount 0\n");
 			werrstr("phase error -- getblk");
 			rc = -1;
 			goto end;
--- a/sys/src/cmd/hjfs/main.c
+++ b/sys/src/cmd/hjfs/main.c
@@ -65,12 +65,17 @@
 int
 dprint(char *fmt, ...)
 {
+	static char buf[2048];
+	static QLock lk;
 	va_list va;
 	int rc;
-	
+
+	qlock(lk);
 	va_start(va, fmt);
-	rc = vfprint(2, fmt, va);
+	snprint(buf, 2048, "hjfs: %s", fmt);
+	rc = vfprint(2, buf, va);
 	va_end(va);
+	qunlock(lk);
 	return rc;
 }
 
@@ -149,7 +154,7 @@
 {
 	wlock(fsmain);
 	sync(1);
-	dprint("hjfs: ending\n");
+	dprint("ending\n");
 	sleep(1000);
 	sync(1);
 	threadexitsall(nil);