Subject: Re: disklabel(8) and machdep on-disk structures issues
To: None <tech-kern@netbsd.org>
From: Manuel Bouyer <bouyer@antioche.eu.org>
List: tech-kern
Date: 11/06/2003 23:38:57
--/04w6evG8XlLl3ft
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

[ please reply to tech-kern, unless your anserw is really port-specific ]

Hi,


On Fri, Oct 31, 2003 at 05:07:04PM +0100, Manuel Bouyer wrote:
> 
> So I propose:
> - fix next68k disksubr.c to always write a next-compatible disklabel
>   in addition to the NetBSD disklabel (need to find some space for
>   the NetBSD disklabel first, shouldn't be too hard).
> - Fix the sun3 LABELOFFSET, and factor out disksubr.c between sun3, sparc and
>   sparc64 (with some compat code to look for a NetBSD disklabel at
>   LABELOFFSET=64 in the sun3 case)
> - remove #ifdef __sparc__ hack from disklabel(8), and change it to issue
>   a DIOCWDINFO after writing the disklabel to the raw partition in the
>   -r/-I case (so that the kernel can convert the label if needed)

Attached is a patch implementing this. Tested on sparc, sun3 and next68k.
We now have a sys/dev/sun/disksubr.c, based on sparc/disksubr.c. The
sparc/disksubr.c and sparc64/disksubr.c differed only by some includes
(BTW, both #included too much things). sun3/disksubr.c has some more
differences, especially the groveling code to find a NetBSD disklabel 
in the first sector. I integrated this in sys/dev/sun/disksubr.c, as fallback
if no NetBSD or Sun label have been found at the expected place (this will
ensure that disk writtens with disklabel -r using the wrong Sun3 labeloffset
will still be readable).

next68k still doesn't write a NetBSD disklanel; I didn't find a proper place
for it on disk yet (LABELSECTOR=15 should put it at the end of the NeXT v3
label, but the machine doens't boot with it ...).

Comments ?
I'd like to commit this in about a week, as it fixes 2 bugs:
- disklabel -r sd0 reports "no disk label" on sun3 because of the wrong
  LABELOFFSET
- next68k can't be installed on a SCSI disk, because in order to write
  a label to a virgin disk you have to use disklanel -I or -r, which will
  install a NetBSD disklabel and prevent the kernel from writing a NeXT
  disklabel.

-- 
Manuel Bouyer <bouyer@antioche.eu.org>
     NetBSD: 24 ans d'experience feront toujours la difference
--

--/04w6evG8XlLl3ft
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=diff

Index: sbin/disklabel/disklabel.c
===================================================================
RCS file: /cvsroot/src/sbin/disklabel/disklabel.c,v
retrieving revision 1.119
diff -u -r1.119 disklabel.c
--- sbin/disklabel/disklabel.c	2003/10/08 04:25:44	1.119
+++ sbin/disklabel/disklabel.c	2003/11/06 20:06:19
@@ -476,12 +476,7 @@
 	lp->d_checksum = 0;
 	lp->d_checksum = dkcksum(lp);
 
-#ifdef __sparc__
-	/* Let the kernel deal with SunOS disklabel compatibility */
-	if (0)
-#else	/* ! __sparc__ */
 	if (rflag || Iflag)
-#endif	/* ! __sparc__ */
 	{
 #ifdef USE_MBR
 		struct partition *pp = &lp->d_partitions[2];
@@ -569,6 +564,14 @@
 		writable = 0;
 		if (ioctl(f, DIOCWLABEL, &writable) < 0)
 			perror("ioctl DIOCWLABEL");
+		/* 
+		 * Now issue a DIOCWDINFO. This will let the kernel convert the
+		 * disklabel to some machdep format if needed.
+		 */
+		if (ioctl(f, DIOCWDINFO, lp) < 0) {
+			l_perror("ioctl DIOCWDINFO");
+			return (1);
+		}
 	} else {
 		if (ioctl(f, DIOCWDINFO, lp) < 0) {
 			l_perror("ioctl DIOCWDINFO");
Index: sys/arch/next68k/include/disklabel.h
===================================================================
RCS file: /cvsroot/src/sys/arch/next68k/include/disklabel.h,v
retrieving revision 1.3
diff -u -r1.3 disklabel.h
--- sys/arch/next68k/include/disklabel.h	2003/10/27 16:48:08	1.3
+++ sys/arch/next68k/include/disklabel.h	2003/11/06 20:06:44
@@ -34,9 +34,12 @@
 
 #include <sys/bootblock.h>
 
-#define	LABELSECTOR	NEXT68K_LABEL_SECTOR	/* sector containing label */
-#define	LABELOFFSET	NEXT68K_LABEL_OFFSET	/* offset of label in sector */
-#define LABELSIZE	NEXT68K_LABEL_SIZE	/* size of label */
+/*
+ * The NetBSD disklabel is located in the last sector of the next68k label
+ * area, so that it can coexists with a next68k v3 label
+ */
+#define	LABELSECTOR	15	/* sector containing label */
+#define	LABELOFFSET	0	/* offset of label in sector */
 #define	MAXPARTITIONS	8	/* number of partitions */
 #define	RAW_PART	2	/* raw partition: xx?c */
 
Index: sys/arch/next68k/next68k/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/next68k/next68k/disksubr.c,v
retrieving revision 1.15
diff -u -r1.15 disksubr.c
--- sys/arch/next68k/next68k/disksubr.c	2003/10/27 16:48:08	1.15
+++ sys/arch/next68k/next68k/disksubr.c	2003/11/06 20:06:44
@@ -58,7 +58,7 @@
 static char * parse_nextstep_label __P((struct next68k_disklabel *, 
 			struct disklabel *, struct cpu_disklabel *));
 static int build_nextstep_label __P((struct next68k_disklabel *, 
-			struct disklabel *, struct cpu_disklabel *));
+			struct disklabel *));
 
 static unsigned short
 nextstep_checksum(buf, limit)
@@ -116,7 +116,7 @@
 	lp->d_rpm = ondisk->cd_rpm;
 	lp->d_flags = ondisk->cd_flags;
 
-	lp->d_bbsize = LABELSIZE;
+	lp->d_bbsize = NEXT68K_LABEL_SIZE;
 	lp->d_sbsize = SBLOCKSIZE;
 
 	lp->d_npartitions = nbp = 0;
@@ -171,38 +171,34 @@
 }
 
 static int
-build_nextstep_label(ondisk, lp, osdep)
+build_nextstep_label(ondisk, lp)
 	struct next68k_disklabel *ondisk;
 	struct disklabel *lp;
-	struct cpu_disklabel *osdep;
 {
 	int i, t, nbp;
 	int front_porch = NEXT68K_LABEL_DEFAULTFRONTPORCH;
 	unsigned short *checksum;
 
-	if (osdep->od_version == 0) {
-		osdep->od_version = NEXT68K_LABEL_CD_V3;
 
-		memset (ondisk, 0, sizeof (ondisk));
+	memset (ondisk, 0, sizeof (ondisk));
 
-		/* ondisk->cd_label_blkno = 0; */
-		/* ondisk->cd_size = 0; */
-		/* ondisk->cd_tag = 0; */
-		strncpy (ondisk->cd_type, "fixed_rw_scsi", sizeof (ondisk->cd_type));
-		ondisk->cd_secsize = lp->d_secsize;
-		/* ondisk->cd_back = 0; */
-		/* ondisk->cd_ngroups = 0; */
-		/* ondisk->cd_ag_size = 0; */
-		/* ondisk->cd_ag_alts = 0; */
-		/* ondisk->cd_ag_off = 0; */
-		/* ondisk->kernel */
-		/* ondisk->hostname */
-		/* ondisk->rootpartition */
-		/* ondisk->rwpartition */
-	}
+	ondisk->cd_version = NEXT68K_LABEL_CD_V3;
+	/* ondisk->cd_label_blkno = 0; */
+	/* ondisk->cd_size = 0; */
+	/* ondisk->cd_tag = 0; */
+	strncpy (ondisk->cd_type, "fixed_rw_scsi", sizeof (ondisk->cd_type));
+	ondisk->cd_secsize = lp->d_secsize;
+	/* ondisk->cd_back = 0; */
+	/* ondisk->cd_ngroups = 0; */
+	/* ondisk->cd_ag_size = 0; */
+	/* ondisk->cd_ag_alts = 0; */
+	/* ondisk->cd_ag_off = 0; */
+	/* ondisk->kernel */
+	/* ondisk->hostname */
+	/* ondisk->rootpartition */
+	/* ondisk->rwpartition */
 	KASSERT(ondisk->cd_secsize >= lp->d_secsize);
 
-	ondisk->cd_version = osdep->od_version;
 	if (memcmp (ondisk->cd_name, lp->d_typename,
 		     min (sizeof (lp->d_typename), sizeof (ondisk->cd_name))) &&
 	    sizeof (ondisk->cd_name) > sizeof (lp->d_typename))
@@ -348,35 +344,57 @@
 		lp->d_partitions[i].p_size = 0x1fffffff;
 	lp->d_partitions[i].p_offset = 0;
 
-	bp = geteblk(LABELSIZE);
+	bp = geteblk(NEXT68K_LABEL_SIZE);
 	bp->b_dev = dev;
-	bp->b_blkno = LABELSECTOR;
-	bp->b_bcount = LABELSIZE;
+	bp->b_blkno = NEXT68K_LABEL_SECTOR;
+	bp->b_bcount = NEXT68K_LABEL_SIZE;
 	bp->b_flags |= B_READ;
-	bp->b_cylinder = LABELSECTOR / lp->d_secpercyl;
+	bp->b_cylinder = NEXT68K_LABEL_SECTOR / lp->d_secpercyl;
 	(*strat)(bp);
 	
 	if (osdep)
 		osdep->od_version = 0;
 
-	if (biowait(bp))
-		msg = "I/O error";
-	else if (IS_DISKLABEL ((struct next68k_disklabel *)bp->b_data))
+	if (biowait(bp)) {
+		brelse(bp);
+		return("I/O error");
+	}
+	dlp = (struct disklabel *)
+	    ((char *)bp->b_data + LABELSECTOR * lp->d_secsize + LABELOFFSET);
+	if (dlp->d_magic == DISKMAGIC || dlp->d_magic2 == DISKMAGIC) {
+		/* got a NetBSD disklabel */
+		if (osdep)
+			osdep->od_version = DISKMAGIC;
+		if (dlp->d_npartitions > MAXPARTITIONS ||
+			   dkcksum(dlp) != 0)
+			msg = "disk label corrupted";
+		else {
+			*lp = *dlp;
+			msg = NULL;
+		}
+		brelse(bp);
+		return msg;
+	}
+	if (IS_DISKLABEL ((struct next68k_disklabel *)bp->b_data)) {
+		/* got a NeXT disklabel */
 		msg = parse_nextstep_label
 			((struct next68k_disklabel *)bp->b_data, lp, osdep);
-	else {
-		if (osdep &&
-		    ((struct disklabel *)bp->b_data)->d_magic == DISKMAGIC)
-			osdep->od_version = DISKMAGIC;
-		for (dlp = (struct disklabel *)bp->b_data;
-		     dlp <= (struct disklabel *)((char *)bp->b_data +
-						 DEV_BSIZE - sizeof(*dlp));
-		     dlp = (struct disklabel *)((char *)dlp + sizeof(long))) {
-			if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) {
-				if (msg == NULL)
-					msg = "no disk label";
-			} else if (dlp->d_npartitions > MAXPARTITIONS ||
-				   dkcksum(dlp) != 0)
+		brelse(bp);
+		return msg;
+	}
+	/*
+	 * no disklabel at the usual places. Try to locate a NetBSD disklabel
+	 * in the first sector. This ensure compatibility with others
+	 * big-endian systems, and with next68k when LABELSECTOR was 0.
+	 */
+	msg = "no disk label";
+	for (dlp = (struct disklabel *)bp->b_data;
+	     dlp <= (struct disklabel *)((char *)bp->b_data +
+					 DEV_BSIZE - sizeof(*dlp));
+	     dlp = (struct disklabel *)((char *)dlp + sizeof(long))) {
+		if (dlp->d_magic == DISKMAGIC || dlp->d_magic2 == DISKMAGIC) {
+			if (dlp->d_npartitions > MAXPARTITIONS ||
+			   dkcksum(dlp) != 0)
 				msg = "disk label corrupted";
 			else {
 				*lp = *dlp;
@@ -443,7 +461,9 @@
 	struct cpu_disklabel *osdep;
 {
 	struct buf *bp;
+#if 0
 	struct disklabel *dlp;
+#endif
 	int labelpart;
 	int error = 0;
 
@@ -453,50 +473,28 @@
 			return (EXDEV);			/* not quite right */
 		labelpart = 0;
 	}
-	if (osdep->od_version != DISKMAGIC) {
-		bp = geteblk(LABELSIZE);
-		bp->b_dev = MAKEDISKDEV(major(dev), DISKUNIT(dev), labelpart);
-		bp->b_blkno = LABELSECTOR;
-		bp->b_bcount = LABELSIZE;
-		bp->b_flags |= B_READ;
-		bp->b_cylinder = LABELSECTOR / lp->d_secpercyl;
-		(*strat)(bp);
-		error = biowait(bp);
-		if (error)
-			goto done;
-		error = build_nextstep_label 
-			((struct next68k_disklabel *)bp->b_data, lp, osdep);
-		if (error)
-			goto done;
-		bp->b_flags &= ~(B_READ|B_DONE);
-		bp->b_flags |= B_WRITE;
-		(*strat)(bp);
-		error = biowait(bp);
-	} else {
-		bp = geteblk((int)lp->d_secsize);
-		bp->b_dev = MAKEDISKDEV(major(dev), DISKUNIT(dev), labelpart);
-		bp->b_blkno = LABELSECTOR;
-		bp->b_bcount = lp->d_secsize;
-		bp->b_flags |= B_READ;
-		(*strat)(bp);
-		if ((error = biowait(bp)))
-			goto done;
-		for (dlp = (struct disklabel *)bp->b_data;
-		     dlp <= (struct disklabel *)
-			     ((char *)bp->b_data + lp->d_secsize - sizeof(*dlp));
-		     dlp = (struct disklabel *)((char *)dlp + sizeof(long))) {
-			if (dlp->d_magic == DISKMAGIC && dlp->d_magic2 == DISKMAGIC &&
-			    dkcksum(dlp) == 0) {
-				*dlp = *lp;
-				bp->b_flags &= ~(B_READ|B_DONE);
-				bp->b_flags |= B_WRITE;
-				(*strat)(bp);
-				error = biowait(bp);
-				goto done;
-			}
-		}
-		error = ESRCH;
-	}
+	/*
+	 * We always write a NeXT v3 disklabel, and a NetBSD disklabel in
+	 * the last sector of the NeXT label area.
+	 */
+  
+	bp = geteblk(NEXT68K_LABEL_SIZE);
+	bp->b_dev = MAKEDISKDEV(major(dev), DISKUNIT(dev), labelpart);
+	bp->b_blkno = NEXT68K_LABEL_SECTOR;
+	bp->b_bcount = NEXT68K_LABEL_SIZE;
+	bp->b_flags |= B_WRITE;
+	bp->b_cylinder = NEXT68K_LABEL_SECTOR / lp->d_secpercyl;
+	error = build_nextstep_label 
+		((struct next68k_disklabel *)bp->b_data, lp);
+	if (error)
+		goto done;
+#if 0
+	dlp = (struct disklabel *)
+	    ((char *)bp->b_data + LABELSECTOR * lp->d_secsize + LABELOFFSET);
+	*dlp = *lp;
+#endif
+	(*strat)(bp);
+	error = biowait(bp);
 done:
 	brelse(bp);
 	return (error);
Index: sys/arch/sparc/conf/files.sparc
===================================================================
RCS file: /cvsroot/src/sys/arch/sparc/conf/files.sparc,v
retrieving revision 1.123
diff -u -r1.123 files.sparc
--- sys/arch/sparc/conf/files.sparc	2003/07/27 01:19:32	1.123
+++ sys/arch/sparc/conf/files.sparc	2003/11/06 20:06:50
@@ -266,6 +266,7 @@
 #
 
 file	dev/cons.c
+file	dev/sun/disksubr.c
 
 file	arch/sparc/fpu/fpu.c
 file	arch/sparc/fpu/fpu_add.c
@@ -299,7 +300,6 @@
 file	arch/sparc/sparc/sys_machdep.c
 file	arch/sparc/sparc/trap.c
 file	arch/sparc/sparc/vm_machdep.c
-file	arch/sparc/sparc/disksubr.c
 
 file	arch/sparc/sparc/db_interface.c	ddb | kgdb
 file	arch/sparc/sparc/db_trace.c	ddb
Index: sys/arch/sparc/sparc/disksubr.c
===================================================================
RCS file: disksubr.c
diff -N disksubr.c
--- /tmp/cvs20401ah	Thu Nov  6 20:13:05 2003
+++ /dev/null	Mon Aug 30 16:41:34 1999
@@ -1,469 +0,0 @@
-/*	$NetBSD: disksubr.c,v 1.36 2003/07/15 00:05:03 lukem Exp $ */
-
-/*
- * Copyright (c) 1994, 1995 Gordon W. Ross
- * Copyright (c) 1994 Theo de Raadt
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *      This product includes software developed by Theo de Raadt.
- * 4. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: disksubr.c,v 1.36 2003/07/15 00:05:03 lukem Exp $");
-
-#include "opt_sparc_arch.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/buf.h>
-#include <sys/ioccom.h>
-#include <sys/device.h>
-#include <sys/disklabel.h>
-#include <sys/disk.h>
-#include <sys/dkbad.h>
-
-#include <dev/scsipi/scsi_all.h>
-#include <dev/scsipi/scsipi_all.h>
-#include <dev/scsipi/scsiconf.h>
-
-#include <machine/autoconf.h>
-#include <machine/cpu.h>
-#if defined(SUN4)
-#include <machine/oldmon.h>
-#endif
-
-#include <dev/sun/disklabel.h>
-
-#include <sparc/dev/sbusvar.h>
-
-static	char *disklabel_sun_to_bsd __P((char *, struct disklabel *));
-static	int disklabel_bsd_to_sun __P((struct disklabel *, char *));
-
-extern struct device *bootdv;
-
-/*
- * Attempt to read a disk label from a device
- * using the indicated strategy routine.
- * The label must be partly set up before this:
- * secpercyl, secsize and anything required for a block i/o read
- * operation in the driver's strategy/start routines
- * must be filled in before calling us.
- *
- * Return buffer for use in signalling errors if requested.
- *
- * Returns null on success and an error string on failure.
- */
-const char *
-readdisklabel(dev, strat, lp, clp)
-	dev_t dev;
-	void (*strat) __P((struct buf *));
-	struct disklabel *lp;
-	struct cpu_disklabel *clp;
-{
-	struct buf *bp;
-	struct disklabel *dlp;
-	struct sun_disklabel *slp;
-	int error;
-
-	/* minimal requirements for archtypal disk label */
-	if (lp->d_secperunit == 0)
-		lp->d_secperunit = 0x1fffffff;
-	if (lp->d_npartitions == 0) {
-		lp->d_npartitions = RAW_PART + 1;
-		if (lp->d_partitions[RAW_PART].p_size == 0)
-			lp->d_partitions[RAW_PART].p_size = 0x1fffffff;
-		lp->d_partitions[RAW_PART].p_offset = 0;
-	}
-
-	/* obtain buffer to probe drive with */
-	bp = geteblk((int)lp->d_secsize);
-
-	/* next, dig out disk label */
-	bp->b_dev = dev;
-	bp->b_blkno = LABELSECTOR;
-	bp->b_cylinder = 0;
-	bp->b_bcount = lp->d_secsize;
-	bp->b_flags |= B_READ;
-	(*strat)(bp);
-
-	/* if successful, locate disk label within block and validate */
-	error = biowait(bp);
-	if (error == 0) {
-		/* Save the whole block in case it has info we need. */
-		bcopy(bp->b_data, clp->cd_block, sizeof(clp->cd_block));
-	}
-	brelse(bp);
-	if (error)
-		return ("disk label read error");
-
-	/* Check for a NetBSD disk label. */
-	dlp = (struct disklabel *) (clp->cd_block + LABELOFFSET);
-	if (dlp->d_magic == DISKMAGIC) {
-		if (dkcksum(dlp))
-			return ("NetBSD disk label corrupted");
-		*lp = *dlp;
-		return (NULL);
-	}
-
-	/* Check for a Sun disk label (for PROM compatibility). */
-	slp = (struct sun_disklabel *) clp->cd_block;
-	if (slp->sl_magic == SUN_DKMAGIC)
-		return (disklabel_sun_to_bsd(clp->cd_block, lp));
-
-
-	bzero(clp->cd_block, sizeof(clp->cd_block));
-	return ("no disk label");
-}
-
-/*
- * Check new disk label for sensibility
- * before setting it.
- */
-int
-setdisklabel(olp, nlp, openmask, clp)
-	struct disklabel *olp, *nlp;
-	u_long openmask;
-	struct cpu_disklabel *clp;
-{
-	int i;
-	struct partition *opp, *npp;
-
-	/* sanity clause */
-	if (nlp->d_secpercyl == 0 || nlp->d_secsize == 0 ||
-	    (nlp->d_secsize % DEV_BSIZE) != 0)
-		return(EINVAL);
-
-	/* special case to allow disklabel to be invalidated */
-	if (nlp->d_magic == 0xffffffff) {
-		*olp = *nlp;
-		return (0);
-	}
-
-	if (nlp->d_magic != DISKMAGIC || nlp->d_magic2 != DISKMAGIC ||
-	    dkcksum(nlp) != 0)
-		return (EINVAL);
-
-	while ((i = ffs(openmask)) != 0) {
-		i--;
-		openmask &= ~(1 << i);
-		if (nlp->d_npartitions <= i)
-			return (EBUSY);
-		opp = &olp->d_partitions[i];
-		npp = &nlp->d_partitions[i];
-		if (npp->p_offset != opp->p_offset || npp->p_size < opp->p_size)
-			return (EBUSY);
-	}
-
-	*olp = *nlp;
-	return (0);
-}
-
-/*
- * Write disk label back to device after modification.
- * Current label is already in clp->cd_block[]
- */
-int
-writedisklabel(dev, strat, lp, clp)
-	dev_t dev;
-	void (*strat) __P((struct buf *));
-	struct disklabel *lp;
-	struct cpu_disklabel *clp;
-{
-	struct buf *bp;
-	int error;
-	struct disklabel *dlp;
-	struct sun_disklabel *slp;
-
-	/*
-	 * Embed native label in a piece of wasteland.
-	 */
-	if (sizeof(struct disklabel) > sizeof slp->sl_bsdlabel)
-		return EFBIG;
-
-	slp = (struct sun_disklabel *)clp->cd_block;
-	bzero(slp->sl_bsdlabel, sizeof(slp->sl_bsdlabel));
-	dlp = (struct disklabel *)slp->sl_bsdlabel;
-	*dlp = *lp;
-
-	/* Build a SunOS compatible label around the native label */
-	error = disklabel_bsd_to_sun(lp, clp->cd_block);
-	if (error)
-		return (error);
-
-	/* Get a buffer and copy the new label into it. */
-	bp = geteblk((int)lp->d_secsize);
-	bcopy(clp->cd_block, bp->b_data, sizeof(clp->cd_block));
-
-	/* Write out the updated label. */
-	bp->b_dev = dev;
-	bp->b_blkno = LABELSECTOR;
-	bp->b_cylinder = 0;
-	bp->b_bcount = lp->d_secsize;
-	bp->b_flags |= B_WRITE;
-	(*strat)(bp);
-	error = biowait(bp);
-	brelse(bp);
-
-	return (error);
-}
-
-/*
- * Determine the size of the transfer, and make sure it is
- * within the boundaries of the partition. Adjust transfer
- * if needed, and signal errors or early completion.
- */
-int
-bounds_check_with_label(dk, bp, wlabel)
-	struct disk *dk;
-	struct buf *bp;
-	int wlabel;
-{
-	struct disklabel *lp = dk->dk_label;
-	struct partition *p = lp->d_partitions + DISKPART(bp->b_dev);
-	int maxsz = p->p_size;
-	int sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT;
-
-	/*
-	 * overwriting disk label ?
-	 * The label is always in sector LABELSECTOR.
-	 * XXX should also protect bootstrap in first 8K
-	 */
-	if (bp->b_blkno + p->p_offset <= LABELSECTOR &&
-	    (bp->b_flags & B_READ) == 0 && wlabel == 0) {
-		bp->b_error = EROFS;
-		goto bad;
-	}
-
-	/* beyond partition? */
-	if (bp->b_blkno < 0 || bp->b_blkno + sz > maxsz) {
-		/* if exactly at end of disk, return an EOF */
-		if (bp->b_blkno == maxsz) {
-			bp->b_resid = bp->b_bcount;
-			return(0);
-		}
-		/* or truncate if part of it fits */
-		sz = maxsz - bp->b_blkno;
-		if (sz <= 0) {
-			bp->b_error = EINVAL;
-			goto bad;
-		}
-		bp->b_bcount = sz << DEV_BSHIFT;
-	}
-
-	/* calculate cylinder for disksort to order transfers with */
-	bp->b_resid = (bp->b_blkno + p->p_offset) / lp->d_secpercyl;
-	return(1);
-bad:
-	bp->b_flags |= B_ERROR;
-	return(-1);
-}
-
-/************************************************************************
- *
- * The rest of this was taken from arch/sparc/scsi/sun_disklabel.c
- * and then substantially rewritten by Gordon W. Ross
- *
- ************************************************************************/
-
-/* What partition types to assume for Sun disklabels: */
-static u_char
-sun_fstypes[8] = {
-	FS_BSDFFS,	/* a */
-	FS_SWAP,	/* b */
-	FS_OTHER,	/* c - whole disk */
-	FS_BSDFFS,	/* d */
-	FS_BSDFFS,	/* e */
-	FS_BSDFFS,	/* f */
-	FS_BSDFFS,	/* g */
-	FS_BSDFFS,	/* h */
-};
-
-/*
- * Given a SunOS disk label, set lp to a BSD disk label.
- * Returns NULL on success, else an error string.
- *
- * The BSD label is cleared out before this is called.
- */
-static char *
-disklabel_sun_to_bsd(cp, lp)
-	char *cp;
-	struct disklabel *lp;
-{
-	struct sun_disklabel *sl;
-	struct partition *npp;
-	struct sun_dkpart *spp;
-	int i, secpercyl;
-	u_short cksum, *sp1, *sp2;
-
-	sl = (struct sun_disklabel *)cp;
-
-	/* Verify the XOR check. */
-	sp1 = (u_short *)sl;
-	sp2 = (u_short *)(sl + 1);
-	cksum = 0;
-	while (sp1 < sp2)
-		cksum ^= *sp1++;
-	if (cksum != 0)
-		return("SunOS disk label, bad checksum");
-
-	/* Format conversion. */
-	lp->d_magic = DISKMAGIC;
-	lp->d_magic2 = DISKMAGIC;
-	memcpy(lp->d_packname, sl->sl_text, sizeof(lp->d_packname));
-
-	lp->d_secsize = 512;
-	lp->d_nsectors   = sl->sl_nsectors;
-	lp->d_ntracks    = sl->sl_ntracks;
-	lp->d_ncylinders = sl->sl_ncylinders;
-
-	secpercyl = sl->sl_nsectors * sl->sl_ntracks;
-	lp->d_secpercyl  = secpercyl;
-	lp->d_secperunit = secpercyl * sl->sl_ncylinders;
-
-	lp->d_sparespercyl = sl->sl_sparespercyl;
-	lp->d_acylinders   = sl->sl_acylinders;
-	lp->d_rpm          = sl->sl_rpm;
-	lp->d_interleave   = sl->sl_interleave;
-
-	lp->d_npartitions = 8;
-	/* These are as defined in <ufs/ffs/fs.h> */
-	lp->d_bbsize = 8192;	/* XXX */
-	lp->d_sbsize = 8192;	/* XXX */
-
-	for (i = 0; i < 8; i++) {
-		spp = &sl->sl_part[i];
-		npp = &lp->d_partitions[i];
-		npp->p_offset = spp->sdkp_cyloffset * secpercyl;
-		npp->p_size = spp->sdkp_nsectors;
-		if (npp->p_size == 0) {
-			npp->p_fstype = FS_UNUSED;
-		} else {
-			npp->p_fstype = sun_fstypes[i];
-			if (npp->p_fstype == FS_BSDFFS) {
-				/*
-				 * The sun label does not store the FFS fields,
-				 * so just set them with default values here.
-				 */
-				npp->p_fsize = 1024;
-				npp->p_frag = 8;
-				npp->p_cpg = 16;
-			}
-		}
-	}
-
-	lp->d_checksum = 0;
-	lp->d_checksum = dkcksum(lp);
-	return (NULL);
-}
-
-/*
- * Given a BSD disk label, update the Sun disklabel
- * pointed to by cp with the new info.  Note that the
- * Sun disklabel may have other info we need to keep.
- * Returns zero or error code.
- */
-static int
-disklabel_bsd_to_sun(lp, cp)
-	struct disklabel *lp;
-	char *cp;
-{
-	struct sun_disklabel *sl;
-	struct partition *npp;
-	struct sun_dkpart *spp;
-	int i, secpercyl;
-	u_short cksum, *sp1, *sp2;
-
-	if (lp->d_secsize != 512)
-		return (EINVAL);
-
-	sl = (struct sun_disklabel *)cp;
-
-	/*
-	 * Format conversion.
-	 */
-	memcpy(sl->sl_text, lp->d_packname, sizeof(lp->d_packname));
-	sl->sl_rpm = lp->d_rpm;
-	sl->sl_pcylinders   = lp->d_ncylinders + lp->d_acylinders; /* XXX */
-	sl->sl_sparespercyl = lp->d_sparespercyl;
-	sl->sl_interleave   = lp->d_interleave;
-	sl->sl_ncylinders   = lp->d_ncylinders;
-	sl->sl_acylinders   = lp->d_acylinders;
-	sl->sl_ntracks      = lp->d_ntracks;
-	sl->sl_nsectors     = lp->d_nsectors;
-
-	secpercyl = sl->sl_nsectors * sl->sl_ntracks;
-	for (i = 0; i < 8; i++) {
-		spp = &sl->sl_part[i];
-		npp = &lp->d_partitions[i];
-
-		/*
-		 * SunOS partitions must start on a cylinder boundary.
-		 * Note this restriction is forced upon NetBSD/sparc
-		 * labels too, since we want to keep both labels
-		 * synchronised.
-		 */
-		if (npp->p_offset % secpercyl)
-			return (EINVAL);
-		spp->sdkp_cyloffset = npp->p_offset / secpercyl;
-		spp->sdkp_nsectors = npp->p_size;
-	}
-	sl->sl_magic = SUN_DKMAGIC;
-
-	/* Compute the XOR check. */
-	sp1 = (u_short *)sl;
-	sp2 = (u_short *)(sl + 1);
-	sl->sl_cksum = cksum = 0;
-	while (sp1 < sp2)
-		cksum ^= *sp1++;
-	sl->sl_cksum = cksum;
-
-	return (0);
-}
-
-/*
- * Search the bad sector table looking for the specified sector.
- * Return index if found.
- * Return -1 if not found.
- */
-int
-isbad(bt, cyl, trk, sec)
-	struct dkbad *bt;
-	int cyl, trk, sec;
-{
-	int i;
-	long blk, bblk;
-
-	blk = ((long)cyl << 16) + (trk << 8) + sec;
-	for (i = 0; i < 126; i++) {
-		bblk = ((long)bt->bt_bad[i].bt_cyl << 16) +
-			bt->bt_bad[i].bt_trksec;
-		if (blk == bblk)
-			return (i);
-		if (blk < bblk || bblk < 0)
-			break;
-	}
-	return (-1);
-}
Index: sys/arch/sparc64/conf/files.sparc64
===================================================================
RCS file: /cvsroot/src/sys/arch/sparc64/conf/files.sparc64,v
retrieving revision 1.83
diff -u -r1.83 files.sparc64
--- sys/arch/sparc64/conf/files.sparc64	2003/10/26 08:07:27	1.83
+++ sys/arch/sparc64/conf/files.sparc64	2003/11/06 20:06:50
@@ -162,6 +162,7 @@
 file	dev/cons.c
 file	arch/sparc64/dev/consinit.c
 file	kern/kern_microtime.c
+file	dev/sun/disksubr.c 
 
 file	arch/sparc/fpu/fpu.c
 file	arch/sparc/fpu/fpu_add.c
@@ -192,7 +193,6 @@
 file	arch/sparc64/sparc64/sys_machdep.c
 file	arch/sparc64/sparc64/trap.c
 file	arch/sparc64/sparc64/vm_machdep.c
-file	arch/sparc64/sparc64/disksubr.c
 
 file	arch/sparc64/sparc64/db_interface.c	ddb | kgdb
 file	arch/sparc64/sparc64/db_trace.c	ddb
Index: sys/arch/sparc64/sparc64/disksubr.c
===================================================================
RCS file: disksubr.c
diff -N disksubr.c
--- /tmp/cvs20401ak	Thu Nov  6 20:13:07 2003
+++ /dev/null	Mon Aug 30 16:41:34 1999
@@ -1,467 +0,0 @@
-/*	$NetBSD: disksubr.c,v 1.18 2003/07/15 03:36:08 lukem Exp $ */
-
-/*
- * Copyright (c) 1994, 1995 Gordon W. Ross
- * Copyright (c) 1994 Theo de Raadt
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *      This product includes software developed by Theo de Raadt.
- * 4. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: disksubr.c,v 1.18 2003/07/15 03:36:08 lukem Exp $");
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/buf.h>
-#include <sys/ioccom.h>
-#include <sys/device.h>
-#include <sys/disklabel.h>
-#include <sys/disk.h>
-#include <sys/dkbad.h>
-
-#include <dev/scsipi/scsi_all.h>
-#include <dev/scsipi/scsipi_all.h>
-#include <dev/scsipi/scsiconf.h>
-
-#include <dev/sun/disklabel.h>
-
-#include <machine/autoconf.h>
-#include <machine/cpu.h>
-#if defined(SUN4)
-#include <machine/oldmon.h>
-#endif
-
-#include <dev/sbus/sbusvar.h>
-
-static	char *disklabel_sun_to_bsd __P((char *, struct disklabel *));
-static	int disklabel_bsd_to_sun __P((struct disklabel *, char *));
-
-extern struct device *bootdv;
-
-/*
- * Attempt to read a disk label from a device
- * using the indicated strategy routine.
- * The label must be partly set up before this:
- * secpercyl, secsize and anything required for a block i/o read
- * operation in the driver's strategy/start routines
- * must be filled in before calling us.
- *
- * Return buffer for use in signalling errors if requested.
- *
- * Returns null on success and an error string on failure.
- */
-const char *
-readdisklabel(dev, strat, lp, clp)
-	dev_t dev;
-	void (*strat) __P((struct buf *));
-	struct disklabel *lp;
-	struct cpu_disklabel *clp;
-{
-	struct buf *bp;
-	struct disklabel *dlp;
-	struct sun_disklabel *slp;
-	int error;
-
-	/* minimal requirements for archtypal disk label */
-	if (lp->d_secperunit == 0)
-		lp->d_secperunit = 0x1fffffff;
-	if (lp->d_npartitions == 0) {
-		lp->d_npartitions = RAW_PART + 1;
-		if (lp->d_partitions[RAW_PART].p_size == 0)
-			lp->d_partitions[RAW_PART].p_size = 0x1fffffff;
-		lp->d_partitions[RAW_PART].p_offset = 0;
-	}
-
-	/* obtain buffer to probe drive with */
-	bp = geteblk((int)lp->d_secsize);
-
-	/* next, dig out disk label */
-	bp->b_dev = dev;
-	bp->b_blkno = LABELSECTOR;
-	bp->b_cylinder = 0;
-	bp->b_bcount = lp->d_secsize;
-	bp->b_flags |= B_READ;
-	(*strat)(bp);
-
-	/* if successful, locate disk label within block and validate */
-	error = biowait(bp);
-	if (error == 0) {
-		/* Save the whole block in case it has info we need. */
-		bcopy(bp->b_data, clp->cd_block, sizeof(clp->cd_block));
-	}
-	brelse(bp);
-	if (error)
-		return ("disk label read error");
-
-	/* Check for a NetBSD disk label. */
-	dlp = (struct disklabel *) (clp->cd_block + LABELOFFSET);
-	if (dlp->d_magic == DISKMAGIC) {
-		if (dkcksum(dlp))
-			return ("NetBSD disk label corrupted");
-		*lp = *dlp;
-		return (NULL);
-	}
-
-	/* Check for a Sun disk label (for PROM compatibility). */
-	slp = (struct sun_disklabel *) clp->cd_block;
-	if (slp->sl_magic == SUN_DKMAGIC)
-		return (disklabel_sun_to_bsd(clp->cd_block, lp));
-
-
-	bzero(clp->cd_block, sizeof(clp->cd_block));
-	return ("no disk label");
-}
-
-/*
- * Check new disk label for sensibility
- * before setting it.
- */
-int
-setdisklabel(olp, nlp, openmask, clp)
-	struct disklabel *olp, *nlp;
-	u_long openmask;
-	struct cpu_disklabel *clp;
-{
-	int i;
-	struct partition *opp, *npp;
-
-	/* sanity clause */
-	if (nlp->d_secpercyl == 0 || nlp->d_secsize == 0 ||
-	    (nlp->d_secsize % DEV_BSIZE) != 0)
-		return(EINVAL);
-
-	/* special case to allow disklabel to be invalidated */
-	if (nlp->d_magic == 0xffffffff) {
-		*olp = *nlp;
-		return (0);
-	}
-
-	if (nlp->d_magic != DISKMAGIC || nlp->d_magic2 != DISKMAGIC ||
-	    dkcksum(nlp) != 0)
-		return (EINVAL);
-
-	while ((i = ffs(openmask)) != 0) {
-		i--;
-		openmask &= ~(1 << i);
-		if (nlp->d_npartitions <= i)
-			return (EBUSY);
-		opp = &olp->d_partitions[i];
-		npp = &nlp->d_partitions[i];
-		if (npp->p_offset != opp->p_offset || npp->p_size < opp->p_size)
-			return (EBUSY);
-	}
-
-	*olp = *nlp;
-	return (0);
-}
-
-/*
- * Write disk label back to device after modification.
- * Current label is already in clp->cd_block[]
- */
-int
-writedisklabel(dev, strat, lp, clp)
-	dev_t dev;
-	void (*strat) __P((struct buf *));
-	struct disklabel *lp;
-	struct cpu_disklabel *clp;
-{
-	struct buf *bp;
-	int error;
-	struct disklabel *dlp;
-	struct sun_disklabel *slp;
-
-	/*
-	 * Embed native label in a piece of wasteland.
-	 */
-	if (sizeof(struct disklabel) > sizeof slp->sl_bsdlabel)
-		return EFBIG;
-
-	slp = (struct sun_disklabel *)clp->cd_block;
-	bzero(slp->sl_bsdlabel, sizeof(slp->sl_bsdlabel));
-	dlp = (struct disklabel *)slp->sl_bsdlabel;
-	*dlp = *lp;
-
-	/* Build a SunOS compatible label around the native label */
-	error = disklabel_bsd_to_sun(lp, clp->cd_block);
-	if (error)
-		return (error);
-
-	/* Get a buffer and copy the new label into it. */
-	bp = geteblk((int)lp->d_secsize);
-	bcopy(clp->cd_block, bp->b_data, sizeof(clp->cd_block));
-
-	/* Write out the updated label. */
-	bp->b_dev = dev;
-	bp->b_blkno = LABELSECTOR;
-	bp->b_cylinder = 0;
-	bp->b_bcount = lp->d_secsize;
-	bp->b_flags |= B_WRITE;
-	(*strat)(bp);
-	error = biowait(bp);
-	brelse(bp);
-
-	return (error);
-}
-
-/*
- * Determine the size of the transfer, and make sure it is
- * within the boundaries of the partition. Adjust transfer
- * if needed, and signal errors or early completion.
- */
-int
-bounds_check_with_label(dk, bp, wlabel)
-	struct disk *dk;
-	struct buf *bp;
-	int wlabel;
-{
-	struct disklabel *lp = dk->dk_label;
-	struct partition *p = lp->d_partitions + DISKPART(bp->b_dev);
-	int maxsz = p->p_size;
-	int sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT;
-
-	/*
-	 * overwriting disk label ?
-	 * The label is always in sector LABELSECTOR.
-	 * XXX should also protect bootstrap in first 8K
-	 */
-	if (bp->b_blkno + p->p_offset <= LABELSECTOR &&
-	    (bp->b_flags & B_READ) == 0 && wlabel == 0) {
-		bp->b_error = EROFS;
-		goto bad;
-	}
-
-	/* beyond partition? */
-	if (bp->b_blkno < 0 || bp->b_blkno + sz > maxsz) {
-		/* if exactly at end of disk, return an EOF */
-		if (bp->b_blkno == maxsz) {
-			bp->b_resid = bp->b_bcount;
-			return(0);
-		}
-		/* or truncate if part of it fits */
-		sz = maxsz - bp->b_blkno;
-		if (sz <= 0) {
-			bp->b_error = EINVAL;
-			goto bad;
-		}
-		bp->b_bcount = sz << DEV_BSHIFT;
-	}
-
-	/* calculate cylinder for disksort to order transfers with */
-	bp->b_resid = (bp->b_blkno + p->p_offset) / lp->d_secpercyl;
-	return(1);
-bad:
-	bp->b_flags |= B_ERROR;
-	return(-1);
-}
-
-/************************************************************************
- *
- * The rest of this was taken from arch/sparc/scsi/sun_disklabel.c
- * and then substantially rewritten by Gordon W. Ross
- *
- ************************************************************************/
-
-/* What partition types to assume for Sun disklabels: */
-static u_char
-sun_fstypes[8] = {
-	FS_BSDFFS,	/* a */
-	FS_SWAP,	/* b */
-	FS_OTHER,	/* c - whole disk */
-	FS_BSDFFS,	/* d */
-	FS_BSDFFS,	/* e */
-	FS_BSDFFS,	/* f */
-	FS_BSDFFS,	/* g */
-	FS_BSDFFS,	/* h */
-};
-
-/*
- * Given a SunOS disk label, set lp to a BSD disk label.
- * Returns NULL on success, else an error string.
- *
- * The BSD label is cleared out before this is called.
- */
-static char *
-disklabel_sun_to_bsd(cp, lp)
-	char *cp;
-	struct disklabel *lp;
-{
-	struct sun_disklabel *sl;
-	struct partition *npp;
-	struct sun_dkpart *spp;
-	int i, secpercyl;
-	u_short cksum, *sp1, *sp2;
-
-	sl = (struct sun_disklabel *)cp;
-
-	/* Verify the XOR check. */
-	sp1 = (u_short *)sl;
-	sp2 = (u_short *)(sl + 1);
-	cksum = 0;
-	while (sp1 < sp2)
-		cksum ^= *sp1++;
-	if (cksum != 0)
-		return("SunOS disk label, bad checksum");
-
-	/* Format conversion. */
-	lp->d_magic = DISKMAGIC;
-	lp->d_magic2 = DISKMAGIC;
-	memcpy(lp->d_packname, sl->sl_text, sizeof(lp->d_packname));
-
-	lp->d_secsize = 512;
-	lp->d_nsectors   = sl->sl_nsectors;
-	lp->d_ntracks    = sl->sl_ntracks;
-	lp->d_ncylinders = sl->sl_ncylinders;
-
-	secpercyl = sl->sl_nsectors * sl->sl_ntracks;
-	lp->d_secpercyl  = secpercyl;
-	lp->d_secperunit = secpercyl * sl->sl_ncylinders;
-
-	lp->d_sparespercyl = sl->sl_sparespercyl;
-	lp->d_acylinders   = sl->sl_acylinders;
-	lp->d_rpm          = sl->sl_rpm;
-	lp->d_interleave   = sl->sl_interleave;
-
-	lp->d_npartitions = 8;
-	/* These are as defined in <ufs/ffs/fs.h> */
-	lp->d_bbsize = 8192;	/* XXX */
-	lp->d_sbsize = 8192;	/* XXX */
-
-	for (i = 0; i < 8; i++) {
-		spp = &sl->sl_part[i];
-		npp = &lp->d_partitions[i];
-		npp->p_offset = spp->sdkp_cyloffset * secpercyl;
-		npp->p_size = spp->sdkp_nsectors;
-		if (npp->p_size == 0) {
-			npp->p_fstype = FS_UNUSED;
-		} else {
-			npp->p_fstype = sun_fstypes[i];
-			if (npp->p_fstype == FS_BSDFFS) {
-				/*
-				 * The sun label does not store the FFS fields,
-				 * so just set them with default values here.
-				 */
-				npp->p_fsize = 1024;
-				npp->p_frag = 8;
-				npp->p_cpg = 16;
-			}
-		}
-	}
-
-	lp->d_checksum = 0;
-	lp->d_checksum = dkcksum(lp);
-	return (NULL);
-}
-
-/*
- * Given a BSD disk label, update the Sun disklabel
- * pointed to by cp with the new info.  Note that the
- * Sun disklabel may have other info we need to keep.
- * Returns zero or error code.
- */
-static int
-disklabel_bsd_to_sun(lp, cp)
-	struct disklabel *lp;
-	char *cp;
-{
-	struct sun_disklabel *sl;
-	struct partition *npp;
-	struct sun_dkpart *spp;
-	int i, secpercyl;
-	u_short cksum, *sp1, *sp2;
-
-	if (lp->d_secsize != 512)
-		return (EINVAL);
-
-	sl = (struct sun_disklabel *)cp;
-
-	/*
-	 * Format conversion.
-	 */
-	memcpy(sl->sl_text, lp->d_packname, sizeof(lp->d_packname));
-	sl->sl_rpm = lp->d_rpm;
-	sl->sl_pcylinders   = lp->d_ncylinders + lp->d_acylinders; /* XXX */
-	sl->sl_sparespercyl = lp->d_sparespercyl;
-	sl->sl_interleave   = lp->d_interleave;
-	sl->sl_ncylinders   = lp->d_ncylinders;
-	sl->sl_acylinders   = lp->d_acylinders;
-	sl->sl_ntracks      = lp->d_ntracks;
-	sl->sl_nsectors     = lp->d_nsectors;
-
-	secpercyl = sl->sl_nsectors * sl->sl_ntracks;
-	for (i = 0; i < 8; i++) {
-		spp = &sl->sl_part[i];
-		npp = &lp->d_partitions[i];
-
-		/*
-		 * SunOS partitions must start on a cylinder boundary.
-		 * Note this restriction is forced upon NetBSD/sparc
-		 * labels too, since we want to keep both labels
-		 * synchronised.
-		 */
-		if (npp->p_offset % secpercyl)
-			return (EINVAL);
-		spp->sdkp_cyloffset = npp->p_offset / secpercyl;
-		spp->sdkp_nsectors = npp->p_size;
-	}
-	sl->sl_magic = SUN_DKMAGIC;
-
-	/* Compute the XOR check. */
-	sp1 = (u_short *)sl;
-	sp2 = (u_short *)(sl + 1);
-	sl->sl_cksum = cksum = 0;
-	while (sp1 < sp2)
-		cksum ^= *sp1++;
-	sl->sl_cksum = cksum;
-
-	return (0);
-}
-
-/*
- * Search the bad sector table looking for the specified sector.
- * Return index if found.
- * Return -1 if not found.
- */
-int
-isbad(bt, cyl, trk, sec)
-	struct dkbad *bt;
-	int cyl, trk, sec;
-{
-	int i;
-	long blk, bblk;
-
-	blk = ((long)cyl << 16) + (trk << 8) + sec;
-	for (i = 0; i < 126; i++) {
-		bblk = ((long)bt->bt_bad[i].bt_cyl << 16) +
-			bt->bt_bad[i].bt_trksec;
-		if (blk == bblk)
-			return (i);
-		if (blk < bblk || bblk < 0)
-			break;
-	}
-	return (-1);
-}
Index: sys/arch/sun3/conf/files.sun3
===================================================================
RCS file: /cvsroot/src/sys/arch/sun3/conf/files.sun3,v
retrieving revision 1.70
diff -u -r1.70 files.sun3
--- sys/arch/sun3/conf/files.sun3	2003/07/27 01:19:33	1.70
+++ sys/arch/sun3/conf/files.sun3	2003/11/06 20:06:51
@@ -34,7 +34,6 @@
 file arch/sun3/sun3/autoconf.c
 file arch/sun3/sun3/db_machdep.c		ddb
 file arch/sun3/sun3/db_memrw.c			ddb | kgdb
-file arch/sun3/sun3/disksubr.c
 file arch/sun3/sun3/fpu.c
 file arch/sun3/sun3/isr.c
 file arch/sun3/sun3/leds.c
@@ -47,6 +46,7 @@
 file arch/m68k/m68k/cacheops.c			_sun3x_
 file arch/m68k/m68k/kgdb_machdep.c 		kgdb
 file arch/m68k/m68k/vm_machdep.c
+file dev/sun/disksubr.c
 
 include "arch/m68k/fpe/files.fpe"
 
Index: sys/arch/sun3/include/disklabel.h
===================================================================
RCS file: /cvsroot/src/sys/arch/sun3/include/disklabel.h,v
retrieving revision 1.5
diff -u -r1.5 disklabel.h
--- sys/arch/sun3/include/disklabel.h	1998/10/24 16:22:58	1.5
+++ sys/arch/sun3/include/disklabel.h	2003/11/06 20:06:51
@@ -34,7 +34,7 @@
 #define _MACHINE_DISKLABEL_H_
 
 #define	LABELSECTOR	0			/* sector containing label */
-#define	LABELOFFSET	64			/* offset of label in sector */
+#define	LABELOFFSET	128			/* offset of label in sector */
 #define	MAXPARTITIONS	8			/* number of partitions */
 #define	RAW_PART	2			/* raw partition: xx?c */
 
Index: sys/arch/sun3/sun3/disksubr.c
===================================================================
RCS file: disksubr.c
diff -N disksubr.c
--- /tmp/cvs20401an	Thu Nov  6 20:13:10 2003
+++ /dev/null	Mon Aug 30 16:41:34 1999
@@ -1,516 +0,0 @@
-/*	$NetBSD: disksubr.c,v 1.33 2003/08/07 16:29:57 agc Exp $	*/
-
-/*
- * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * Credits:
- * This file was based mostly on the i386/disksubr.c file:
- *  	@(#)ufs_disksubr.c	7.16 (Berkeley) 5/4/91
- * The functions: disklabel_sun_to_bsd, disklabel_bsd_to_sun
- * were originally taken from arch/sparc/scsi/sun_disklabel.c
- * (which was written by Theo de Raadt) and then substantially
- * rewritten by Gordon W. Ross.
- */
-
-/*
- * Copyright (c) 1994, 1995 Gordon W. Ross
- * Copyright (c) 1994 Theo de Raadt
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * Credits:
- * This file was based mostly on the i386/disksubr.c file:
- *  	@(#)ufs_disksubr.c	7.16 (Berkeley) 5/4/91
- * The functions: disklabel_sun_to_bsd, disklabel_bsd_to_sun
- * were originally taken from arch/sparc/scsi/sun_disklabel.c
- * (which was written by Theo de Raadt) and then substantially
- * rewritten by Gordon W. Ross.
- */
-
-#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: disksubr.c,v 1.33 2003/08/07 16:29:57 agc Exp $");
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/buf.h>
-#include <sys/device.h>
-#include <sys/disklabel.h>
-#include <sys/disk.h>
-#include <sys/dkbad.h>
-
-#include <dev/sun/disklabel.h>
-
-#if LABELSECTOR != 0
-#error	"Default value of LABELSECTOR no longer zero?"
-#endif
-
-static char * disklabel_sun_to_bsd(char *, struct disklabel *);
-static int disklabel_bsd_to_sun(struct disklabel *, char *);
-
-/*
- * Attempt to read a disk label from a device
- * using the indicated strategy routine.
- * The label must be partly set up before this:
- * secpercyl, secsize and anything required for a block i/o read
- * operation in the driver's strategy/start routines
- * must be filled in before calling us.
- *
- * Return buffer for use in signalling errors if requested.
- *
- * Returns null on success and an error string on failure.
- */
-const char *
-readdisklabel(dev, strat, lp, clp)
-	dev_t dev;
-	void (*strat) __P((struct buf *));
-	struct disklabel *lp;
-	struct cpu_disklabel *clp;
-{
-	struct buf *bp;
-	struct disklabel *dlp;
-	struct sun_disklabel *slp;
-	int error;
-
-	/* minimal requirements for archtypal disk label */
-	if (lp->d_secperunit == 0)
-		lp->d_secperunit = 0x1fffffff;
-	lp->d_npartitions = RAW_PART + 1;
-	if (lp->d_partitions[0].p_size == 0)
-		lp->d_partitions[0].p_size = 0x1fffffff;
-	lp->d_partitions[0].p_offset = 0;
-
-	/* obtain buffer to probe drive with */
-	bp = geteblk((int)lp->d_secsize);
-
-	/* next, dig out disk label */
-	bp->b_dev = dev;
-	bp->b_blkno = LABELSECTOR;
-	bp->b_cylinder = 0;
-	bp->b_bcount = lp->d_secsize;
-	bp->b_flags |= B_READ;
-	(*strat)(bp);
-
-	/* if successful, locate disk label within block and validate */
-	error = biowait(bp);
-	if (!error) {
-		/* Save the whole block in case it has info we need. */
-		memcpy(clp->cd_block, bp->b_data, sizeof(clp->cd_block));
-	}
-	brelse(bp);
-	if (error)
-		return("disk label read error");
-
-	/* Check for a Sun disk label (for PROM compatibility). */
-	slp = (struct sun_disklabel *) clp->cd_block;
-	if (slp->sl_magic == SUN_DKMAGIC) {
-		return(disklabel_sun_to_bsd(clp->cd_block, lp));
-	}
-
-	/* Check for a NetBSD disk label (PROM can not boot it). */
-	for (dlp = (struct disklabel *)clp->cd_block;
-	    dlp <= (struct disklabel *)((char *)clp->cd_block +
-	    DEV_BSIZE - sizeof(*dlp));
-	    dlp = (struct disklabel *)((char *)dlp + sizeof(long))) {
-		if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) {
-			continue;
-		}
-		if (dlp->d_npartitions > MAXPARTITIONS || dkcksum(dlp) != 0)
-			return("BSD disk label corrupted");
-		else {
-			*lp = *dlp;
-			return(NULL); 
-		}
-	}
-
-#if 0
-	dlp = (struct disklabel *) (clp->cd_block + LABELOFFSET);
-	if (dlp->d_magic == DISKMAGIC) {
-		if (dkcksum(dlp))
-			return("NetBSD disk label corrupted");
-		*lp = *dlp; 	/* struct assignment */
-		return(NULL);
-	}
-#endif
-
-	memset(clp->cd_block, 0, sizeof(clp->cd_block));
-	return("no disk label");
-}
-
-/*
- * Check new disk label for sensibility
- * before setting it.
- */
-int
-setdisklabel(olp, nlp, openmask, clp)
-	struct disklabel *olp, *nlp;
-	u_long openmask;
-	struct cpu_disklabel *clp;
-{
-	struct partition *opp, *npp;
-	int i;
-
-	/* sanity clause */
-	if ((nlp->d_secpercyl == 0) || (nlp->d_secsize == 0) ||
-	    (nlp->d_secsize % DEV_BSIZE) != 0)
-		return(EINVAL);
-
-	/* special case to allow disklabel to be invalidated */
-	if (nlp->d_magic == 0xffffffff) {
-		*olp = *nlp;
-		return (0);
-	}
-
-	if (nlp->d_magic != DISKMAGIC ||
-	    nlp->d_magic2 != DISKMAGIC ||
-	    dkcksum(nlp) != 0)
-		return (EINVAL);
-
-	while (openmask != 0) {
-		i = ffs(openmask) - 1;
-		openmask &= ~(1 << i);
-		if (nlp->d_npartitions <= i)
-			return (EBUSY);
-		opp = &olp->d_partitions[i];
-		npp = &nlp->d_partitions[i];
-		if (npp->p_offset != opp->p_offset ||
-		    npp->p_size   <  opp->p_size)
-			return (EBUSY);
-	}
-
-	/* We did not modify the new label, so the checksum is OK. */
-	*olp = *nlp;
-	return (0);
-}
-
-
-/*
- * Write disk label back to device after modification.
- * Current label is already in clp->cd_block[]
- */
-int
-writedisklabel(dev, strat, lp, clp)
-	dev_t dev;
-	void (*strat) __P((struct buf *));
-	struct disklabel *lp;
-	struct cpu_disklabel *clp;
-{
-	struct buf *bp;
-	int error;
-
-	error = disklabel_bsd_to_sun(lp, clp->cd_block);
-	if (error)
-		return(error);
-
-#if 0	/* XXX - Allow writing NetBSD disk labels? */
-	{
-		struct disklabel *dlp;
-		dlp = (struct disklabel *)(clp->cd_block + LABELOFFSET);
-		*dlp = *lp; 	/* struct assignment */
-	}
-#endif
-
-	/* Get a buffer and copy the new label into it. */
-	bp = geteblk((int)lp->d_secsize);
-	memcpy(bp->b_data, clp->cd_block, sizeof(clp->cd_block));
-
-	/* Write out the updated label. */
-	bp->b_dev = dev;
-	bp->b_blkno = LABELSECTOR;
-	bp->b_cylinder = 0;
-	bp->b_bcount = lp->d_secsize;
-	bp->b_flags |= B_WRITE;
-	(*strat)(bp);
-	error = biowait(bp);
-	brelse(bp);
-
-	return (error);
-}
-
-/*
- * Determine the size of the transfer, and make sure it is
- * within the boundaries of the partition. Adjust transfer
- * if needed, and signal errors or early completion.
- */
-int
-bounds_check_with_label(dk, bp, wlabel)
-	struct disk *dk;
-	struct buf *bp;
-	int wlabel;
-{
-	struct disklabel *lp = dk->dk_label;
-	struct partition *p;
-	int sz, maxsz;
-
-	p = lp->d_partitions + DISKPART(bp->b_dev);
-	maxsz = p->p_size;
-	sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT;
-
-	/* overwriting disk label ? */
-	/* XXX should also protect bootstrap in first 8K */
-	/* XXX PR#2598: labelsect is always sector zero. */
-	if (((bp->b_blkno + p->p_offset) <= LABELSECTOR) &&
-	    ((bp->b_flags & B_READ) == 0) && (wlabel == 0))
-	{
-		bp->b_error = EROFS;
-		goto bad;
-	}
-
-	/* beyond partition? */
-	if (bp->b_blkno < 0 || bp->b_blkno + sz > maxsz) {
-		/* if exactly at end of disk, return an EOF */
-		if (bp->b_blkno == maxsz) {
-			bp->b_resid = bp->b_bcount;
-			return(0);
-		}
-		/* or truncate if part of it fits */
-		sz = maxsz - bp->b_blkno;
-		if (sz <= 0) {
-			bp->b_error = EINVAL;
-			goto bad;
-		}
-		bp->b_bcount = sz << DEV_BSHIFT;
-	}
-
-	/* calculate cylinder for disksort to order transfers with */
-	bp->b_cylinder = (bp->b_blkno + p->p_offset) / lp->d_secpercyl;
-	return(1);
-
-bad:
-	bp->b_flags |= B_ERROR;
-	return(-1);
-}
-
-/************************************************************************
- *
- * The rest of this was taken from arch/sparc/scsi/sun_disklabel.c
- * and then substantially rewritten by Gordon W. Ross
- *
- ************************************************************************/
-
-/* What partition types to assume for Sun disklabels: */
-static u_char
-sun_fstypes[8] = {
-	FS_BSDFFS,	/* a */
-	FS_SWAP,	/* b */
-	FS_OTHER,	/* c - whole disk */
-	FS_BSDFFS,	/* d */
-	FS_BSDFFS,	/* e */
-	FS_BSDFFS,	/* f */
-	FS_BSDFFS,	/* g */
-	FS_BSDFFS,	/* h */
-};
-
-/*
- * Given a SunOS disk label, set lp to a BSD disk label.
- * Returns NULL on success, else an error string.
- *
- * The BSD label is cleared out before this is called.
- */
-static char *
-disklabel_sun_to_bsd(cp, lp)
-	char *cp;
-	struct disklabel *lp;
-{
-	struct sun_disklabel *sl;
-	struct partition *npp;
-	struct sun_dkpart *spp;
-	int i, secpercyl;
-	u_short cksum, *sp1, *sp2;
-
-	sl = (struct sun_disklabel *)cp;
-
-	/* Verify the XOR check. */
-	sp1 = (u_short *)sl;
-	sp2 = (u_short *)(sl + 1);
-	cksum = 0;
-	while (sp1 < sp2)
-		cksum ^= *sp1++;
-	if (cksum != 0)
-		return("SunOS disk label, bad checksum");
-
-	/* Format conversion. */
-	lp->d_magic = DISKMAGIC;
-	lp->d_magic2 = DISKMAGIC;
-	memcpy(lp->d_packname, sl->sl_text, sizeof(lp->d_packname));
-
-	lp->d_secsize = 512;
-	lp->d_nsectors   = sl->sl_nsectors;
-	lp->d_ntracks    = sl->sl_ntracks;
-	lp->d_ncylinders = sl->sl_ncylinders;
-
-	secpercyl = sl->sl_nsectors * sl->sl_ntracks;
-	lp->d_secpercyl  = secpercyl;
-	lp->d_secperunit = secpercyl * sl->sl_ncylinders;
-
-	lp->d_sparespercyl = sl->sl_sparespercyl;
-	lp->d_acylinders   = sl->sl_acylinders;
-	lp->d_rpm          = sl->sl_rpm;
-	lp->d_interleave   = sl->sl_interleave;
-
-	lp->d_npartitions = 8;
-	/* These are as defined in <ufs/ffs/fs.h> */
-	lp->d_bbsize = 8192;	/* XXX */
-	lp->d_sbsize = 8192;	/* XXX */
-
-	for (i = 0; i < 8; i++) {
-		spp = &sl->sl_part[i];
-		npp = &lp->d_partitions[i];
-		npp->p_offset = spp->sdkp_cyloffset * secpercyl;
-		npp->p_size = spp->sdkp_nsectors;
-		if (npp->p_size == 0)
-			npp->p_fstype = FS_UNUSED;
-		else {
-			/* Partition has non-zero size.  Set type, etc. */
-			npp->p_fstype = sun_fstypes[i];
-			/*
-			 * The sun label does not store the FFS fields,
-			 * so just set them with default values here.
-			 * XXX: This keeps newfs from trying to rewrite
-			 * XXX: the disk label in the most common case.
-			 * XXX: (Should remove that code from newfs...)
-			 */
-			if (npp->p_fstype == FS_BSDFFS) {
-				npp->p_fsize = 1024;
-				npp->p_frag = 8;
-				npp->p_cpg = 16;
-			}
-		}
-	}
-
-	lp->d_checksum = 0;
-	lp->d_checksum = dkcksum(lp);
-
-	return(NULL);
-}
-
-/*
- * Given a BSD disk label, update the Sun disklabel
- * pointed to by cp with the new info.  Note that the
- * Sun disklabel may have other info we need to keep.
- * Returns zero or error code.
- */
-static int
-disklabel_bsd_to_sun(lp, cp)
-	struct disklabel *lp;
-	char *cp;
-{
-	struct sun_disklabel *sl;
-	struct partition *npp;
-	struct sun_dkpart *spp;
-	int i, secpercyl;
-	u_short cksum, *sp1, *sp2;
-
-	if (lp->d_secsize != 512)
-	    return (EINVAL);
-
-	sl = (struct sun_disklabel *)cp;
-
-	/* Format conversion. */
-	memcpy(sl->sl_text, lp->d_packname, sizeof(lp->d_packname));
-	sl->sl_rpm = lp->d_rpm;
-	sl->sl_pcyl = lp->d_ncylinders + lp->d_acylinders;	/* XXX */
-	sl->sl_sparespercyl = lp->d_sparespercyl;
-	sl->sl_interleave   = lp->d_interleave;
-	sl->sl_ncylinders   = lp->d_ncylinders;
-	sl->sl_acylinders   = lp->d_acylinders;
-	sl->sl_ntracks      = lp->d_ntracks;
-	sl->sl_nsectors     = lp->d_nsectors;
-
-	secpercyl = sl->sl_nsectors * sl->sl_ntracks;
-	for (i = 0; i < 8; i++) {
-		spp = &sl->sl_part[i];
-		npp = &lp->d_partitions[i];
-
-		if (npp->p_offset % secpercyl)
-			return (EINVAL);
-		spp->sdkp_cyloffset = npp->p_offset / secpercyl;
-		spp->sdkp_nsectors = npp->p_size;
-	}
-	sl->sl_magic = SUN_DKMAGIC;
-
-	/* Correct the XOR check. */
-	sp1 = (u_short *)sl;
-	sp2 = (u_short *)(sl + 1);
-	sl->sl_cksum = cksum = 0;
-	while (sp1 < sp2)
-		cksum ^= *sp1++;
-	sl->sl_cksum = cksum;
-
-	return(0);
-}
-
-/*
- * Search the bad sector table looking for the specified sector.
- * Return index if found.
- * Return -1 if not found.
- */
-int
-isbad(bt, cyl, trk, sec)
-	struct dkbad *bt;
-	int cyl, trk, sec;
-{
-	int i;
-	long blk, bblk;
-
-	blk = ((long)cyl << 16) + (trk << 8) + sec;
-	for (i = 0; i < 126; i++) {
-		bblk = ((long)bt->bt_bad[i].bt_cyl << 16) +
-			bt->bt_bad[i].bt_trksec;
-		if (blk == bblk)
-			return (i);
-		if (blk < bblk || bblk < 0)
-			break;
-	}
-	return (-1);
-}
Index: sys/dev/sun/disksubr.c
===================================================================
RCS file: disksubr.c
diff -N disksubr.c
--- /dev/null	Mon Aug 30 16:41:34 1999
+++ disksubr.c	Thu Nov  6 20:06:56 2003
@@ -0,0 +1,503 @@
+/*	$NetBSD: disksubr.c,v 1.36 2003/07/15 00:05:03 lukem Exp $ */
+
+/* 
+ * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 1994, 1995 Gordon W. Ross
+ * Copyright (c) 1994 Theo de Raadt
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by Theo de Raadt.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: disksubr.c,v 1.36 2003/07/15 00:05:03 lukem Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/buf.h>
+#include <sys/ioccom.h>
+#include <sys/device.h>
+#include <sys/disklabel.h>
+#include <sys/disk.h>
+#include <sys/dkbad.h>
+
+#include <dev/sun/disklabel.h>
+
+#if LABELSECTOR != 0
+#error  "Default value of LABELSECTOR no longer zero?"
+#endif
+
+static	char *disklabel_sun_to_bsd __P((char *, struct disklabel *));
+static	int disklabel_bsd_to_sun __P((struct disklabel *, char *));
+
+/*
+ * Attempt to read a disk label from a device
+ * using the indicated strategy routine.
+ * The label must be partly set up before this:
+ * secpercyl, secsize and anything required for a block i/o read
+ * operation in the driver's strategy/start routines
+ * must be filled in before calling us.
+ *
+ * Return buffer for use in signalling errors if requested.
+ *
+ * Returns null on success and an error string on failure.
+ */
+const char *
+readdisklabel(dev, strat, lp, clp)
+	dev_t dev;
+	void (*strat) __P((struct buf *));
+	struct disklabel *lp;
+	struct cpu_disklabel *clp;
+{
+	struct buf *bp;
+	struct disklabel *dlp;
+	struct sun_disklabel *slp;
+	int error;
+
+	/* minimal requirements for archtypal disk label */
+	if (lp->d_secperunit == 0)
+		lp->d_secperunit = 0x1fffffff;
+	if (lp->d_npartitions == 0) {
+		lp->d_npartitions = RAW_PART + 1;
+		if (lp->d_partitions[RAW_PART].p_size == 0)
+			lp->d_partitions[RAW_PART].p_size = 0x1fffffff;
+		lp->d_partitions[RAW_PART].p_offset = 0;
+	}
+
+	/* obtain buffer to probe drive with */
+	bp = geteblk((int)lp->d_secsize);
+
+	/* next, dig out disk label */
+	bp->b_dev = dev;
+	bp->b_blkno = LABELSECTOR;
+	bp->b_cylinder = 0;
+	bp->b_bcount = lp->d_secsize;
+	bp->b_flags |= B_READ;
+	(*strat)(bp);
+
+	/* if successful, locate disk label within block and validate */
+	error = biowait(bp);
+	if (error == 0) {
+		/* Save the whole block in case it has info we need. */
+		bcopy(bp->b_data, clp->cd_block, sizeof(clp->cd_block));
+	}
+	brelse(bp);
+	if (error)
+		return ("disk label read error");
+
+	/* Check for a NetBSD disk label at LABELOFFSET */
+	dlp = (struct disklabel *) (clp->cd_block + LABELOFFSET);
+	if (dlp->d_magic == DISKMAGIC) {
+		if (dkcksum(dlp))
+			return ("NetBSD disk label corrupted");
+		*lp = *dlp;
+		return (NULL);
+	}
+
+	/* Check for a Sun disk label (for PROM compatibility). */
+	slp = (struct sun_disklabel *) clp->cd_block;
+	if (slp->sl_magic == SUN_DKMAGIC)
+		return (disklabel_sun_to_bsd(clp->cd_block, lp));
+
+	/*
+	 * Check for a NetBSD disk label somewhere in LABELSECTOR
+	 * (compat with others big-endian boxes)
+	 */
+	for (dlp = (struct disklabel *)clp->cd_block;
+	    dlp <= (struct disklabel *)((char *)clp->cd_block +
+	    DEV_BSIZE - sizeof(*dlp));
+	    dlp = (struct disklabel *)((char *)dlp + sizeof(long))) {
+		if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) {
+			continue;
+		}
+		if (dlp->d_npartitions > MAXPARTITIONS || dkcksum(dlp) != 0)
+			return("NetBSD disk label corrupted");
+		else {
+			*lp = *dlp;
+			return(NULL);
+		}
+	}
+
+	bzero(clp->cd_block, sizeof(clp->cd_block));
+	return ("no disk label");
+}
+
+/*
+ * Check new disk label for sensibility
+ * before setting it.
+ */
+int
+setdisklabel(olp, nlp, openmask, clp)
+	struct disklabel *olp, *nlp;
+	u_long openmask;
+	struct cpu_disklabel *clp;
+{
+	int i;
+	struct partition *opp, *npp;
+
+	/* sanity clause */
+	if (nlp->d_secpercyl == 0 || nlp->d_secsize == 0 ||
+	    (nlp->d_secsize % DEV_BSIZE) != 0)
+		return(EINVAL);
+
+	/* special case to allow disklabel to be invalidated */
+	if (nlp->d_magic == 0xffffffff) {
+		*olp = *nlp;
+		return (0);
+	}
+
+	if (nlp->d_magic != DISKMAGIC || nlp->d_magic2 != DISKMAGIC ||
+	    dkcksum(nlp) != 0)
+		return (EINVAL);
+
+	while ((i = ffs(openmask)) != 0) {
+		i--;
+		openmask &= ~(1 << i);
+		if (nlp->d_npartitions <= i)
+			return (EBUSY);
+		opp = &olp->d_partitions[i];
+		npp = &nlp->d_partitions[i];
+		if (npp->p_offset != opp->p_offset || npp->p_size < opp->p_size)
+			return (EBUSY);
+	}
+
+	*olp = *nlp;
+	return (0);
+}
+
+/*
+ * Write disk label back to device after modification.
+ * Current label is already in clp->cd_block[]
+ */
+int
+writedisklabel(dev, strat, lp, clp)
+	dev_t dev;
+	void (*strat) __P((struct buf *));
+	struct disklabel *lp;
+	struct cpu_disklabel *clp;
+{
+	struct buf *bp;
+	int error;
+	struct disklabel *dlp;
+	struct sun_disklabel *slp;
+
+	/*
+	 * Embed native label in a piece of wasteland.
+	 */
+	if (sizeof(struct disklabel) > sizeof slp->sl_bsdlabel)
+		return EFBIG;
+
+	slp = (struct sun_disklabel *)clp->cd_block;
+	bzero(slp->sl_bsdlabel, sizeof(slp->sl_bsdlabel));
+	dlp = (struct disklabel *)slp->sl_bsdlabel;
+	*dlp = *lp;
+
+	/* Build a SunOS compatible label around the native label */
+	error = disklabel_bsd_to_sun(lp, clp->cd_block);
+	if (error)
+		return (error);
+
+	/* Get a buffer and copy the new label into it. */
+	bp = geteblk((int)lp->d_secsize);
+	bcopy(clp->cd_block, bp->b_data, sizeof(clp->cd_block));
+
+	/* Write out the updated label. */
+	bp->b_dev = dev;
+	bp->b_blkno = LABELSECTOR;
+	bp->b_cylinder = 0;
+	bp->b_bcount = lp->d_secsize;
+	bp->b_flags |= B_WRITE;
+	(*strat)(bp);
+	error = biowait(bp);
+	brelse(bp);
+
+	return (error);
+}
+
+/*
+ * Determine the size of the transfer, and make sure it is
+ * within the boundaries of the partition. Adjust transfer
+ * if needed, and signal errors or early completion.
+ */
+int
+bounds_check_with_label(dk, bp, wlabel)
+	struct disk *dk;
+	struct buf *bp;
+	int wlabel;
+{
+	struct disklabel *lp = dk->dk_label;
+	struct partition *p = lp->d_partitions + DISKPART(bp->b_dev);
+	int maxsz = p->p_size;
+	int sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT;
+
+	/*
+	 * overwriting disk label ?
+	 * The label is always in sector LABELSECTOR.
+	 * XXX should also protect bootstrap in first 8K
+	 */
+	if (bp->b_blkno + p->p_offset <= LABELSECTOR &&
+	    (bp->b_flags & B_READ) == 0 && wlabel == 0) {
+		bp->b_error = EROFS;
+		goto bad;
+	}
+
+	/* beyond partition? */
+	if (bp->b_blkno < 0 || bp->b_blkno + sz > maxsz) {
+		/* if exactly at end of disk, return an EOF */
+		if (bp->b_blkno == maxsz) {
+			bp->b_resid = bp->b_bcount;
+			return(0);
+		}
+		/* or truncate if part of it fits */
+		sz = maxsz - bp->b_blkno;
+		if (sz <= 0) {
+			bp->b_error = EINVAL;
+			goto bad;
+		}
+		bp->b_bcount = sz << DEV_BSHIFT;
+	}
+
+	/* calculate cylinder for disksort to order transfers with */
+	bp->b_resid = (bp->b_blkno + p->p_offset) / lp->d_secpercyl;
+	return(1);
+bad:
+	bp->b_flags |= B_ERROR;
+	return(-1);
+}
+
+/************************************************************************
+ *
+ * The rest of this was taken from arch/sparc/scsi/sun_disklabel.c
+ * and then substantially rewritten by Gordon W. Ross
+ *
+ ************************************************************************/
+
+/* What partition types to assume for Sun disklabels: */
+static u_char
+sun_fstypes[8] = {
+	FS_BSDFFS,	/* a */
+	FS_SWAP,	/* b */
+	FS_OTHER,	/* c - whole disk */
+	FS_BSDFFS,	/* d */
+	FS_BSDFFS,	/* e */
+	FS_BSDFFS,	/* f */
+	FS_BSDFFS,	/* g */
+	FS_BSDFFS,	/* h */
+};
+
+/*
+ * Given a SunOS disk label, set lp to a BSD disk label.
+ * Returns NULL on success, else an error string.
+ *
+ * The BSD label is cleared out before this is called.
+ */
+static char *
+disklabel_sun_to_bsd(cp, lp)
+	char *cp;
+	struct disklabel *lp;
+{
+	struct sun_disklabel *sl;
+	struct partition *npp;
+	struct sun_dkpart *spp;
+	int i, secpercyl;
+	u_short cksum, *sp1, *sp2;
+
+	sl = (struct sun_disklabel *)cp;
+
+	/* Verify the XOR check. */
+	sp1 = (u_short *)sl;
+	sp2 = (u_short *)(sl + 1);
+	cksum = 0;
+	while (sp1 < sp2)
+		cksum ^= *sp1++;
+	if (cksum != 0)
+		return("SunOS disk label, bad checksum");
+
+	/* Format conversion. */
+	lp->d_magic = DISKMAGIC;
+	lp->d_magic2 = DISKMAGIC;
+	memcpy(lp->d_packname, sl->sl_text, sizeof(lp->d_packname));
+
+	lp->d_secsize = 512;
+	lp->d_nsectors   = sl->sl_nsectors;
+	lp->d_ntracks    = sl->sl_ntracks;
+	lp->d_ncylinders = sl->sl_ncylinders;
+
+	secpercyl = sl->sl_nsectors * sl->sl_ntracks;
+	lp->d_secpercyl  = secpercyl;
+	lp->d_secperunit = secpercyl * sl->sl_ncylinders;
+
+	lp->d_sparespercyl = sl->sl_sparespercyl;
+	lp->d_acylinders   = sl->sl_acylinders;
+	lp->d_rpm          = sl->sl_rpm;
+	lp->d_interleave   = sl->sl_interleave;
+
+	lp->d_npartitions = 8;
+	/* These are as defined in <ufs/ffs/fs.h> */
+	lp->d_bbsize = 8192;	/* XXX */
+	lp->d_sbsize = 8192;	/* XXX */
+
+	for (i = 0; i < 8; i++) {
+		spp = &sl->sl_part[i];
+		npp = &lp->d_partitions[i];
+		npp->p_offset = spp->sdkp_cyloffset * secpercyl;
+		npp->p_size = spp->sdkp_nsectors;
+		if (npp->p_size == 0) {
+			npp->p_fstype = FS_UNUSED;
+		} else {
+			npp->p_fstype = sun_fstypes[i];
+			if (npp->p_fstype == FS_BSDFFS) {
+				/*
+				 * The sun label does not store the FFS fields,
+				 * so just set them with default values here.
+				 */
+				npp->p_fsize = 1024;
+				npp->p_frag = 8;
+				npp->p_cpg = 16;
+			}
+		}
+	}
+
+	lp->d_checksum = 0;
+	lp->d_checksum = dkcksum(lp);
+	return (NULL);
+}
+
+/*
+ * Given a BSD disk label, update the Sun disklabel
+ * pointed to by cp with the new info.  Note that the
+ * Sun disklabel may have other info we need to keep.
+ * Returns zero or error code.
+ */
+static int
+disklabel_bsd_to_sun(lp, cp)
+	struct disklabel *lp;
+	char *cp;
+{
+	struct sun_disklabel *sl;
+	struct partition *npp;
+	struct sun_dkpart *spp;
+	int i, secpercyl;
+	u_short cksum, *sp1, *sp2;
+
+	if (lp->d_secsize != 512)
+		return (EINVAL);
+
+	sl = (struct sun_disklabel *)cp;
+
+	/*
+	 * Format conversion.
+	 */
+	memcpy(sl->sl_text, lp->d_packname, sizeof(lp->d_packname));
+	sl->sl_rpm = lp->d_rpm;
+	sl->sl_pcylinders   = lp->d_ncylinders + lp->d_acylinders; /* XXX */
+	sl->sl_sparespercyl = lp->d_sparespercyl;
+	sl->sl_interleave   = lp->d_interleave;
+	sl->sl_ncylinders   = lp->d_ncylinders;
+	sl->sl_acylinders   = lp->d_acylinders;
+	sl->sl_ntracks      = lp->d_ntracks;
+	sl->sl_nsectors     = lp->d_nsectors;
+
+	secpercyl = sl->sl_nsectors * sl->sl_ntracks;
+	for (i = 0; i < 8; i++) {
+		spp = &sl->sl_part[i];
+		npp = &lp->d_partitions[i];
+
+		/*
+		 * SunOS partitions must start on a cylinder boundary.
+		 * Note this restriction is forced upon NetBSD/sparc
+		 * labels too, since we want to keep both labels
+		 * synchronised.
+		 */
+		if (npp->p_offset % secpercyl)
+			return (EINVAL);
+		spp->sdkp_cyloffset = npp->p_offset / secpercyl;
+		spp->sdkp_nsectors = npp->p_size;
+	}
+	sl->sl_magic = SUN_DKMAGIC;
+
+	/* Compute the XOR check. */
+	sp1 = (u_short *)sl;
+	sp2 = (u_short *)(sl + 1);
+	sl->sl_cksum = cksum = 0;
+	while (sp1 < sp2)
+		cksum ^= *sp1++;
+	sl->sl_cksum = cksum;
+
+	return (0);
+}
+
+/*
+ * Search the bad sector table looking for the specified sector.
+ * Return index if found.
+ * Return -1 if not found.
+ */
+int
+isbad(bt, cyl, trk, sec)
+	struct dkbad *bt;
+	int cyl, trk, sec;
+{
+	int i;
+	long blk, bblk;
+
+	blk = ((long)cyl << 16) + (trk << 8) + sec;
+	for (i = 0; i < 126; i++) {
+		bblk = ((long)bt->bt_bad[i].bt_cyl << 16) +
+			bt->bt_bad[i].bt_trksec;
+		if (blk == bblk)
+			return (i);
+		if (blk < bblk || bblk < 0)
+			break;
+	}
+	return (-1);
+}

--/04w6evG8XlLl3ft--