Subject: Re: Reading past device size (/dev/vnd v.s. /dev/cd)
To: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
From: Reinoud Zandijk <reinoud@netbsd.org>
List: tech-kern
Date: 01/20/2006 21:03:33
--lEGEL1/lMxI0MVQ2
Content-Type: multipart/mixed; boundary="vkogqOf2sHV7VnPd"
Content-Disposition: inline


--vkogqOf2sHV7VnPd
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hiya Takashi,

On Sat, Jan 21, 2006 at 02:26:28AM +0900, YAMAMOTO Takashi wrote:
> > I think it would thus be better to 
> > raise an error in nestiobuf_iodone() in that case.
> 
> sounds fine to me.

i've created the attached patch and it works fine. I had to add a check for 
b_resid too since i've found that /dev/cd0* also can return a buffer with 
matched sizes but with b_resid=b_count.

If noone objects, i'd like to commit it.

regards,
Reinoud


--vkogqOf2sHV7VnPd
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="vfs_bio.c-diff"

Index: vfs_bio.c
===================================================================
RCS file: /cvsroot/src/sys/kern/vfs_bio.c,v
retrieving revision 1.154
diff -u -r1.154 vfs_bio.c
--- vfs_bio.c	15 Jan 2006 09:01:02 -0000	1.154
+++ vfs_bio.c	20 Jan 2006 20:00:44 -0000
@@ -1787,10 +1787,18 @@
 {
 	struct buf *mbp = bp->b_private;
 	int error;
-	int donebytes = bp->b_bcount; /* XXX ignore b_resid */
+	int donebytes;
 
-	KASSERT(bp->b_bufsize == bp->b_bcount);
+	KASSERT(bp->b_bufsize >= bp->b_bcount);
 	KASSERT(mbp != bp);
+	if (bp->b_bcount < bp->b_bufsize || bp->b_resid > 0) {
+		/* not all got transfered, raise an error */
+		bp->b_flags |= B_ERROR;
+		bp->b_error = EIO;
+	};
+
+	donebytes = bp->b_bufsize; /* XXX ignore b_resid */
+
 	if ((bp->b_flags & B_ERROR) != 0) {
 		error = bp->b_error;
 	} else {
@@ -1822,9 +1830,7 @@
 	bp->b_iodone = nestiobuf_iodone;
 	bp->b_data = mbp->b_data + offset;
 	bp->b_resid = bp->b_bcount = size;
-#if defined(DIAGNOSTIC)
 	bp->b_bufsize = bp->b_bcount;
-#endif /* defined(DIAGNOSTIC) */
 	bp->b_private = mbp;
 	BIO_COPYPRIO(bp, mbp);
 	if (!b_read && vp != NULL) {

--vkogqOf2sHV7VnPd--

--lEGEL1/lMxI0MVQ2
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (NetBSD)

iQEVAwUBQ9FCDoKcNwBDyKpoAQKrTQgAwSOaPylXZ2HLQ4+fmQSH2bVM17Laf3PD
TK+hH31VJ7nXdYKuf/6L8CfGT4JPzFNyRRu7/pkQkuaR8jwVtMQZtLoKD2HZ5y32
V1GJR7BVIczStcFyr9M0atBDacwoyc+54pN4AxWdEOTToR50vyysVwFR6jyJpv3V
l1OfdD9xTCHei2ntcdy/E/zbmQbr+Ujqxtu+3NwjTOpwJ2nToN3sfUC98OIRx3am
qPX2xpf/l3icPLyAiTabeeB/Nw3xSCD/H6HG+KjCJgyflSLWLC+p88E49gzW86dk
xsHm4PtcbNKdPQNK9ar2NAHX0jR1eB6/qYYaZLH3dZNYK7ogQf93BA==
=GU1n
-----END PGP SIGNATURE-----

--lEGEL1/lMxI0MVQ2--