code: mafs

Download patch

ref: a566629485f872d51d4d5661d8b4aa32bd45f3e2
parent: 7754c42469ca6f6dff350f2d87e0903a5ce61c00
author: 9ferno <gophone2015@gmail.com>
date: Sun Oct 16 23:42:23 EDT 2022

do not write to new blocks if the number of blocks has not changed

--- a/9p.c
+++ b/9p.c
@@ -449,17 +449,6 @@
 	Fid *fid;
 	Spanid s;
 
-/*	if(chatty9p > 1)
-		dprint("< %ld mafscreate c->path %s req->ifcall.name %s\n"
-				"	c->mode 0x%ux mode 0x%ux perm 0x%lux\n"
-				"	c->qid.path 0x%zux c->qid.vers %lud c->qid.type %ud 0x%ux\n"
-				"	c->aux 0x%p t->idx %d dblkno %llud\n",
-				time(nil),
-				chanpath(c), req->ifcall.name, c->mode, omode, perm,
-				c->qid.path,
-				c->qid.vers, c->qid.type, c->qid.type,
-				c->aux, aux->t->idx, aux->dblkno);*/
-
 	/* no create's when shutting down */
 	if(shuttingdown){
 		respond(req, errstring[Eshutdown]);
@@ -613,12 +602,6 @@
 				return;
 			}
 			putbuf(dbuf);
-			/* DBG("> mafscreate c->path %s mode 0x%ux omode0 0x%ux\n"
-				"	c->qid.path 0x%zux c->qid.vers %lud c->qid.type %d 0x%ux\n"
-				"	c->aux 0x%p\n",
-				chanpath(c), c->mode, omode, c->qid.path,
-				c->qid.vers, c->qid.type, c->qid.type,
-				c->aux); */
 			respond(req, nil);
 			return;
 		}else{
@@ -1288,12 +1271,12 @@
 		}
 		return howmuch;
 	}else{
-		/* last extent is partially full */
+		/* last Span is partially full */
 		/*
-		get the old extent and the new extent
-		copy from the old extent to the new
-		addrelative the new extent
-		free the old extent */
+		get the old Span and the new Span
+		copy from the old Span to the new
+		addrelative the new Span
+		free the old Span */
 
 		rel2abs(d, d->size/Maxspansize, &s);
 		blkno = s.blkno;
@@ -1318,6 +1301,18 @@
 			if((lastspansize+wbufsize+sizeof(Tag))%Rawblocksize > 0)
 				newnblocks++;
 		}
+
+		/* Filling up the old Span. No new blocks are added. */
+		if(oldnblocks == newnblocks){
+			howmuch = min(Maxspansize-lastspansize, wbufsize);
+			if(chatty9p > 1)
+			dprint("fill lastspansize %llud nblocks %llud howmuch %llud\n",
+					lastspansize, newnblocks, howmuch);
+			memcpy(buf->io->buf+lastspansize, wbuf, howmuch);
+			putbuf(buf);
+			return howmuch;
+		}
+
 		nbuf = allocblocks(newnblocks, Tdata, d->qid.path);
 		if(nbuf == nil){
 			putbuf(buf);