shithub: riscv

Download patch

ref: bf7e8777f391caa82705a0b64709a95672d2632c
parent: ad458243e83c3ad9490da77fc40eacfdc64b5359
author: Jacob Moody <moody@posixcafe.org>
date: Fri Aug 25 14:51:36 EDT 2023

actually merge

--- a/sys/src/lib9p/srv.c
+++ b/sys/src/lib9p/srv.c
@@ -468,10 +468,15 @@
 static void
 ropen(Req *r, char *error)
 {
+	uint iounit;
+
 	if(error)
 		return;
 	if(chatty9p)
 		fprint(2, "fid mode is %x\n", (int)r->ifcall.mode);
+	iounit = r->srv->msize - IOHDRSZ;
+	if(r->ofcall.iounit > iounit)
+		r->ofcall.iounit = iounit;
 	if(r->ofcall.qid.type&QTDIR)
 		r->fid->diroffset = 0;
 	r->fid->qid = r->ofcall.qid;
@@ -481,6 +486,7 @@
 static void
 sread(Srv *srv, Req *r)
 {
+	uint iounit;
 	int o;
 
 	if((r->fid = lookupfid(srv->fpool, r->ifcall.fid)) == nil){
@@ -501,17 +507,18 @@
 	case OEXEC:
 		break;
 	}
-	if((int)r->ifcall.count < 0){
-		respond(r, Ebotch);
-		return;
-	}
 	if(r->ifcall.offset < 0
 	|| ((r->fid->qid.type&QTDIR) && r->ifcall.offset != 0 && r->ifcall.offset != r->fid->diroffset)){
 		respond(r, Ebadoffset);
 		return;
 	}
-	if(r->ifcall.count > srv->msize - IOHDRSZ)
-		r->ifcall.count = srv->msize - IOHDRSZ;
+	if((int)r->ifcall.count < 0){
+		respond(r, Ebotch);
+		return;
+	}
+	iounit = srv->msize - IOHDRSZ;
+	if(r->ifcall.count > iounit)
+		r->ifcall.count = iounit;
 	r->rbuf = emalloc9p(r->ifcall.count);
 	r->ofcall.data = r->rbuf;
 	if((r->fid->qid.type&QTDIR) && r->fid->file){
@@ -534,6 +541,7 @@
 static void
 swrite(Srv *srv, Req *r)
 {
+	uint iounit;
 	int o;
 
 	if((r->fid = lookupfid(srv->fpool, r->ifcall.fid)) == nil){
@@ -557,16 +565,17 @@
 		respond(r, Ebotch);
 		return;
 	}
-	if((int)r->ifcall.count < 0){
+	if(r->ifcall.offset < 0){
 		respond(r, Ebotch);
 		return;
 	}
-	if(r->ifcall.offset < 0){
+	if((int)r->ifcall.count < 0){
 		respond(r, Ebotch);
 		return;
 	}
-	if(r->ifcall.count > srv->msize - IOHDRSZ)
-		r->ifcall.count = srv->msize - IOHDRSZ;
+	iounit = srv->msize - IOHDRSZ;
+	if(r->ifcall.count > iounit)
+		r->ifcall.count = iounit;
 	if(srv->write)
 		srv->write(r);
 	else
--- a/sys/src/libdraw/readimage.c
+++ b/sys/src/libdraw/readimage.c
@@ -29,8 +29,11 @@
 		return nil;
 	if(d != nil)
 		chunk = d->bufsize - 32;	/* a little room for header */
-	else
-		chunk = 8192;
+	else {
+		chunk = iounit(fd);
+		if(chunk <= 0)
+			chunk = IOUNIT;
+	}
 
 	/*
 	 * distinguish new channel descriptor from old ldepth.