shithub: gefs

Download patch

ref: d40d407c6cbecf226a9ec24d316520e506659730
parent: 9d407ffc62b4ffd70eb89f26f0c9f88155d090bb
author: Michael Forney <mforney@mforney.org>
date: Thu Feb 3 05:54:13 EST 2022

fs: zero new data block outside write range

Otherwise, we write garbage to the parts of the file not explicitly
written.

--- a/fs.c
+++ b/fs.c
@@ -301,6 +301,7 @@
 	b = newblk(Traw);
 	if(b == nil)
 		return -1;
+	t = nil;
 	if(fb < sz && (fo != 0 || n != Blksz)){
 		if(lookup(f, m, &kv, buf, sizeof(buf), 0) != nil)
 			return -1;
@@ -314,6 +315,12 @@
 	if(fo+n > Blksz)
 		n = Blksz-fo;
 	memcpy(b->buf+fo, s, n);
+	if(t == nil){
+		if(fo > 0)
+			memset(b->buf, 0, fo);
+		if(fo+n < Blksz)
+			memset(b->buf+fo+n, 0, Blksz-fo-n);
+	}
 	enqueue(b);
 
 	packbp(m->v, m->nv, &b->bp);