Merge branch 'vendor/GCC44' into gcc441
[dragonfly.git] / sys / kern / subr_disklabel32.c
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  * $DragonFly: src/sys/kern/subr_disklabel32.c,v 1.4 2007/06/19 06:07:57 dillon Exp $
93  */
94
95 #include <sys/param.h>
96 #include <sys/systm.h>
97 #include <sys/kernel.h>
98 #include <sys/proc.h>
99 #include <sys/sysctl.h>
100 #include <sys/buf.h>
101 #include <sys/conf.h>
102 #include <sys/disklabel.h>
103 #include <sys/disklabel32.h>
104 #include <sys/diskslice.h>
105 #include <sys/disk.h>
106 #include <sys/dtype.h>          /* DTYPE_* constants */
107 #include <sys/sysctl.h>
108 #include <machine/md_var.h>
109 #include <sys/ctype.h>
110 #include <sys/syslog.h>
111 #include <sys/device.h>
112 #include <sys/msgport.h>
113 #include <sys/msgport2.h>
114 #include <sys/buf2.h>
115
116 #include <vfs/ufs/dinode.h>     /* XXX used only for fs.h */
117 #include <vfs/ufs/fs.h>         /* XXX used only to get BBSIZE/SBSIZE */
118
119 static void partition_info(const char *sname, int part, struct partition32 *pp);
120 static void slice_info(const char *sname, struct diskslice *sp);
121 static const char *l32_fixlabel(const char *sname, struct diskslice *sp,
122                                 disklabel_t lpx, int writeflag);
123
124 /*
125  * Retrieve the partition start and extent, in blocks.  Return 0 on success,
126  * EINVAL on error.
127  */
128 static int
129 l32_getpartbounds(struct diskslices *ssp, disklabel_t lp, u_int32_t part,
130                   u_int64_t *start, u_int64_t *blocks)
131 {
132         struct partition32 *pp;
133
134         if (part >= lp.lab32->d_npartitions)
135                 return (EINVAL);
136         pp = &lp.lab32->d_partitions[part];
137         *start = pp->p_offset;
138         *blocks = pp->p_size;
139         return(0);
140 }
141
142 static void
143 l32_loadpartinfo(disklabel_t lp, u_int32_t part, struct partinfo *dpart)
144 {
145         struct partition32 *pp;
146         const size_t uuid_size = sizeof(struct uuid);
147
148         bzero(&dpart->fstype_uuid, uuid_size);
149         bzero(&dpart->storage_uuid, uuid_size);
150         if (part < lp.lab32->d_npartitions) {
151                 pp = &lp.lab32->d_partitions[part];
152                 dpart->fstype = pp->p_fstype;
153         } else {
154                 dpart->fstype = 0;
155         }
156 }
157
158 static u_int32_t
159 l32_getnumparts(disklabel_t lp)
160 {
161         return(lp.lab32->d_npartitions);
162 }
163
164 /*
165  * Attempt to read a disk label from a device.  
166  *
167  * Returns NULL on sucess, and an error string on failure
168  */
169 static const char *
170 l32_readdisklabel(cdev_t dev, struct diskslice *sp, disklabel_t *lpp,
171                 struct disk_info *info)
172 {
173         disklabel_t lpx;
174         struct buf *bp;
175         struct disklabel32 *dlp;
176         const char *msg = NULL;
177         int secsize = info->d_media_blksize;
178
179         bp = geteblk(secsize);
180         bp->b_bio1.bio_offset = (off_t)LABELSECTOR32 * secsize;
181         bp->b_bio1.bio_done = biodone_sync;
182         bp->b_bio1.bio_flags |= BIO_SYNC;
183         bp->b_bcount = secsize;
184         bp->b_flags &= ~B_INVAL;
185         bp->b_cmd = BUF_CMD_READ;
186         dev_dstrategy(dev, &bp->b_bio1);
187         if (biowait(&bp->b_bio1, "labrd"))
188                 msg = "I/O error";
189         else for (dlp = (struct disklabel32 *)bp->b_data;
190             dlp <= (struct disklabel32 *)((char *)bp->b_data +
191             secsize - sizeof(*dlp));
192             dlp = (struct disklabel32 *)((char *)dlp + sizeof(long))) {
193                 if (dlp->d_magic != DISKMAGIC32 ||
194                     dlp->d_magic2 != DISKMAGIC32) {
195                         /*
196                          * NOTE! dsreadandsetlabel() does a strcmp() on
197                          * this string.
198                          */
199                         if (msg == NULL) 
200                                 msg = "no disk label";
201                 } else if (dlp->d_npartitions > MAXPARTITIONS32 ||
202                            dkcksum32(dlp) != 0) {
203                         msg = "disk label corrupted";
204                 } else {
205                         lpx.lab32 = dlp;
206                         msg = l32_fixlabel(NULL, sp, lpx, FALSE);
207                         if (msg == NULL) {
208                                 (*lpp).lab32 = kmalloc(sizeof(*dlp),
209                                                        M_DEVBUF, M_WAITOK|M_ZERO);
210                                 *(*lpp).lab32 = *dlp;
211                         }
212                         break;
213                 }
214         }
215         bp->b_flags |= B_INVAL | B_AGE;
216         brelse(bp);
217         return (msg);
218 }
219
220 /*
221  * Check new disk label for sensibility before setting it.
222  */
223 static int
224 l32_setdisklabel(disklabel_t olpx, disklabel_t nlpx, struct diskslices *ssp,
225                  struct diskslice *sp, u_int32_t *openmask)
226 {
227         struct disklabel32 *olp, *nlp;
228         struct partition32 *opp, *npp;
229         int part;
230         int i;
231
232         olp = olpx.lab32;
233         nlp = nlpx.lab32;
234
235         /*
236          * Check it is actually a disklabel we are looking at.
237          */
238         if (nlp->d_magic != DISKMAGIC32 || nlp->d_magic2 != DISKMAGIC32 ||
239             dkcksum32(nlp) != 0)
240                 return (EINVAL);
241
242         /*
243          * For each partition that we think is open, check the new disklabel
244          * for compatibility.  Ignore special partitions (>= 128).
245          */
246         i = 0;
247         while (i < 128) {
248                 if (openmask[i >> 5] == 0) {
249                         i += 32;
250                         continue;
251                 }
252                 if ((openmask[i >> 5] & (1 << (i & 31))) == 0) {
253                         ++i;
254                         continue;
255                 }
256                 if (nlp->d_npartitions <= i)
257                         return (EBUSY);
258                 opp = &olp->d_partitions[i];
259                 npp = &nlp->d_partitions[i];
260                 if (npp->p_offset != opp->p_offset || npp->p_size < opp->p_size)
261                         return (EBUSY);
262                 /*
263                  * Copy internally-set partition information
264                  * if new label doesn't include it.             XXX
265                  * (If we are using it then we had better stay the same type)
266                  * This is possibly dubious, as someone else noted (XXX)
267                  */
268                 if (npp->p_fstype == FS_UNUSED && opp->p_fstype != FS_UNUSED) {
269                         npp->p_fstype = opp->p_fstype;
270                         npp->p_fsize = opp->p_fsize;
271                         npp->p_frag = opp->p_frag;
272                         npp->p_cpg = opp->p_cpg;
273                 }
274                 ++i;
275         }
276         nlp->d_checksum = 0;
277         nlp->d_checksum = dkcksum32(nlp);
278         *olp = *nlp;
279
280         if (olp->d_partitions[RAW_PART].p_offset)
281                 return (EXDEV);
282         if (olp->d_secperunit > sp->ds_size)
283                 return (ENOSPC);
284         for (part = 0; part < olp->d_npartitions; ++part) {
285                 if (olp->d_partitions[part].p_size > sp->ds_size)
286                         return(ENOSPC);
287         }
288         return (0);
289 }
290
291 /*
292  * Write disk label back to device after modification.
293  */
294 static int
295 l32_writedisklabel(cdev_t dev, struct diskslices *ssp, struct diskslice *sp,
296                    disklabel_t lpx)
297 {
298         struct disklabel32 *lp;
299         struct disklabel32 *dlp;
300         struct buf *bp;
301         const char *msg;
302         int error = 0;
303
304         lp = lpx.lab32;
305
306         if (lp->d_partitions[RAW_PART].p_offset != 0)
307                 return (EXDEV);                 /* not quite right */
308         bp = geteblk((int)lp->d_secsize);
309         bp->b_bio1.bio_offset = (off_t)LABELSECTOR32 * lp->d_secsize;
310         bp->b_bio1.bio_done = biodone_sync;
311         bp->b_bio1.bio_flags |= BIO_SYNC;
312         bp->b_bcount = lp->d_secsize;
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         dev_dstrategy(dkmodpart(dev, WHOLE_SLICE_PART), &bp->b_bio1);
324         error = biowait(&bp->b_bio1, "labrd");
325         if (error)
326                 goto done;
327         for (dlp = (struct disklabel32 *)bp->b_data;
328             dlp <= (struct disklabel32 *)
329               ((char *)bp->b_data + lp->d_secsize - sizeof(*dlp));
330             dlp = (struct disklabel32 *)((char *)dlp + sizeof(long))) {
331                 if (dlp->d_magic == DISKMAGIC32 &&
332                     dlp->d_magic2 == DISKMAGIC32 && dkcksum32(dlp) == 0) {
333                         *dlp = *lp;
334                         lpx.lab32 = dlp;
335                         msg = l32_fixlabel(NULL, sp, lpx, TRUE);
336                         if (msg) {
337                                 error = EINVAL;
338                         } else {
339                                 bp->b_cmd = BUF_CMD_WRITE;
340                                 bp->b_bio1.bio_done = biodone_sync;
341                                 bp->b_bio1.bio_flags |= BIO_SYNC;
342                                 dev_dstrategy(dkmodpart(dev, WHOLE_SLICE_PART),
343                                               &bp->b_bio1);
344                                 error = biowait(&bp->b_bio1, "labwr");
345                         }
346                         goto done;
347                 }
348         }
349         error = ESRCH;
350 done:
351 #else
352         bzero(bp->b_data, lp->d_secsize);
353         dlp = (struct disklabel32 *)bp->b_data;
354         *dlp = *lp;
355         bp->b_flags &= ~B_INVAL;
356         bp->b_cmd = BUF_CMD_WRITE;
357         bp->b_bio1.bio_done = biodone_sync;
358         bp->b_bio1.bio_flags |= BIO_SYNC;
359         BUF_STRATEGY(bp, 1);
360         error = biowait(&bp->b_bio1, "labwr");
361 #endif
362         bp->b_flags |= B_INVAL | B_AGE;
363         brelse(bp);
364         return (error);
365 }
366
367 /*
368  * Create a disklabel based on a disk_info structure, initializing
369  * the appropriate fields and creating a raw partition that covers the
370  * whole disk.
371  *
372  * If a diskslice is passed, the label is truncated to the slice
373  */
374 static disklabel_t
375 l32_clone_label(struct disk_info *info, struct diskslice *sp)
376 {
377         struct disklabel32 *lp;
378         disklabel_t res;
379
380         lp = kmalloc(sizeof *lp, M_DEVBUF, M_WAITOK | M_ZERO);
381         lp->d_nsectors = info->d_secpertrack;
382         lp->d_ntracks = info->d_nheads;
383         lp->d_secpercyl = info->d_secpercyl;
384         lp->d_secsize = info->d_media_blksize;
385
386         if (sp)
387                 lp->d_secperunit = (u_int)sp->ds_size;
388         else
389                 lp->d_secperunit = (u_int)info->d_media_blocks;
390
391         if (lp->d_typename[0] == '\0')
392                 strncpy(lp->d_typename, "amnesiac", sizeof(lp->d_typename));
393         if (lp->d_packname[0] == '\0')
394                 strncpy(lp->d_packname, "fictitious", sizeof(lp->d_packname));
395         if (lp->d_nsectors == 0)
396                 lp->d_nsectors = 32;
397         if (lp->d_ntracks == 0)
398                 lp->d_ntracks = 64;
399         lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks;
400         lp->d_ncylinders = lp->d_secperunit / lp->d_secpercyl;
401         if (lp->d_rpm == 0)
402                 lp->d_rpm = 3600;
403         if (lp->d_interleave == 0)
404                 lp->d_interleave = 1;
405         if (lp->d_npartitions < RAW_PART + 1)
406                 lp->d_npartitions = MAXPARTITIONS32;
407         if (lp->d_bbsize == 0)
408                 lp->d_bbsize = BBSIZE;
409         if (lp->d_sbsize == 0)
410                 lp->d_sbsize = SBSIZE;
411
412         /*
413          * Used by various devices to create a compatibility slice which
414          * allows us to mount root from devices which do not have a
415          * disklabel.  Particularly: CDs.
416          */
417         lp->d_partitions[RAW_PART].p_size = lp->d_secperunit;
418         if (info->d_dsflags & DSO_COMPATPARTA) {
419                 lp->d_partitions[0].p_size = lp->d_secperunit;
420                 lp->d_partitions[0].p_fstype = FS_OTHER;
421         }
422         lp->d_magic = DISKMAGIC32;
423         lp->d_magic2 = DISKMAGIC32;
424         lp->d_checksum = dkcksum32(lp);
425         res.lab32 = lp;
426         return (res);
427 }
428
429 static void
430 l32_makevirginlabel(disklabel_t lpx, struct diskslices *ssp,
431                     struct diskslice *sp, struct disk_info *info)
432 {
433         struct disklabel32 *lp = lpx.lab32;
434         struct partition32 *pp;
435         disklabel_t template;
436
437         template = l32_clone_label(info, NULL);
438         bcopy(template.opaque, lp, sizeof(struct disklabel32));
439
440         lp->d_magic = DISKMAGIC32;
441         lp->d_magic2 = DISKMAGIC32;
442
443         lp->d_npartitions = MAXPARTITIONS32;
444         if (lp->d_interleave == 0)
445                 lp->d_interleave = 1;
446         if (lp->d_rpm == 0)
447                 lp->d_rpm = 3600;
448         if (lp->d_nsectors == 0)        /* sectors per track */
449                 lp->d_nsectors = 32;
450         if (lp->d_ntracks == 0)         /* heads */
451                 lp->d_ntracks = 64;
452         lp->d_ncylinders = 0;
453         lp->d_bbsize = BBSIZE;
454         lp->d_sbsize = SBSIZE;
455
456         /*
457          * If the slice or GPT partition is really small we could
458          * wind up with an absurd calculation for ncylinders.
459          */
460         while (lp->d_ncylinders < 4) {
461                 if (lp->d_ntracks > 1)
462                         lp->d_ntracks >>= 1;
463                 else if (lp->d_nsectors > 1)
464                         lp->d_nsectors >>= 1;
465                 else
466                         break;
467                 lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks;
468                 lp->d_ncylinders = sp->ds_size / lp->d_secpercyl;
469         }
470
471         /*
472          * Set or Modify the partition sizes to accomodate the slice,
473          * since we started with a copy of the virgin label stored
474          * in the whole-disk-slice and we are probably not a
475          * whole-disk slice.
476          */
477         lp->d_secperunit = sp->ds_size;
478         pp = &lp->d_partitions[RAW_PART];
479         pp->p_offset = 0;
480         pp->p_size = lp->d_secperunit;
481         if (info->d_dsflags & DSO_COMPATPARTA) {
482                 pp = &lp->d_partitions[0];
483                 pp->p_offset = 0;
484                 pp->p_size = lp->d_secperunit;
485                 pp->p_fstype = FS_OTHER;
486         }
487         lp->d_checksum = 0;
488         lp->d_checksum = dkcksum32(lp);
489
490         kfree(template.opaque, M_DEVBUF);
491 }
492
493 static const char *
494 l32_fixlabel(const char *sname, struct diskslice *sp,
495              disklabel_t lpx, int writeflag)
496 {
497         struct disklabel32 *lp;
498         struct partition32 *pp;
499         u_int64_t start;
500         u_int64_t end;
501         u_int64_t offset;
502         int part;
503         int warned;
504
505         lp = lpx.lab32;
506
507         /* These errors "can't happen" so don't bother reporting details. */
508         if (lp->d_magic != DISKMAGIC32 || lp->d_magic2 != DISKMAGIC32)
509                 return ("fixlabel: invalid magic");
510         if (dkcksum32(lp) != 0)
511                 return ("fixlabel: invalid checksum");
512
513         pp = &lp->d_partitions[RAW_PART];
514
515         /*
516          * What a mess.  For ages old backwards compatibility the disklabel
517          * on-disk stores absolute offsets instead of slice-relative offsets.
518          * So fix it up when reading, writing, or snooping.
519          *
520          * The in-core label is always slice-relative.
521          */
522         if (writeflag) {
523                 start = 0;
524                 offset = sp->ds_offset;
525         } else {
526                 start = sp->ds_offset;
527                 offset = -sp->ds_offset;
528         }
529         if (pp->p_offset != start) {
530                 if (sname != NULL) {
531                         kprintf(
532 "%s: rejecting BSD label: raw partition offset != slice offset\n",
533                                sname);
534                         slice_info(sname, sp);
535                         partition_info(sname, RAW_PART, pp);
536                 }
537                 return ("fixlabel: raw partition offset != slice offset");
538         }
539         if (pp->p_size != sp->ds_size) {
540                 if (sname != NULL) {
541                         kprintf("%s: raw partition size != slice size\n", sname);
542                         slice_info(sname, sp);
543                         partition_info(sname, RAW_PART, pp);
544                 }
545                 if (pp->p_size > sp->ds_size) {
546                         if (sname == NULL)
547                                 return ("fixlabel: raw partition size > slice size");
548                         kprintf("%s: truncating raw partition\n", sname);
549                         pp->p_size = sp->ds_size;
550                 }
551         }
552         end = start + sp->ds_size;
553         if (start > end)
554                 return ("fixlabel: slice wraps");
555         if (lp->d_secpercyl <= 0)
556                 return ("fixlabel: d_secpercyl <= 0");
557         pp -= RAW_PART;
558         warned = FALSE;
559         for (part = 0; part < lp->d_npartitions; part++, pp++) {
560                 if (pp->p_offset != 0 || pp->p_size != 0) {
561                         if (pp->p_offset < start
562                             || pp->p_offset + pp->p_size > end
563                             || pp->p_offset + pp->p_size < pp->p_offset) {
564                                 if (sname != NULL) {
565                                         kprintf(
566 "%s: rejecting partition in BSD label: it isn't entirely within the slice\n",
567                                                sname);
568                                         if (!warned) {
569                                                 slice_info(sname, sp);
570                                                 warned = TRUE;
571                                         }
572                                         partition_info(sname, part, pp);
573                                 }
574                                 /* XXX else silently discard junk. */
575                                 bzero(pp, sizeof *pp);
576                         } else {
577                                 pp->p_offset += offset;
578                         }
579                 }
580         }
581         lp->d_ncylinders = sp->ds_size / lp->d_secpercyl;
582         lp->d_secperunit = sp->ds_size;
583         lp->d_checksum = 0;
584         lp->d_checksum = dkcksum32(lp);
585         return (NULL);
586 }
587
588 /*
589  * Set the number of blocks at the beginning of the slice which have
590  * been reserved for label operations.  This area will be write-protected
591  * when accessed via the slice.
592  */
593 static void
594 l32_adjust_label_reserved(struct diskslices *ssp, int slice,
595                           struct diskslice *sp)
596 {
597         /*struct disklabel32 *lp = sp->ds_label.lab32;*/
598         sp->ds_reserved = SBSIZE / ssp->dss_secsize;
599 }
600
601 static void
602 partition_info(const char *sname, int part, struct partition32 *pp)
603 {
604         kprintf("%s%c: start %lu, end %lu, size %lu\n", sname, 'a' + part,
605                 (u_long)pp->p_offset, (u_long)(pp->p_offset + pp->p_size - 1),
606                 (u_long)pp->p_size);
607 }
608
609 static void
610 slice_info(const char *sname, struct diskslice *sp)
611 {
612         kprintf("%s: start %llu, end %llu, size %llu\n", sname,
613                (long long)sp->ds_offset,
614                (long long)sp->ds_offset + sp->ds_size - 1,
615                (long long)sp->ds_size);
616 }
617
618 struct disklabel_ops disklabel32_ops = {
619         .labelsize = sizeof(struct disklabel32),
620         .op_readdisklabel = l32_readdisklabel,
621         .op_setdisklabel = l32_setdisklabel,
622         .op_writedisklabel = l32_writedisklabel,
623         .op_clone_label = l32_clone_label,
624         .op_adjust_label_reserved = l32_adjust_label_reserved,
625         .op_getpartbounds = l32_getpartbounds,
626         .op_loadpartinfo = l32_loadpartinfo,
627         .op_getnumparts = l32_getnumparts,
628         .op_makevirginlabel = l32_makevirginlabel
629 };
630