shithub: riscv

Download patch

ref: f2c70fe2f708446794af299b1130b7aaf8dc73e5
parent: 34bf0ce496a36746a4f6746f8a187dd66fe7a136
author: aiju <[email protected]>
date: Tue Aug 7 20:52:37 EDT 2012

more hjfs fixes

--- a/sys/src/cmd/hjfs/cons.c
+++ b/sys/src/cmd/hjfs/cons.c
@@ -21,8 +21,7 @@
 walkpath(Chan *ch, char *path, char **cr)
 {
 	char buf[NAMELEN], *p, *fp;
-	
-	buf[NAMELEN - 1] = 0;
+
 	fp = path;
 	if(*path != '/'){
 	noent:
@@ -51,6 +50,7 @@
 			break;
 		if(p - path >= NAMELEN)
 			goto noent;
+		memset(buf, 0, sizeof buf);
 		memcpy(buf, path, p - path);
 		if(chanwalk(ch, buf) <= 0){
 			werrstr("%s: %r", fp);
--- a/sys/src/cmd/hjfs/dump.c
+++ b/sys/src/cmd/hjfs/dump.c
@@ -115,6 +115,8 @@
 		runlock(fs);
 		wlock(fs);
 	}
+	if(l->next != nil && willmodify(fs, l->next, 1) < 0)
+		goto err;
 	rc = chref(fs, l->blk, 0);
 	if(rc < 0)
 		goto err;
@@ -125,8 +127,7 @@
 	}
 	if(rc == 1)
 		goto done;
-	if(willmodify(fs, l->next, 1) < 0)
-		goto err;
+
 	p = getbuf(fs->d, l->next->blk, TDENTRY, 0);
 	if(p == nil)
 		goto err;
--- a/sys/src/cmd/hjfs/fs1.c
+++ b/sys/src/cmd/hjfs/fs1.c
@@ -387,7 +387,10 @@
 	Buf *b;
 
 	qlock(&fs->loctree);
+	if(!loop && --l->ref <= 0)
+		goto freeit;
 	while(loop && l != nil && l->ref <= 1){
+freeit:
 		if((l->flags & LGONE) != 0){
 			b = getbuf(fs->d, l->blk, TDENTRY, 0);
 			if(b != nil){
@@ -558,12 +561,14 @@
 				return -1;
 			memset(b->offs, 0, sizeof(b->offs));
 		}else{
-			if(mode != GBREAD && chref(fs, *loc, 0) > 1)
+			if(mode != GBREAD && chref(fs, *loc, 0) > 1){
 				if(dumpblk(fs, L, loc) < 0){
 					if(b != bd)
 						putbuf(b);
 					return -1;
 				}
+				b->op |= BDELWRI;
+			}
 			k = *loc;
 			if(b != bd)
 				putbuf(b);