xref: /dragonfly/sys/kern/subr_disklabel32.c (revision fb151170)
1 /*
2  * Copyright (c) 2003-2007 The DragonFly Project.  All rights reserved.
3  *
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com>
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  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  * 3. Neither the name of The DragonFly Project nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific, prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  * ----------------------------------------------------------------------------
35  * "THE BEER-WARE LICENSE" (Revision 42):
36  * <phk@FreeBSD.ORG> wrote this file.  As long as you retain this notice you
37  * can do whatever you want with this stuff. If we meet some day, and you think
38  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
39  * ----------------------------------------------------------------------------
40  *
41  * Copyright (c) 1982, 1986, 1988, 1993
42  *	The Regents of the University of California.  All rights reserved.
43  * (c) UNIX System Laboratories, Inc.
44  * All or some portions of this file are derived from material licensed
45  * to the University of California by American Telephone and Telegraph
46  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
47  * the permission of UNIX System Laboratories, Inc.
48  *
49  * Copyright (c) 1994 Bruce D. Evans.
50  * All rights reserved.
51  *
52  * Copyright (c) 1990 The Regents of the University of California.
53  * All rights reserved.
54  *
55  * This code is derived from software contributed to Berkeley by
56  * William Jolitz.
57  *
58  * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
59  * All rights reserved.
60  *
61  * Redistribution and use in source and binary forms, with or without
62  * modification, are permitted provided that the following conditions
63  * are met:
64  * 1. Redistributions of source code must retain the above copyright
65  *    notice, this list of conditions and the following disclaimer.
66  * 2. Redistributions in binary form must reproduce the above copyright
67  *    notice, this list of conditions and the following disclaimer in the
68  *    documentation and/or other materials provided with the distribution.
69  * 3. All advertising materials mentioning features or use of this software
70  *    must display the following acknowledgement:
71  *	This product includes software developed by the University of
72  *	California, Berkeley and its contributors.
73  * 4. Neither the name of the University nor the names of its contributors
74  *    may be used to endorse or promote products derived from this software
75  *    without specific prior written permission.
76  *
77  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
78  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
79  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
80  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
81  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
82  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
83  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
84  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
85  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
86  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
87  * SUCH DAMAGE.
88  *
89  *	@(#)ufs_disksubr.c	8.5 (Berkeley) 1/21/94
90  * $FreeBSD: src/sys/kern/subr_disk.c,v 1.20.2.6 2001/10/05 07:14:57 peter Exp $
91  * $FreeBSD: src/sys/ufs/ufs/ufs_disksubr.c,v 1.44.2.3 2001/03/05 05:42:19 obrien Exp $
92  */
93 
94 #include <sys/param.h>
95 #include <sys/systm.h>
96 #include <sys/kernel.h>
97 #include <sys/proc.h>
98 #include <sys/sysctl.h>
99 #include <sys/buf.h>
100 #include <sys/conf.h>
101 #include <sys/disklabel.h>
102 #include <sys/disklabel32.h>
103 #include <sys/diskslice.h>
104 #include <sys/disk.h>
105 #include <sys/dtype.h>		/* DTYPE_* constants */
106 #include <machine/md_var.h>
107 #include <sys/ctype.h>
108 #include <sys/syslog.h>
109 #include <sys/device.h>
110 #include <sys/msgport.h>
111 #include <sys/msgport2.h>
112 #include <sys/buf2.h>
113 
114 #include <vfs/ufs/dinode.h>	/* XXX used only for fs.h */
115 #include <vfs/ufs/fs.h>		/* XXX used only to get BBSIZE/SBSIZE */
116 
117 static void partition_info(const char *sname, int part, struct partition32 *pp);
118 static void slice_info(const char *sname, struct diskslice *sp);
119 static const char *l32_fixlabel(const char *sname, struct diskslice *sp,
120 				disklabel_t lpx, int writeflag);
121 
122 /*
123  * Retrieve the partition start and extent, in blocks.  Return 0 on success,
124  * EINVAL on error.
125  */
126 static int
127 l32_getpartbounds(struct diskslices *ssp, disklabel_t lp, u_int32_t part,
128 		  u_int64_t *start, u_int64_t *blocks)
129 {
130 	struct partition32 *pp;
131 
132 	if (part >= lp.lab32->d_npartitions)
133 		return (EINVAL);
134 	pp = &lp.lab32->d_partitions[part];
135 	*start = pp->p_offset;
136 	*blocks = pp->p_size;
137 	return(0);
138 }
139 
140 static void
141 l32_loadpartinfo(disklabel_t lp, u_int32_t part, struct partinfo *dpart)
142 {
143 	struct partition32 *pp;
144 	const size_t uuid_size = sizeof(struct uuid);
145 
146 	bzero(&dpart->fstype_uuid, uuid_size);
147 	bzero(&dpart->storage_uuid, uuid_size);
148 	if (part < lp.lab32->d_npartitions) {
149 		pp = &lp.lab32->d_partitions[part];
150 		dpart->fstype = pp->p_fstype;
151 	} else {
152 		dpart->fstype = 0;
153 	}
154 }
155 
156 static u_int32_t
157 l32_getnumparts(disklabel_t lp)
158 {
159 	return(lp.lab32->d_npartitions);
160 }
161 
162 /*
163  * Attempt to read a disk label from a device.
164  *
165  * Returns NULL on sucess, and an error string on failure
166  */
167 static const char *
168 l32_readdisklabel(cdev_t dev, struct diskslice *sp, disklabel_t *lpp,
169 		struct disk_info *info)
170 {
171 	disklabel_t lpx;
172 	struct buf *bp;
173 	struct disklabel32 *dlp;
174 	const char *msg = NULL;
175 	int secsize = info->d_media_blksize;
176 
177 	bp = geteblk(secsize);
178 	bp->b_bio1.bio_offset = (off_t)LABELSECTOR32 * secsize;
179 	bp->b_bio1.bio_done = biodone_sync;
180 	bp->b_bio1.bio_flags |= BIO_SYNC;
181 	bp->b_bcount = secsize;
182 	bp->b_flags &= ~B_INVAL;
183 	bp->b_cmd = BUF_CMD_READ;
184 	dev_dstrategy(dev, &bp->b_bio1);
185 	if (biowait(&bp->b_bio1, "labrd"))
186 		msg = "I/O error";
187 	else for (dlp = (struct disklabel32 *)bp->b_data;
188 	    dlp <= (struct disklabel32 *)((char *)bp->b_data +
189 	    secsize - sizeof(*dlp));
190 	    dlp = (struct disklabel32 *)((char *)dlp + sizeof(long))) {
191 		if (dlp->d_magic != DISKMAGIC32 ||
192 		    dlp->d_magic2 != DISKMAGIC32) {
193 			/*
194 			 * NOTE! dsreadandsetlabel() does a strcmp() on
195 			 * this string.
196 			 */
197 			if (msg == NULL)
198 				msg = "no disk label";
199 		} else if (dlp->d_npartitions > MAXPARTITIONS32 ||
200 			   dkcksum32(dlp) != 0) {
201 			msg = "disk label corrupted";
202 		} else {
203 			lpx.lab32 = dlp;
204 			msg = l32_fixlabel(NULL, sp, lpx, FALSE);
205 			if (msg == NULL) {
206 				(*lpp).lab32 = kmalloc(sizeof(*dlp),
207 						       M_DEVBUF, M_WAITOK|M_ZERO);
208 				*(*lpp).lab32 = *dlp;
209 			}
210 			break;
211 		}
212 	}
213 	bp->b_flags |= B_INVAL | B_AGE;
214 	brelse(bp);
215 	return (msg);
216 }
217 
218 /*
219  * Check new disk label for sensibility before setting it.
220  */
221 static int
222 l32_setdisklabel(disklabel_t olpx, disklabel_t nlpx, struct diskslices *ssp,
223 		 struct diskslice *sp, u_int32_t *openmask)
224 {
225 	struct disklabel32 *olp, *nlp;
226 	struct partition32 *opp, *npp;
227 	int part;
228 	int i;
229 
230 	olp = olpx.lab32;
231 	nlp = nlpx.lab32;
232 
233 	/*
234 	 * Check it is actually a disklabel we are looking at.
235 	 */
236 	if (nlp->d_magic != DISKMAGIC32 || nlp->d_magic2 != DISKMAGIC32 ||
237 	    dkcksum32(nlp) != 0)
238 		return (EINVAL);
239 
240 	/*
241 	 * For each partition that we think is open, check the new disklabel
242 	 * for compatibility.  Ignore special partitions (>= 128).
243 	 */
244 	i = 0;
245 	while (i < 128) {
246 		if (openmask[i >> 5] == 0) {
247 			i += 32;
248 			continue;
249 		}
250 		if ((openmask[i >> 5] & (1 << (i & 31))) == 0) {
251 			++i;
252 			continue;
253 		}
254 		if (nlp->d_npartitions <= i)
255 			return (EBUSY);
256 		opp = &olp->d_partitions[i];
257 		npp = &nlp->d_partitions[i];
258 		if (npp->p_offset != opp->p_offset || npp->p_size < opp->p_size)
259 			return (EBUSY);
260 		/*
261 		 * Copy internally-set partition information
262 		 * if new label doesn't include it.		XXX
263 		 * (If we are using it then we had better stay the same type)
264 		 * This is possibly dubious, as someone else noted (XXX)
265 		 */
266 		if (npp->p_fstype == FS_UNUSED && opp->p_fstype != FS_UNUSED) {
267 			npp->p_fstype = opp->p_fstype;
268 			npp->p_fsize = opp->p_fsize;
269 			npp->p_frag = opp->p_frag;
270 			npp->p_cpg = opp->p_cpg;
271 		}
272 		++i;
273 	}
274  	nlp->d_checksum = 0;
275  	nlp->d_checksum = dkcksum32(nlp);
276 	*olp = *nlp;
277 
278 	if (olp->d_partitions[RAW_PART].p_offset)
279 		return (EXDEV);
280 	if (olp->d_secperunit > sp->ds_size)
281 		return (ENOSPC);
282 	for (part = 0; part < olp->d_npartitions; ++part) {
283 		if (olp->d_partitions[part].p_size > sp->ds_size)
284 			return(ENOSPC);
285 	}
286 	return (0);
287 }
288 
289 /*
290  * Write disk label back to device after modification.
291  */
292 static int
293 l32_writedisklabel(cdev_t dev, struct diskslices *ssp, struct diskslice *sp,
294 		   disklabel_t lpx)
295 {
296 	struct disklabel32 *lp;
297 	struct disklabel32 *dlp;
298 	struct buf *bp;
299 	const char *msg;
300 	int error = 0;
301 
302 	lp = lpx.lab32;
303 
304 	if (lp->d_partitions[RAW_PART].p_offset != 0)
305 		return (EXDEV);			/* not quite right */
306 
307 	bp = geteblk((int)lp->d_secsize);
308 	bp->b_bio1.bio_offset = (off_t)LABELSECTOR32 * lp->d_secsize;
309 	bp->b_bio1.bio_done = biodone_sync;
310 	bp->b_bio1.bio_flags |= BIO_SYNC;
311 	bp->b_bcount = lp->d_secsize;
312 
313 #if 1
314 	/*
315 	 * We read the label first to see if it's there,
316 	 * in which case we will put ours at the same offset into the block..
317 	 * (I think this is stupid [Julian])
318 	 * Note that you can't write a label out over a corrupted label!
319 	 * (also stupid.. how do you write the first one? by raw writes?)
320 	 */
321 	bp->b_flags &= ~B_INVAL;
322 	bp->b_cmd = BUF_CMD_READ;
323 	KKASSERT(dkpart(dev) == WHOLE_SLICE_PART);
324 	dev_dstrategy(dev, &bp->b_bio1);
325 	error = biowait(&bp->b_bio1, "labrd");
326 	if (error)
327 		goto done;
328 	for (dlp = (struct disklabel32 *)bp->b_data;
329 	    dlp <= (struct disklabel32 *)
330 	      ((char *)bp->b_data + lp->d_secsize - sizeof(*dlp));
331 	    dlp = (struct disklabel32 *)((char *)dlp + sizeof(long))) {
332 		if (dlp->d_magic == DISKMAGIC32 &&
333 		    dlp->d_magic2 == DISKMAGIC32 && dkcksum32(dlp) == 0) {
334 			*dlp = *lp;
335 			lpx.lab32 = dlp;
336 			msg = l32_fixlabel(NULL, sp, lpx, TRUE);
337 			if (msg) {
338 				error = EINVAL;
339 			} else {
340 				bp->b_cmd = BUF_CMD_WRITE;
341 				bp->b_bio1.bio_done = biodone_sync;
342 				bp->b_bio1.bio_flags |= BIO_SYNC;
343 				KKASSERT(dkpart(dev) == WHOLE_SLICE_PART);
344 				dev_dstrategy(dev, &bp->b_bio1);
345 				error = biowait(&bp->b_bio1, "labwr");
346 			}
347 			goto done;
348 		}
349 	}
350 	error = ESRCH;
351 done:
352 #else
353 	bzero(bp->b_data, lp->d_secsize);
354 	dlp = (struct disklabel32 *)bp->b_data;
355 	*dlp = *lp;
356 	bp->b_flags &= ~B_INVAL;
357 	bp->b_cmd = BUF_CMD_WRITE;
358 	bp->b_bio1.bio_done = biodone_sync;
359 	bp->b_bio1.bio_flags |= BIO_SYNC;
360 	BUF_STRATEGY(bp, 1);
361 	error = biowait(&bp->b_bio1, "labwr");
362 #endif
363 	bp->b_flags |= B_INVAL | B_AGE;
364 	brelse(bp);
365 	return (error);
366 }
367 
368 /*
369  * Create a disklabel based on a disk_info structure, initializing
370  * the appropriate fields and creating a raw partition that covers the
371  * whole disk.
372  *
373  * If a diskslice is passed, the label is truncated to the slice
374  */
375 static disklabel_t
376 l32_clone_label(struct disk_info *info, struct diskslice *sp)
377 {
378 	struct disklabel32 *lp;
379 	disklabel_t res;
380 
381 	lp = kmalloc(sizeof *lp, M_DEVBUF, M_WAITOK | M_ZERO);
382 	lp->d_nsectors = info->d_secpertrack;
383 	lp->d_ntracks = info->d_nheads;
384 	lp->d_secpercyl = info->d_secpercyl;
385 	lp->d_secsize = info->d_media_blksize;
386 
387 	if (sp)
388 		lp->d_secperunit = (u_int)sp->ds_size;
389 	else
390 		lp->d_secperunit = (u_int)info->d_media_blocks;
391 
392 	if (lp->d_typename[0] == '\0')
393 		strncpy(lp->d_typename, "amnesiac", sizeof(lp->d_typename));
394 	if (lp->d_packname[0] == '\0')
395 		strncpy(lp->d_packname, "fictitious", sizeof(lp->d_packname));
396 	if (lp->d_nsectors == 0)
397 		lp->d_nsectors = 32;
398 	if (lp->d_ntracks == 0)
399 		lp->d_ntracks = 64;
400 	lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks;
401 	lp->d_ncylinders = lp->d_secperunit / lp->d_secpercyl;
402 	if (lp->d_rpm == 0)
403 		lp->d_rpm = 3600;
404 	if (lp->d_interleave == 0)
405 		lp->d_interleave = 1;
406 	if (lp->d_npartitions < RAW_PART + 1)
407 		lp->d_npartitions = MAXPARTITIONS32;
408 	if (lp->d_bbsize == 0)
409 		lp->d_bbsize = BBSIZE;
410 	if (lp->d_sbsize == 0)
411 		lp->d_sbsize = SBSIZE;
412 
413 	/*
414 	 * Used by various devices to create a compatibility slice which
415 	 * allows us to mount root from devices which do not have a
416 	 * disklabel.  Particularly: CDs.
417 	 */
418 	lp->d_partitions[RAW_PART].p_size = lp->d_secperunit;
419 	if (info->d_dsflags & DSO_COMPATPARTA) {
420 		lp->d_partitions[0].p_size = lp->d_secperunit;
421 		lp->d_partitions[0].p_fstype = FS_OTHER;
422 	}
423 	lp->d_magic = DISKMAGIC32;
424 	lp->d_magic2 = DISKMAGIC32;
425 	lp->d_checksum = dkcksum32(lp);
426 	res.lab32 = lp;
427 	return (res);
428 }
429 
430 static void
431 l32_makevirginlabel(disklabel_t lpx, struct diskslices *ssp,
432 		    struct diskslice *sp, struct disk_info *info)
433 {
434 	struct disklabel32 *lp = lpx.lab32;
435 	struct partition32 *pp;
436 	disklabel_t template;
437 
438 	template = l32_clone_label(info, NULL);
439 	bcopy(template.opaque, lp, sizeof(struct disklabel32));
440 
441 	lp->d_magic = DISKMAGIC32;
442 	lp->d_magic2 = DISKMAGIC32;
443 
444 	lp->d_npartitions = MAXPARTITIONS32;
445 	if (lp->d_interleave == 0)
446 		lp->d_interleave = 1;
447 	if (lp->d_rpm == 0)
448 		lp->d_rpm = 3600;
449 	if (lp->d_nsectors == 0)	/* sectors per track */
450 		lp->d_nsectors = 32;
451 	if (lp->d_ntracks == 0)		/* heads */
452 		lp->d_ntracks = 64;
453 	lp->d_ncylinders = 0;
454 	lp->d_bbsize = BBSIZE;
455 	lp->d_sbsize = SBSIZE;
456 
457 	/*
458 	 * If the slice or GPT partition is really small we could
459 	 * wind up with an absurd calculation for ncylinders.
460 	 */
461 	while (lp->d_ncylinders < 4) {
462 		if (lp->d_ntracks > 1)
463 			lp->d_ntracks >>= 1;
464 		else if (lp->d_nsectors > 1)
465 			lp->d_nsectors >>= 1;
466 		else
467 			break;
468 		lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks;
469 		lp->d_ncylinders = sp->ds_size / lp->d_secpercyl;
470 	}
471 
472 	/*
473 	 * Set or Modify the partition sizes to accomodate the slice,
474 	 * since we started with a copy of the virgin label stored
475 	 * in the whole-disk-slice and we are probably not a
476 	 * whole-disk slice.
477 	 */
478 	lp->d_secperunit = sp->ds_size;
479 	pp = &lp->d_partitions[RAW_PART];
480 	pp->p_offset = 0;
481 	pp->p_size = lp->d_secperunit;
482 	if (info->d_dsflags & DSO_COMPATPARTA) {
483 		pp = &lp->d_partitions[0];
484 		pp->p_offset = 0;
485 		pp->p_size = lp->d_secperunit;
486 		pp->p_fstype = FS_OTHER;
487 	}
488 	lp->d_checksum = 0;
489 	lp->d_checksum = dkcksum32(lp);
490 
491 	kfree(template.opaque, M_DEVBUF);
492 }
493 
494 static const char *
495 l32_fixlabel(const char *sname, struct diskslice *sp,
496 	     disklabel_t lpx, int writeflag)
497 {
498 	struct disklabel32 *lp;
499 	struct partition32 *pp;
500 	u_int64_t start;
501 	u_int64_t end;
502 	u_int64_t offset;
503 	int part;
504 	int warned;
505 
506 	lp = lpx.lab32;
507 
508 	/* These errors "can't happen" so don't bother reporting details. */
509 	if (lp->d_magic != DISKMAGIC32 || lp->d_magic2 != DISKMAGIC32)
510 		return ("fixlabel: invalid magic");
511 	if (dkcksum32(lp) != 0)
512 		return ("fixlabel: invalid checksum");
513 
514 	pp = &lp->d_partitions[RAW_PART];
515 
516 	/*
517 	 * What a mess.  For ages old backwards compatibility the disklabel
518 	 * on-disk stores absolute offsets instead of slice-relative offsets.
519 	 * So fix it up when reading, writing, or snooping.
520 	 *
521 	 * The in-core label is always slice-relative.
522 	 */
523 	if (writeflag) {
524 		start = 0;
525 		offset = sp->ds_offset;
526 	} else {
527 		start = sp->ds_offset;
528 		offset = -sp->ds_offset;
529 	}
530 	if (pp->p_offset != start) {
531 		if (sname != NULL) {
532 			kprintf(
533 "%s: rejecting BSD label: raw partition offset != slice offset\n",
534 			       sname);
535 			slice_info(sname, sp);
536 			partition_info(sname, RAW_PART, pp);
537 		}
538 		return ("fixlabel: raw partition offset != slice offset");
539 	}
540 	if (pp->p_size != sp->ds_size) {
541 		if (sname != NULL) {
542 			kprintf("%s: raw partition size != slice size\n", sname);
543 			slice_info(sname, sp);
544 			partition_info(sname, RAW_PART, pp);
545 		}
546 		if (pp->p_size > sp->ds_size) {
547 			if (sname == NULL)
548 				return ("fixlabel: raw partition size > slice size");
549 			kprintf("%s: truncating raw partition\n", sname);
550 			pp->p_size = sp->ds_size;
551 		}
552 	}
553 	end = start + sp->ds_size;
554 	if (start > end)
555 		return ("fixlabel: slice wraps");
556 	if (lp->d_secpercyl <= 0)
557 		return ("fixlabel: d_secpercyl <= 0");
558 	pp -= RAW_PART;
559 	warned = FALSE;
560 	for (part = 0; part < lp->d_npartitions; part++, pp++) {
561 		if (pp->p_offset != 0 || pp->p_size != 0) {
562 			if (pp->p_offset < start
563 			    || pp->p_offset + pp->p_size > end
564 			    || pp->p_offset + pp->p_size < pp->p_offset) {
565 				if (sname != NULL) {
566 					kprintf(
567 "%s: rejecting partition in BSD label: it isn't entirely within the slice\n",
568 					       sname);
569 					if (!warned) {
570 						slice_info(sname, sp);
571 						warned = TRUE;
572 					}
573 					partition_info(sname, part, pp);
574 				}
575 				/* XXX else silently discard junk. */
576 				bzero(pp, sizeof *pp);
577 			} else {
578 				pp->p_offset += offset;
579 			}
580 		}
581 	}
582 	lp->d_ncylinders = sp->ds_size / lp->d_secpercyl;
583 	lp->d_secperunit = sp->ds_size;
584  	lp->d_checksum = 0;
585  	lp->d_checksum = dkcksum32(lp);
586 	return (NULL);
587 }
588 
589 /*
590  * Set the number of blocks at the beginning of the slice which have
591  * been reserved for label operations.  This area will be write-protected
592  * when accessed via the slice.
593  */
594 static void
595 l32_adjust_label_reserved(struct diskslices *ssp, int slice,
596 			  struct diskslice *sp)
597 {
598 	/*struct disklabel32 *lp = sp->ds_label.lab32;*/
599 	sp->ds_reserved = SBSIZE / ssp->dss_secsize;
600 }
601 
602 static void
603 partition_info(const char *sname, int part, struct partition32 *pp)
604 {
605 	kprintf("%s%c: start %lu, end %lu, size %lu\n", sname, 'a' + part,
606 		(u_long)pp->p_offset, (u_long)(pp->p_offset + pp->p_size - 1),
607 		(u_long)pp->p_size);
608 }
609 
610 static void
611 slice_info(const char *sname, struct diskslice *sp)
612 {
613 	kprintf("%s: start %llu, end %llu, size %llu\n", sname,
614 	       (long long)sp->ds_offset,
615 	       (long long)sp->ds_offset + sp->ds_size - 1,
616 	       (long long)sp->ds_size);
617 }
618 
619 struct disklabel_ops disklabel32_ops = {
620 	.labelsize = sizeof(struct disklabel32),
621 	.op_readdisklabel = l32_readdisklabel,
622 	.op_setdisklabel = l32_setdisklabel,
623 	.op_writedisklabel = l32_writedisklabel,
624 	.op_clone_label = l32_clone_label,
625 	.op_adjust_label_reserved = l32_adjust_label_reserved,
626 	.op_getpartbounds = l32_getpartbounds,
627 	.op_loadpartinfo = l32_loadpartinfo,
628 	.op_getnumparts = l32_getnumparts,
629 	.op_makevirginlabel = l32_makevirginlabel
630 };
631 
632