/* $OpenBSD: chklabel.c,v 1.2 1998/08/22 08:49:16 smurph Exp $ */ /* * Copyright (c) 1993 Paul Kranenburg * 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 Paul Kranenburg. * 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 #include #include void cputobsdlabel __P((struct disklabel *lp, struct cpu_disklabel *clp)); main(int argc, char *argv[]) { struct cpu_disklabel cpu_label; struct disklabel sdlabel; int i; fread((void *)&cpu_label, sizeof(struct cpu_disklabel), 1, stdin); cputobsdlabel(&sdlabel, (struct cpu_disklabel *)&cpu_label); for (i = 0; i < MAXPARTITIONS; i++) { printf("part %x off %x size %x\n", i, sdlabel.d_partitions[i].p_offset, sdlabel.d_partitions[i].p_size); } } void cputobsdlabel(struct disklabel *lp, struct cpu_disklabel *clp) { int i; lp->d_magic = clp->magic1; lp->d_type = clp->type; lp->d_subtype = clp->subtype; bcopy(clp->vid_vd, lp->d_typename, 16); bcopy(clp->packname, lp->d_packname, 16); lp->d_secsize = clp->cfg_psm; lp->d_nsectors = clp->cfg_spt; lp->d_ncylinders = clp->cfg_trk; /* trk is really num of cyl! */ lp->d_ntracks = clp->cfg_hds; lp->d_secpercyl = clp->secpercyl; lp->d_secperunit = clp->secperunit; lp->d_secpercyl = clp->secpercyl; lp->d_secperunit = clp->secperunit; lp->d_sparespertrack = clp->sparespertrack; lp->d_sparespercyl = clp->sparespercyl; lp->d_acylinders = clp->acylinders; lp->d_rpm = clp->rpm; lp->d_interleave = clp->cfg_ilv; lp->d_trackskew = clp->cfg_sof; lp->d_cylskew = clp->cylskew; lp->d_headswitch = clp->headswitch; /* this silly table is for winchester drives */ switch (clp->cfg_ssr) { case 0: lp->d_trkseek = 0; break; case 1: lp->d_trkseek = 6; break; case 2: lp->d_trkseek = 10; break; case 3: lp->d_trkseek = 15; break; case 4: lp->d_trkseek = 20; break; default: lp->d_trkseek = 0; break; } lp->d_flags = clp->flags; for (i = 0; i < NDDATA; i++) lp->d_drivedata[i] = clp->drivedata[i]; for (i = 0; i < NSPARE; i++) lp->d_spare[i] = clp->spare[i]; lp->d_magic2 = clp->magic2; lp->d_checksum = clp->checksum; lp->d_npartitions = clp->partitions; lp->d_bbsize = clp->bbsize; lp->d_sbsize = clp->sbsize; bcopy(clp->vid_4, &(lp->d_partitions[0]), sizeof (struct partition) * 4); bcopy(clp->cfg_4, &(lp->d_partitions[4]), sizeof (struct partition) * 12); }