Subject: genfs_getpages() nit
To: None <tech-kern@netbsd.org>
From: Jaromír Dolecek <dolecek@ics.muni.cz>
List: tech-kern
Date: 01/26/2001 23:44:10
Hi,
while looking around on how mmap() internally works, I've came
across the not very easily parsable stuff in sys/miscfs/genfs/genfs_vnops.c
at lines 527+. I adjusted it a little so that the intent is more
easy to grok, this even yielded an microoptimization. Does
following change look correct ?

Jaromir

Index: genfs_vnops.c
===================================================================
RCS file: /cvsroot/syssrc/sys/miscfs/genfs/genfs_vnops.c,v
retrieving revision 1.25
diff -u -r1.25 genfs_vnops.c
--- genfs_vnops.c	2001/01/22 16:39:54	1.25
+++ genfs_vnops.c	2001/01/26 22:31:11
@@ -524,17 +524,22 @@
 	dev_bsize = 1 << dev_bshift;
 	KASSERT((eof & (dev_bsize - 1)) == 0);
 
-	orignpages = min(*ap->a_count,
-	    round_page(eof - origoffset) >> PAGE_SHIFT);
-	if (flags & PGO_PASTEOF) {
+	if (flags & PGO_PASTEOF)
 		orignpages = *ap->a_count;
+	else {
+		orignpages = min(*ap->a_count,
+			round_page(eof - origoffset) >> PAGE_SHIFT);
 	}
 	npages = orignpages;
 	startoffset = origoffset & ~(fs_bsize - 1);
-	endoffset = round_page((origoffset + (npages << PAGE_SHIFT)
-				+ fs_bsize - 1) & ~(fs_bsize - 1));
+	if (fs_bshift < PAGE_SHIFT)
+		endoffset = round_page(startoffset + (npages << PAGE_SHIFT));
+	else {
+		endoffset = round_page(startoffset +
+		  (((npages << PAGE_SHIFT) + fs_bsize - 1) & ~(fs_bsize - 1)));
+	}
 	endoffset = min(endoffset, round_page(eof));
-	ridx = (origoffset - startoffset) >> PAGE_SHIFT;
+	ridx = (origoffset & fs_bsize) >> PAGE_SHIFT;
 
 	memset(pgs, 0, sizeof(pgs));
 	uvn_findpages(uobj, origoffset, &npages, &pgs[ridx], UFP_ALL);

-- 
Jaromir Dolecek <jdolecek@NetBSD.org>      http://www.ics.muni.cz/~dolecek/
@@@@  Wanna a real operating system ? Go and get NetBSD, dammit!  @@@@