shithub: gefs

Download patch

ref: 307645129bd818a9b9b731ef9c5c0c43a3fdaeb3
parent: 9e59da5b58cd2a31589ca738cb301ef7fad89937
author: Ori Bernstein <[email protected]>
date: Tue Apr 18 19:42:59 EDT 2023

fs: correct large writes with large iounit

--- a/fs.c
+++ b/fs.c
@@ -174,7 +174,7 @@
 respond(Fmsg *m, Fcall *r)
 {
 	Fcall rf;
-	uchar buf[Max9p];
+	uchar buf[Max9p+IOHDRSZ];
 	int w, n;
 
 	r->tag = m->tag;
@@ -654,7 +654,7 @@
 	if(p != nil)
 		*p = '\0';
 	r.type = Rversion;
-	r.msize = Max9p;
+	r.msize = Max9p + IOHDRSZ;
 	if(strcmp(m->version, "9P2000") == 0){
 		if(m->msize < r.msize)
 			r.msize = m->msize;
@@ -1869,12 +1869,12 @@
 static void
 fswrite(Fmsg *m)
 {
-	char sbuf[Wstatmax], kbuf[4][Offksz], vbuf[4][Ptrsz];
+	char sbuf[Wstatmax], kbuf[Max9p/Blksz+2][Offksz], vbuf[Max9p/Blksz+2][Ptrsz];
+	Bptr bp[Max9p/Blksz + 2];
+	Msg kv[Max9p/Blksz + 2];
+	vlong n, o, c, w;
 	char *p, *e;
-	vlong n, o, c;
 	int i, j;
-	Bptr bp[4];
-	Msg kv[4];
 	Fcall r;
 	Fid *f;
 
@@ -1898,10 +1898,12 @@
 	}		
 
 	wlock(f->dent);
+	w = 0;
 	p = m->data;
 	o = m->offset;
 	c = m->count;
 	for(i = 0; i < nelem(kv)-1 && c != 0; i++){
+		assert(i == 0 || o%Blksz == 0);
 		kv[i].op = Oinsert;
 		kv[i].k = kbuf[i];
 		kv[i].nk = sizeof(kbuf[i]);
@@ -1917,6 +1919,7 @@
 			abort();
 			return;
 		}
+		w += n;
 		p += n;
 		o += n;
 		c -= n;
@@ -1926,7 +1929,7 @@
 	kv[i].op = Owstat;
 	kv[i].k = f->dent->k;
 	kv[i].nk = f->dent->nk;
-	n = m->offset+m->count;
+	n = m->offset+w;
 	*p++ = 0;
 	if(n > f->dent->length){
 		sbuf[0] |= Owsize;
@@ -1953,7 +1956,7 @@
 	wunlock(f->dent);
 
 	r.type = Rwrite;
-	r.count = m->count;
+	r.count = w;
  	respond(m, &r);
 	putfid(f);
 }