Home | History | Annotate | Line # | Download | only in amiga
disksubr.c revision 1.61
      1 /*	$NetBSD: disksubr.c,v 1.60 2009/09/12 09:18:42 phx Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. Neither the name of the University nor the names of its contributors
     16  *    may be used to endorse or promote products derived from this software
     17  *    without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  *
     31  *	@(#)ufs_disksubr.c	7.16 (Berkeley) 5/4/91
     32  */
     33 
     34 /*
     35  * Copyright (c) 1994 Christian E. Hopps
     36  *
     37  * Redistribution and use in source and binary forms, with or without
     38  * modification, are permitted provided that the following conditions
     39  * are met:
     40  * 1. Redistributions of source code must retain the above copyright
     41  *    notice, this list of conditions and the following disclaimer.
     42  * 2. Redistributions in binary form must reproduce the above copyright
     43  *    notice, this list of conditions and the following disclaimer in the
     44  *    documentation and/or other materials provided with the distribution.
     45  * 3. All advertising materials mentioning features or use of this software
     46  *    must display the following acknowledgement:
     47  *	This product includes software developed by the University of
     48  *	California, Berkeley and its contributors.
     49  * 4. Neither the name of the University nor the names of its contributors
     50  *    may be used to endorse or promote products derived from this software
     51  *    without specific prior written permission.
     52  *
     53  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     54  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     55  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     56  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     57  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     58  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     59  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     60  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     61  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     62  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     63  * SUCH DAMAGE.
     64  *
     65  *	@(#)ufs_disksubr.c	7.16 (Berkeley) 5/4/91
     66  */
     67 
     68 #include <sys/cdefs.h>
     69 __KERNEL_RCSID(0, "$NetBSD: disksubr.c,v 1.60 2009/09/12 09:18:42 phx Exp $");
     70 
     71 #include <sys/param.h>
     72 #include <sys/systm.h>
     73 #include <sys/buf.h>
     74 #include <sys/disklabel.h>
     75 #include <sys/disk.h>
     76 
     77 /*
     78  * In /usr/src/sys/dev/scsipi/sd.c, routine sdstart() adjusts the
     79  * block numbers, it changes from DEV_BSIZE units to physical units:
     80  * blkno = bp->b_blkno / (lp->d_secsize / DEV_BSIZE);
     81  * As long as media with sector sizes of 512 bytes are used, this
     82  * doesn't matter (divide by 1), but for successful usage of media with
     83  * greater sector sizes (e.g. 640MB MO-media with 2048 bytes/sector)
     84  * we must multiply block numbers with (lp->d_secsize / DEV_BSIZE)
     85  * to keep "unchanged" physical block numbers.
     86  */
     87 #define SD_C_ADJUSTS_NR
     88 
     89 /*
     90  * bitmap id's
     91  */
     92 #define RDBLOCK_BID	1
     93 #define PARTBLOCK_BID	2
     94 #define BADBLOCK_BID	3
     95 #define FSBLOCK_BID	4
     96 #define LSEGBLOCK_BID	5
     97 
     98 struct rdbmap {
     99 	long firstblk;
    100 	long lastblk;
    101 	int  bigtype;
    102 	struct {
    103 		short next;
    104 		short prev;
    105 		char  shortid;
    106 	} big[0];
    107 	struct {
    108 		char next;
    109 		char prev;
    110 		char shortid;
    111 	} tab[0];
    112 };
    113 
    114 #define baddr(bp) (void *)((bp)->b_data)
    115 
    116 u_long rdbchksum(void *);
    117 struct adostype getadostype(u_long);
    118 struct rdbmap *getrdbmap(dev_t, void (*)(struct buf *), struct disklabel *,
    119 			 struct cpu_disklabel *);
    120 
    121 /*
    122  * Attempt to read a disk label from a device
    123  * using the indicated strategy routine.
    124  * The label must be partly set up before this:
    125  * secpercyl and anything required in the strategy routine
    126  * (e.g., sector size) must be filled in before calling us.
    127  * Returns null on success and an error string on failure.
    128  */
    129 const char *
    130 readdisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp, struct cpu_disklabel *clp)
    131 {
    132 	struct adostype adt;
    133 	struct partition *pp = NULL;
    134 	struct partblock *pbp;
    135 	struct rdblock *rbp;
    136 	struct buf *bp;
    137 	const char *msg;
    138 	char *bcpls, *s, bcpli;
    139 	int cindex, i, nopname;
    140 	u_long nextb;
    141 	struct disklabel *dlp;
    142 
    143 	clp->rdblock = RDBNULL;
    144 	/*
    145 	 * give some guaranteed validity to
    146 	 * the disklabel
    147 	 */
    148 	if (lp->d_secperunit == 0)
    149 		lp->d_secperunit = 0x1fffffff;
    150 	if (lp->d_secpercyl == 0)
    151 		lp->d_secpercyl = 0x1fffffff;
    152 	lp->d_npartitions = RAW_PART + 1;
    153 
    154 	if (lp->d_partitions[RAW_PART].p_size == 0)
    155 		lp->d_partitions[RAW_PART].p_size = 0x1fffffff;
    156 	lp->d_partitions[RAW_PART].p_offset = 0;
    157 	/* if no 'a' partition, default it to copy of 'c' as BSDFFS */
    158 	if (lp->d_partitions[0].p_size == 0) {
    159 		lp->d_partitions[0].p_size = lp->d_partitions[RAW_PART].p_size;
    160 		lp->d_partitions[0].p_offset = 0;
    161 		lp->d_partitions[0].p_fstype = FS_BSDFFS;
    162 		lp->d_partitions[0].p_fsize = 1024;
    163 		lp->d_partitions[0].p_frag = 8;
    164 		lp->d_partitions[0].p_cpg = 0;
    165 	}
    166 
    167 	/* obtain buffer to probe drive with */
    168 	bp = geteblk((int)lp->d_secsize);
    169 
    170 	/*
    171 	 * request no partition relocation by driver on I/O operations
    172 	 */
    173 #ifdef _KERNEL
    174 	bp->b_dev = MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART);
    175 #else
    176 	bp->b_dev = dev;
    177 #endif
    178 	msg = NULL;
    179 
    180 	/*
    181 	 * find the RDB block
    182 	 * XXX Need to check for a standard label if this fails (fd0 etc..)
    183 	 */
    184 	for (nextb = 0; nextb < RDB_MAXBLOCKS; nextb++) {
    185 		bp->b_blkno = nextb;
    186 		bp->b_cylinder = bp->b_blkno / lp->d_secpercyl;
    187 		bp->b_bcount = lp->d_secsize;
    188 		bp->b_oflags &= ~(BO_DONE);
    189 		bp->b_flags |= B_READ;
    190 #ifdef SD_C_ADJUSTS_NR
    191 		bp->b_blkno *= (lp->d_secsize / DEV_BSIZE);
    192 #endif
    193 		strat(bp);
    194 
    195 		if (biowait(bp)) {
    196 			msg = "rdb scan I/O error";
    197 			goto done;
    198 		}
    199 		rbp = baddr(bp);
    200 		if (rbp->id == RDBLOCK_ID) {
    201 			if (rdbchksum(rbp) == 0)
    202 				break;
    203 			else
    204 				msg = "rdb bad checksum";
    205 		}
    206 		/* Check for native NetBSD label? */
    207 		dlp = (struct disklabel *)((char*)bp->b_data + LABELOFFSET);
    208 		if (dlp->d_magic == DISKMAGIC) {
    209 			if (dkcksum(dlp))
    210 				msg = "NetBSD disk label corrupted";
    211 			else {
    212 				/* remember block and continue searching? */
    213 				*lp = *dlp;
    214 				brelse(bp, 0);
    215 				return(msg);
    216 			}
    217 		}
    218 	}
    219 	if (nextb == RDB_MAXBLOCKS) {
    220 		if (msg == NULL)
    221 			msg = "no rdb found";
    222 		goto done;
    223 	} else if (msg) {
    224 		/*
    225 		 * maybe we found an invalid one before a valid.
    226 		 * clear err.
    227 		 */
    228 		msg = NULL;
    229 	}
    230 	clp->rdblock = nextb;
    231 
    232 	/* RDB present, clear disklabel partition table before doing PART blks */
    233 	for (i = 0; i < MAXPARTITIONS; i++) {
    234 		clp->pbindex[i] = -1;
    235 		clp->pblist[i] = RDBNULL;
    236 		if (i == RAW_PART)
    237 			continue;
    238 		lp->d_partitions[i].p_size = 0;
    239 		lp->d_partitions[i].p_offset = 0;
    240 	}
    241 
    242 	lp->d_secsize = rbp->nbytes;
    243 	lp->d_nsectors = rbp->nsectors;
    244 	lp->d_ntracks = rbp->nheads;
    245 	/*
    246 	 * should be rdb->ncylinders however this is a bogus value
    247 	 * sometimes it seems
    248 	 */
    249 	if (rbp->highcyl == 0)
    250 		lp->d_ncylinders = rbp->ncylinders;
    251 	else
    252 		lp->d_ncylinders = rbp->highcyl + 1;
    253 	/*
    254 	 * I also don't trust rdb->secpercyl
    255 	 */
    256 	lp->d_secpercyl = min(rbp->secpercyl, lp->d_nsectors * lp->d_ntracks);
    257 	if (lp->d_secpercyl == 0)
    258 		lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks;
    259 #ifdef DIAGNOSTIC
    260 	if (lp->d_ncylinders != rbp->ncylinders)
    261 		printf("warning found rdb->ncylinders(%ld) != "
    262 		    "rdb->highcyl(%ld) + 1\n", rbp->ncylinders,
    263 		    rbp->highcyl);
    264 	if (lp->d_nsectors * lp->d_ntracks != rbp->secpercyl)
    265 		printf("warning found rdb->secpercyl(%ld) != "
    266 		    "rdb->nsectors(%ld) * rdb->nheads(%ld)\n", rbp->secpercyl,
    267 		    rbp->nsectors, rbp->nheads);
    268 #endif
    269 	lp->d_sparespercyl =
    270 	    max(rbp->secpercyl, lp->d_nsectors * lp->d_ntracks)
    271 	    - lp->d_secpercyl;
    272 	if (lp->d_sparespercyl == 0)
    273 		lp->d_sparespertrack = 0;
    274 	else {
    275 		lp->d_sparespertrack = lp->d_sparespercyl / lp->d_ntracks;
    276 #ifdef DIAGNOSTIC
    277 		if (lp->d_sparespercyl % lp->d_ntracks)
    278 			printf("warning lp->d_sparespercyl(%d) not multiple "
    279 			    "of lp->d_ntracks(%d)\n", lp->d_sparespercyl,
    280 			    lp->d_ntracks);
    281 #endif
    282 	}
    283 
    284 	lp->d_secperunit = lp->d_secpercyl * lp->d_ncylinders;
    285 	lp->d_acylinders = rbp->ncylinders - (rbp->highcyl - rbp->lowcyl + 1);
    286 	lp->d_rpm = 3600; 		/* good guess I suppose. */
    287 	lp->d_interleave = rbp->interleave;
    288 	lp->d_headswitch = lp->d_flags = lp->d_trackskew = lp->d_cylskew = 0;
    289 	lp->d_trkseek = /* rbp->steprate */ 0;
    290 
    291 	/*
    292 	 * raw partition gets the entire disk
    293 	 */
    294 	lp->d_partitions[RAW_PART].p_size = rbp->ncylinders * lp->d_secpercyl;
    295 
    296 	/*
    297 	 * scan for partition blocks
    298 	 */
    299 	nopname = 1;
    300 	cindex = 0;
    301 	for (nextb = rbp->partbhead; nextb != RDBNULL; nextb = pbp->next) {
    302 		bp->b_blkno = nextb;
    303 		bp->b_cylinder = bp->b_blkno / lp->d_secpercyl;
    304 		bp->b_bcount = lp->d_secsize;
    305 		bp->b_oflags &= ~(BO_DONE);
    306 		bp->b_flags |= B_READ;
    307 #ifdef SD_C_ADJUSTS_NR
    308 		bp->b_blkno *= (lp->d_secsize / DEV_BSIZE);
    309 #endif
    310 		strat(bp);
    311 
    312 		if (biowait(bp)) {
    313 			msg = "partition scan I/O error";
    314 			goto done;
    315 		}
    316 		pbp = baddr(bp);
    317 
    318 		if (pbp->id != PARTBLOCK_ID) {
    319 			msg = "partition block with bad id";
    320 			goto done;
    321 		}
    322 		if (rdbchksum(pbp)) {
    323 			msg = "partition block bad checksum";
    324 			goto done;
    325 		}
    326 
    327 		if (pbp->e.tabsize < 11) {
    328 			/*
    329 			 * not enough info, too funky for us.
    330 			 * I don't want to skip I want it fixed.
    331 			 */
    332 			msg = "bad partition info (environ < 11)";
    333 			goto done;
    334 			continue;
    335 		}
    336 
    337 		/*
    338 		 * XXXX should be ">" however some vendors don't know
    339 		 * what a table size is so, we hack for them.
    340 		 * the other checks can fail for all I care but this
    341 		 * is a very common value. *sigh*.
    342 		 */
    343 		if (pbp->e.tabsize >= 16)
    344 			adt = getadostype(pbp->e.dostype);
    345 		else {
    346 			adt.archtype = ADT_UNKNOWN;
    347 			adt.fstype = FS_UNUSED;
    348 		}
    349 
    350 		switch (adt.archtype) {
    351 		case ADT_NETBSDROOT:
    352 			pp = &lp->d_partitions[0];
    353 			if (pp->p_size) {
    354 				printf("WARN: more than one root, ignoring\n");
    355 				clp->rdblock = RDBNULL;	/* invlidate cpulab */
    356 				continue;
    357 			}
    358 			break;
    359 		case ADT_NETBSDSWAP:
    360 			pp = &lp->d_partitions[1];
    361 			if (pp->p_size) {
    362 				printf("WARN: more than one swap, ignoring\n");
    363 				clp->rdblock = RDBNULL;	/* invlidate cpulab */
    364 				continue;
    365 			}
    366 			break;
    367 		case ADT_NETBSDUSER:
    368 		case ADT_AMIGADOS:
    369 		case ADT_AMIX:
    370 		case ADT_EXT2:
    371 		case ADT_RAID:
    372 		case ADT_UNKNOWN:
    373 			pp = &lp->d_partitions[lp->d_npartitions];
    374 			break;
    375 		}
    376 		if (lp->d_npartitions <= (pp - lp->d_partitions))
    377 			lp->d_npartitions = (pp - lp->d_partitions) + 1;
    378 
    379 #ifdef DIAGNOSTIC
    380 		if (lp->d_secpercyl * lp->d_secsize !=
    381 		    (pbp->e.secpertrk * pbp->e.numheads * pbp->e.sizeblock<<2)) {
    382 			if (pbp->partname[0] < sizeof(pbp->partname))
    383 				pbp->partname[pbp->partname[0] + 1] = 0;
    384 			else
    385 				pbp->partname[sizeof(pbp->partname) - 1] = 0;
    386 			printf("Partition '%s' geometry %ld/%ld differs",
    387 			    pbp->partname + 1, pbp->e.numheads,
    388 			    pbp->e.secpertrk);
    389 			printf(" from RDB %d/%d=%d\n", lp->d_ntracks,
    390 			    lp->d_nsectors, lp->d_secpercyl);
    391 		}
    392 #endif
    393 		/*
    394 		 * insert sort in increasing offset order
    395 		 */
    396 		while ((pp - lp->d_partitions) > RAW_PART + 1) {
    397 			daddr_t boff;
    398 
    399 			boff = pbp->e.lowcyl * pbp->e.secpertrk
    400 			    * pbp->e.numheads;
    401 			if (boff > (pp - 1)->p_offset)
    402 				break;
    403 			*pp = *(pp - 1);	/* struct copy */
    404 			pp--;
    405 		}
    406 		i = (pp - lp->d_partitions);
    407 		if (nopname || i == 1) {
    408 			/*
    409 			 * either we have no packname yet or we found
    410 			 * the swap partition. copy BCPL string into packname
    411 			 * [the reason we use the swap partition: the user
    412 			 *  can supply a decent packname without worry
    413 			 *  of having to access an odly named partition
    414 			 *  under AmigaDos]
    415 			 */
    416 			s = lp->d_packname;
    417 			bcpls = &pbp->partname[1];
    418 			bcpli = pbp->partname[0];
    419 			if (sizeof(lp->d_packname) <= bcpli)
    420 				bcpli = sizeof(lp->d_packname) - 1;
    421 			while (bcpli--)
    422 				*s++ = *bcpls++;
    423 			*s = 0;
    424 			nopname = 0;
    425 		}
    426 
    427 		pp->p_size = (pbp->e.highcyl - pbp->e.lowcyl + 1)
    428 		    * pbp->e.secpertrk * pbp->e.numheads
    429 		    * ((pbp->e.sizeblock << 2) / lp->d_secsize);
    430 		pp->p_offset = pbp->e.lowcyl * pbp->e.secpertrk
    431 		    * pbp->e.numheads
    432 		    * ((pbp->e.sizeblock << 2) / lp->d_secsize);
    433 		pp->p_fstype = adt.fstype;
    434 		if (adt.archtype == ADT_AMIGADOS) {
    435 			/*
    436 			 * Save reserved blocks at begin in cpg and
    437 			 *  adjust size by reserved blocks at end
    438 			 */
    439 			int bsize, secperblk, minbsize, prefac;
    440 
    441 			minbsize = max(512, lp->d_secsize);
    442 
    443 			bsize	  = pbp->e.sizeblock << 2;
    444 			secperblk = pbp->e.secperblk;
    445 			prefac	  = pbp->e.prefac;
    446 
    447 			while (bsize > minbsize) {
    448 				bsize >>= 1;
    449 				secperblk <<= 1;
    450 				prefac <<= 1;
    451 			}
    452 
    453 			if (bsize == minbsize) {
    454 				pp->p_fsize = bsize;
    455 				pp->p_frag = secperblk;
    456 				pp->p_cpg = pbp->e.resvblocks;
    457 				pp->p_size -= prefac;
    458 			} else {
    459 				adt.archtype = ADT_UNKNOWN;
    460 				adt.fstype = FS_UNUSED;
    461 			}
    462 		} else if (pbp->e.tabsize > 22 && ISFSARCH_NETBSD(adt)) {
    463 			pp->p_fsize = pbp->e.fsize;
    464 			pp->p_frag = pbp->e.frag;
    465 			pp->p_cpg = pbp->e.cpg;
    466 		} else {
    467 			pp->p_fsize = 1024;
    468 			pp->p_frag = 8;
    469 			pp->p_cpg = 0;
    470 		}
    471 
    472 		/*
    473 		 * store this partitions block number
    474 		 */
    475 		clp->pblist[clp->pbindex[i] = cindex++] = nextb;
    476 	}
    477 	/*
    478 	 * calulate new checksum.
    479 	 */
    480 	lp->d_magic = lp->d_magic2 = DISKMAGIC;
    481 	lp->d_checksum = 0;
    482 	lp->d_checksum = dkcksum(lp);
    483 	if (clp->rdblock != RDBNULL)
    484 		clp->valid = 1;
    485 done:
    486 	if (clp->valid == 0)
    487 		clp->rdblock = RDBNULL;
    488 	brelse(bp, 0);
    489 	return(msg);
    490 }
    491 
    492 /*
    493  * Check new disk label for sensibility
    494  * before setting it.
    495  */
    496 int
    497 setdisklabel(struct disklabel *olp, struct disklabel *nlp, u_long openmask, struct cpu_disklabel *clp)
    498 {
    499 	int i;
    500 	struct partition *opp, *npp;
    501 
    502 	if (nlp->d_magic != DISKMAGIC || nlp->d_magic2 != DISKMAGIC ||
    503 	    dkcksum(nlp) != 0)
    504 		return (EINVAL);
    505 	while ((i = ffs(openmask)) != 0) {
    506 		i--;
    507 		openmask &= ~(1 << i);
    508 		if (nlp->d_npartitions <= i)
    509 			return (EBUSY);
    510 		opp = &olp->d_partitions[i];
    511 		npp = &nlp->d_partitions[i];
    512 		if (npp->p_offset != opp->p_offset || npp->p_size < opp->p_size)
    513 			return (EBUSY);
    514 		/*
    515 		 * Copy internally-set partition information
    516 		 * if new label doesn't include it.		XXX
    517 		 */
    518 		if (npp->p_fstype == FS_UNUSED && opp->p_fstype != FS_UNUSED) {
    519 			npp->p_fstype = opp->p_fstype;
    520 			npp->p_fsize = opp->p_fsize;
    521 			npp->p_frag = opp->p_frag;
    522 			npp->p_cpg = opp->p_cpg;
    523 		}
    524 	}
    525  	nlp->d_checksum = 0;
    526  	nlp->d_checksum = dkcksum(nlp);
    527 	*olp = *nlp;
    528 	return (0);
    529 }
    530 
    531 /*
    532  * Write disk label back to device after modification.
    533  * this means write out the Rigid disk blocks to represent the
    534  * label.  Hope the user was carefull.
    535  */
    536 int
    537 writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp, struct cpu_disklabel *clp)
    538 {
    539 	struct buf *bp;
    540 	struct disklabel *dlp;
    541 	int error = 0;
    542 
    543 	/* If RDB was present, we don't support writing them yet. */
    544 	if (clp->rdblock != RDBNULL)
    545 		return(EINVAL);
    546 
    547 	/* RDB was not present, write out native NetBSD label */
    548 	bp = geteblk((int)lp->d_secsize);
    549 	bp->b_dev = dev;
    550 	bp->b_blkno = LABELSECTOR;
    551 	bp->b_cylinder = 0;
    552 	bp->b_bcount = lp->d_secsize;
    553 	bp->b_flags |= B_READ;           /* get current label */
    554 	(*strat)(bp);
    555 	if ((error = biowait(bp)) != 0)
    556 		goto done;
    557 
    558 	dlp = (struct disklabel *)((char*)bp->b_data + LABELOFFSET);
    559 	*dlp = *lp;     /* struct assignment */
    560 
    561 	bp->b_oflags &= ~(BO_DONE);
    562 	bp->b_flags &= ~(B_READ);
    563 	bp->b_flags |= B_WRITE;
    564 	(*strat)(bp);
    565 	error = biowait(bp);
    566 
    567 done:
    568 	brelse(bp, 0);
    569 	return (error);
    570 
    571 	/*
    572 	 * get write out partition list iff cpu_label is valid.
    573 	 */
    574 	if (clp->valid == 0 ||
    575 	    (clp->rdblock <= 0 || clp->rdblock >= RDB_MAXBLOCKS))
    576 		return(EINVAL);
    577 
    578 	(void)getrdbmap(dev, strat, lp, clp);
    579 	return(EINVAL);
    580 }
    581 
    582 u_long
    583 rdbchksum(void *bdata)
    584 {
    585 	u_long *blp, cnt, val;
    586 
    587 	blp = bdata;
    588 	cnt = blp[1];
    589 	val = 0;
    590 
    591 	while (cnt--)
    592 		val += *blp++;
    593 	return(val);
    594 }
    595 
    596 struct adostype
    597 getadostype(u_long dostype)
    598 {
    599 	struct adostype adt;
    600 	u_long t3, b1;
    601 
    602 	t3 = dostype & 0xffffff00;
    603 	b1 = dostype & 0x000000ff;
    604 
    605 	adt.fstype = b1;
    606 
    607 	switch (t3) {
    608 	case DOST_NBR:
    609 		adt.archtype = ADT_NETBSDROOT;
    610 		return(adt);
    611 	case DOST_NBS:
    612 		adt.archtype = ADT_NETBSDSWAP;
    613 		return(adt);
    614 	case DOST_NBU:
    615 		adt.archtype = ADT_NETBSDUSER;
    616 		return(adt);
    617 	case DOST_MUFS:
    618 		/* check for 'muFS'? */
    619 		adt.archtype = ADT_AMIGADOS;
    620 		adt.fstype = FS_ADOS;
    621 		return(adt);
    622 	case DOST_DOS:
    623 		adt.archtype = ADT_AMIGADOS;
    624                 if (b1 > 5)
    625 			adt.fstype = FS_UNUSED;
    626 		else
    627 			adt.fstype = FS_ADOS;
    628 		return(adt);
    629 
    630 	case DOST_AMIX:
    631 		adt.archtype = ADT_AMIX;
    632 		if (b1 == 2)
    633 			adt.fstype = FS_BSDFFS;
    634 		else
    635 			adt.fstype = FS_UNUSED;
    636 		return(adt);
    637 	case DOST_XXXBSD:
    638 #ifdef DIAGNOSTIC
    639 		printf("found dostype: 0x%lx which is deprecated", dostype);
    640 #endif
    641 		if (b1 == 'S') {
    642 			dostype = DOST_NBS;
    643 			dostype |= FS_SWAP;
    644 		} else {
    645 			if (b1 == 'R')
    646 				dostype = DOST_NBR;
    647 			else
    648 				dostype = DOST_NBU;
    649 			dostype |= FS_BSDFFS;
    650 		}
    651 #ifdef DIAGNOSTIC
    652 		printf(" using: 0x%lx instead\n", dostype);
    653 #endif
    654 		return(getadostype(dostype));
    655 
    656 	case DOST_EXT2:
    657 		adt.archtype = ADT_EXT2;
    658 		adt.fstype = FS_EX2FS;
    659 		return(adt);
    660 
    661 	case DOST_RAID:
    662 		adt.archtype = ADT_RAID;
    663 		adt.fstype = FS_RAID;
    664 		return(adt);
    665 
    666 	default:
    667 #ifdef DIAGNOSTIC
    668 		printf("warning unknown dostype: 0x%lx marking unused\n",
    669 		    dostype);
    670 #endif
    671 		adt.archtype = ADT_UNKNOWN;
    672 		adt.fstype = FS_UNUSED;
    673 		return(adt);
    674 	}
    675 }
    676 
    677 /*
    678  * if we find a bad block we kill it (and the chain it belongs to for
    679  * lseg or end the chain for part, badb, fshd)
    680  */
    681 struct rdbmap *
    682 getrdbmap(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp, struct cpu_disklabel *clp)
    683 {
    684 	struct buf *bp;
    685 
    686 	bp = (void *)geteblk(lp->d_secsize);
    687 	/*
    688 	 * get the raw partition
    689 	 */
    690 
    691 	bp->b_dev = MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART);
    692 	/* XXX finish */
    693 	brelse(bp, 0);
    694 	return(NULL);
    695 }
    696 
    697