Subject: Re: NetBSD, apple fibre-channel card & 2.8TB Xserve-RAID
To: der Mouse <mouse@rodents.montreal.qc.ca>
From: Charles M. Hannum <abuse@spamalicious.com>
List: tech-kern
Date: 12/10/2004 22:17:37
--Boundary-00=_BCiuBTferqQ8C4I
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Could you try this patch to ufs_bmap.c instead?  It basically just makes the 
code like -current, without the snapshot stuff, and also removes a bunch of 
casts that I think are wrong.

If it works, I'll remove the casts in -current and submit this for a pullup.  
Too bad it didn't make 2.0, though.

--Boundary-00=_BCiuBTferqQ8C4I
Content-Type: text/x-diff;
  charset="iso-8859-1";
  name="c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="c"

--- a	2004-12-10 22:05:47.000000000 +0000
+++ b	2004-12-10 22:11:55.000000000 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_bmap.c,v 1.28.2.1 2004/07/28 11:29:42 tron Exp $	*/
+/*	$NetBSD: ufs_bmap.c,v 1.29 2004/05/25 14:55:46 hannken Exp $	*/
 
 /*
  * Copyright (c) 1989, 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ufs_bmap.c,v 1.28.2.1 2004/07/28 11:29:42 tron Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_bmap.c,v 1.29 2004/05/25 14:55:46 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -157,21 +157,21 @@
 		if (nump != NULL)
 			*nump = 0;
 		if (ip->i_ump->um_fstype == UFS1)
-			*bnp = blkptrtodb(ump,
-			    (int32_t)ufs_rw32(ip->i_ffs1_db[bn],
-			    UFS_MPNEEDSWAP(vp->v_mount)));
+			daddr = ufs_rw32(ip->i_ffs1_db[bn],
+			    UFS_MPNEEDSWAP(vp->v_mount));
 		else
-			*bnp = blkptrtodb(ump, ufs_rw64(ip->i_ffs2_db[bn],
-			    UFS_MPNEEDSWAP(vp->v_mount)));
+			daddr = ufs_rw64(ip->i_ffs2_db[bn],
+			    UFS_MPNEEDSWAP(vp->v_mount));
+		*bnp = blkptrtodb(ump, daddr);
 		if (*bnp == 0)
 			*bnp = -1;
-		if (runp) {
+		else if (runp) {
 			if (ip->i_ump->um_fstype == UFS1) {
 				for (++bn; bn < NDADDR && *runp < maxrun &&
 				    is_sequential(ump,
-				        (int32_t)ufs_rw32(ip->i_ffs1_db[bn - 1],
+				        ufs_rw32(ip->i_ffs1_db[bn - 1],
 				            UFS_MPNEEDSWAP(vp->v_mount)),
-				        (int32_t)ufs_rw32(ip->i_ffs1_db[bn],
+				        ufs_rw32(ip->i_ffs1_db[bn],
 				            UFS_MPNEEDSWAP(vp->v_mount)));
 				    ++bn, ++*runp);
 			} else {
@@ -197,7 +197,7 @@
 
 	/* Get disk address out of indirect block array */
 	if (ip->i_ump->um_fstype == UFS1)
-		daddr = (int32_t)ufs_rw32(ip->i_ffs1_ib[xap->in_off],
+		daddr = ufs_rw32(ip->i_ffs1_ib[xap->in_off],
 		    UFS_MPNEEDSWAP(vp->v_mount));
 	else
 		daddr = ufs_rw64(ip->i_ffs2_ib[xap->in_off],
@@ -252,25 +252,22 @@
 			}
 		}
 		if (ip->i_ump->um_fstype == UFS1) {
-			daddr = (int32_t)ufs_rw32(
-			    ((int32_t *)bp->b_data)[xap->in_off],
+			daddr = ufs_rw32(((int32_t *)bp->b_data)[xap->in_off],
 			    UFS_MPNEEDSWAP(mp));
-			if (num == 1 && runp) {
+			if (num == 1 && daddr && runp) {
 				for (bn = xap->in_off + 1;
 				    bn < MNINDIR(ump) && *runp < maxrun &&
 				    is_sequential(ump,
-				        (int32_t)ufs_rw32(
-					    ((int32_t *)bp->b_data)[bn-1],
+				        ufs_rw32(((int32_t *)bp->b_data)[bn-1],
 				            UFS_MPNEEDSWAP(mp)),
-				        (int32_t)ufs_rw32(
-					    ((int32_t *)bp->b_data)[bn],
+				        ufs_rw32(((int32_t *)bp->b_data)[bn],
 				            UFS_MPNEEDSWAP(mp)));
 				    ++bn, ++*runp);
 			}
 		} else {
 			daddr = ufs_rw64(((int64_t *)bp->b_data)[xap->in_off],
 			    UFS_MPNEEDSWAP(mp));
-			if (num == 1 && runp) {
+			if (num == 1 && daddr && runp) {
 				for (bn = xap->in_off + 1;
 				    bn < MNINDIR(ump) && *runp < maxrun &&
 				    is_sequential(ump,
@@ -285,8 +282,9 @@
 	if (bp)
 		brelse(bp);
 
-	daddr = blkptrtodb(ump, daddr);
-	*bnp = daddr == 0 ? -1 : daddr;
+	*bnp = blkptrtodb(ump, daddr);
+	if (*bnp == 0)
+		*bnp = -1;
 	return (0);
 }
 

--Boundary-00=_BCiuBTferqQ8C4I--