libventi: minor vtfile bug fixes
diff --git a/src/libventi/file.c b/src/libventi/file.c
index 29b414f..b6887de 100644
--- a/src/libventi/file.c
+++ b/src/libventi/file.c
@@ -607,7 +607,7 @@
 
 	rb = vtcacheglobal(r->c, e->score, e->type);
 	if(rb == nil)
-		return 0;
+		return -1;
 
 	/*
 	 * Walk down to the new root block.
@@ -748,6 +748,12 @@
 	if(b == nil)
 		return -1;
 
+	if(DEPTH(e.type) == 0){
+		memmove(score, e.score, VtScoreSize);
+		vtblockput(b);
+		return 0;
+	}
+
 	i = mkindices(&e, bn, index);
 	if(i < 0){
 		vtblockput(b);
@@ -1058,6 +1064,8 @@
 		return -1;
 
 	memmove(b->data+frag, data, count);
+	if(m == VtOWRITE && frag+count < e.dsize)
+		memset(b->data+frag+count, 0, e.dsize-frag-count);
 
 	if(offset+count > e.size){
 		vtfilegetentry(f, &e);
@@ -1118,9 +1126,12 @@
 		for(i=0; i<epb; i++){
 			if(vtentryunpack(&e, b->data, i) < 0)
 				goto Err;
+			if(!(e.flags&VtEntryActive))
+				continue;
 			if(flushblock(c, nil, e.score, e.psize/VtScoreSize, e.dsize/VtEntrySize,
 				e.type) < 0)
 				goto Err;
+			vtentrypack(&e, b->data, i);
 		}
 		break;