[BACK]Return to disksubr.c CVS log [TXT][DIR] Up to [local] / sys / arch / mvme68k / mvme68k

Annotation of sys/arch/mvme68k/mvme68k/disksubr.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: disksubr.c,v 1.60 2007/06/20 18:15:46 deraadt Exp $   */
                      2: /*
                      3:  * Copyright (c) 1998 Steve Murphree, Jr.
                      4:  * Copyright (c) 1995 Dale Rahn.
                      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. The name of the author may not be used to endorse or promote products
                     16:  *    derived from this software without specific prior written permission.
                     17:  *
                     18:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     19:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     20:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     21:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     22:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     23:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     24:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     25:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     26:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     27:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     28:  */
                     29:
                     30: #include <sys/param.h>
                     31: #include <sys/systm.h>
                     32: #include <sys/buf.h>
                     33: #include <sys/disklabel.h>
                     34: #include <sys/disk.h>
                     35:
                     36: void bsdtocpulabel(struct disklabel *, struct mvmedisklabel *);
                     37: void cputobsdlabel(struct disklabel *, struct mvmedisklabel *);
                     38:
                     39: /*
                     40:  * Attempt to read a disk label from a device
                     41:  * using the indicated strategy routine.
                     42:  * The label must be partly set up before this:
                     43:  * secpercyl and anything required in the strategy routine
                     44:  * (e.g., sector size) must be filled in before calling us.
                     45:  * Returns NULL on success and an error string on failure.
                     46:  */
                     47:
                     48: char *
                     49: readdisklabel(dev_t dev, void (*strat)(struct buf *),
                     50:     struct disklabel *lp, int spoofonly)
                     51: {
                     52:        struct buf *bp = NULL;
                     53:        struct mvmedisklabel *mlp;
                     54:        int error;
                     55:        char *msg;
                     56:
                     57:        if ((msg = initdisklabel(lp)))
                     58:                goto done;
                     59:
                     60:        /* get a buffer and initialize it */
                     61:        bp = geteblk((int)lp->d_secsize);
                     62:        bp->b_dev = dev;
                     63:
                     64:        /* don't read the on-disk label if we are in spoofed-only mode */
                     65:        if (spoofonly)
                     66:                goto done;
                     67:
                     68:        bp->b_blkno = LABELSECTOR;
                     69:        bp->b_bcount = lp->d_secsize;
                     70:        bp->b_flags = B_BUSY | B_READ;
                     71:        (*strat)(bp);
                     72:        error = biowait(bp);
                     73:        if (error) {
                     74:                msg = "disk label read error";
                     75:                goto done;
                     76:        }
                     77:
                     78:        mlp = (struct mvmedisklabel *)bp->b_data;
                     79:        if (mlp->magic1 != DISKMAGIC || mlp->magic2 != DISKMAGIC) {
                     80:                msg = "no disk label";
                     81:                goto done;
                     82:        }
                     83:
                     84:        cputobsdlabel(lp, mlp);
                     85:        if (dkcksum(lp) == 0)
                     86:                goto done;
                     87:        msg = "disk label corrupted";
                     88:
                     89: #if defined(CD9660)
                     90:        if (iso_disklabelspoof(dev, strat, lp) == 0) {
                     91:                msg = NULL;
                     92:                goto done;
                     93:        }
                     94: #endif
                     95: #if defined(UDF)
                     96:        if (udf_disklabelspoof(dev, strat, lp) == 0) {
                     97:                msg = NULL;
                     98:                goto done;
                     99:        }
                    100: #endif
                    101:
                    102: done:
                    103:        if (bp) {
                    104:                bp->b_flags |= B_INVAL;
                    105:                brelse(bp);
                    106:        }
                    107:        return (msg);
                    108: }
                    109:
                    110: /*
                    111:  * Write disk label back to device after modification.
                    112:  */
                    113: int
                    114: writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp)
                    115: {
                    116:        struct buf *bp = NULL;
                    117:        int error;
                    118:
                    119:        /* get a buffer and initialize it */
                    120:        bp = geteblk((int)lp->d_secsize);
                    121:        bp->b_dev = dev;
                    122:
                    123:        bp->b_blkno = LABELSECTOR;
                    124:        bp->b_bcount = lp->d_secsize;
                    125:        bp->b_flags = B_BUSY | B_READ;
                    126:        (*strat)(bp);
                    127:        if ((error = biowait(bp)) != 0)
                    128:                goto done;
                    129:
                    130:        bsdtocpulabel(lp, (struct mvmedisklabel *)bp->b_data);
                    131:
                    132:        bp->b_flags = B_BUSY | B_WRITE;
                    133:        (*strat)(bp);
                    134:        error = biowait(bp);
                    135:
                    136: done:
                    137:        if (bp) {
                    138:                bp->b_flags |= B_INVAL;
                    139:                brelse(bp);
                    140:        }
                    141:        return (error);
                    142: }
                    143:
                    144: void
                    145: bsdtocpulabel(struct disklabel *lp, struct mvmedisklabel *clp)
                    146: {
                    147:        char *tmot = "MOTOROLA", *id = "M68K", *mot;
                    148:        int i;
                    149:
                    150:        clp->magic1 = lp->d_magic;
                    151:        clp->type = lp->d_type;
                    152:        clp->subtype = lp->d_subtype;
                    153:        strncpy(clp->vid_vd, lp->d_typename, 16);
                    154:        strncpy(clp->packname, lp->d_packname, 16);
                    155:        clp->cfg_psm = lp->d_secsize;
                    156:        clp->cfg_spt = lp->d_nsectors;
                    157:        clp->cfg_trk = lp->d_ncylinders;        /* trk is really num of cyl! */
                    158:        clp->cfg_hds = lp->d_ntracks;
                    159:
                    160:        clp->secpercyl = lp->d_secpercyl;
                    161:        clp->secperunit = DL_GETDSIZE(lp);
                    162:        clp->sparespertrack = lp->d_sparespertrack;
                    163:        clp->sparespercyl = lp->d_sparespercyl;
                    164:        clp->acylinders = lp->d_acylinders;
                    165:        clp->rpm = lp->d_rpm;
                    166:
                    167:        clp->cfg_ilv = lp->d_interleave;
                    168:        clp->cfg_sof = lp->d_trackskew;
                    169:        clp->cylskew = lp->d_cylskew;
                    170:        clp->headswitch = lp->d_headswitch;
                    171:
                    172:        /* this silly table is for winchester drives */
                    173:        if (lp->d_trkseek < 6)
                    174:                clp->cfg_ssr = 0;
                    175:        else if (lp->d_trkseek < 10)
                    176:                clp->cfg_ssr = 1;
                    177:        else if (lp->d_trkseek < 15)
                    178:                clp->cfg_ssr = 2;
                    179:        else if (lp->d_trkseek < 20)
                    180:                clp->cfg_ssr = 3;
                    181:        else
                    182:                clp->cfg_ssr = 4;
                    183:
                    184:        clp->flags = lp->d_flags;
                    185:        for (i = 0; i < NDDATA; i++)
                    186:                clp->drivedata[i] = lp->d_drivedata[i];
                    187:        for (i = 0; i < NSPARE; i++)
                    188:                clp->spare[i] = lp->d_spare[i];
                    189:
                    190:        clp->magic2 = lp->d_magic2;
                    191:        clp->checksum = lp->d_checksum;
                    192:        clp->partitions = lp->d_npartitions;
                    193:        clp->bbsize = lp->d_bbsize;
                    194:        clp->sbsize = lp->d_sbsize;
                    195:        clp->checksum = lp->d_checksum;
                    196:        bcopy(&lp->d_partitions[0], clp->vid_4, sizeof(struct partition) * 4);
                    197:        bcopy(&lp->d_partitions[4], clp->cfg_4, sizeof(struct partition) * 12);
                    198:        clp->version = 2;
                    199:
                    200:        /* Put "MOTOROLA" in the VID. This makes it a valid boot disk. */
                    201:        for (mot = clp->vid_mot, i = 0; i < 8; i++)
                    202:                *mot++ = *tmot++;
                    203:
                    204:        /* put volume id in the VID */
                    205:        for (mot = clp->vid_id, i = 0; i < 4; i++)
                    206:                *mot++ = *id++;
                    207: }
                    208:
                    209: void
                    210: cputobsdlabel(struct disklabel *lp, struct mvmedisklabel *clp)
                    211: {
                    212:        int i;
                    213:
                    214:        lp->d_magic = clp->magic1;
                    215:        lp->d_type = clp->type;
                    216:        lp->d_subtype = clp->subtype;
                    217:        strncpy(lp->d_typename, clp->vid_vd, sizeof lp->d_typename);
                    218:        strncpy(lp->d_packname, clp->packname, sizeof lp->d_packname);
                    219:        lp->d_secsize = clp->cfg_psm;
                    220:        lp->d_nsectors = clp->cfg_spt;
                    221:        lp->d_ncylinders = clp->cfg_trk; /* trk is really num of cyl! */
                    222:        lp->d_ntracks = clp->cfg_hds;
                    223:
                    224:        lp->d_secpercyl = clp->secpercyl;
                    225:        if (DL_GETDSIZE(lp) == 0)
                    226:                DL_SETDSIZE(lp, clp->secperunit);
                    227:        lp->d_sparespertrack = clp->sparespertrack;
                    228:        lp->d_sparespercyl = clp->sparespercyl;
                    229:        lp->d_acylinders = clp->acylinders;
                    230:        lp->d_rpm = clp->rpm;
                    231:        lp->d_interleave = clp->cfg_ilv;
                    232:        lp->d_trackskew = clp->cfg_sof;
                    233:        lp->d_cylskew = clp->cylskew;
                    234:        lp->d_headswitch = clp->headswitch;
                    235:
                    236:        /* this silly table is for winchester drives */
                    237:        switch (clp->cfg_ssr) {
                    238:        case 1:
                    239:                lp->d_trkseek = 6;
                    240:                break;
                    241:        case 2:
                    242:                lp->d_trkseek = 10;
                    243:                break;
                    244:        case 3:
                    245:                lp->d_trkseek = 15;
                    246:                break;
                    247:        case 4:
                    248:                lp->d_trkseek = 20;
                    249:                break;
                    250:        default:
                    251:                lp->d_trkseek = 0;
                    252:        }
                    253:
                    254:        lp->d_flags = clp->flags;
                    255:        for (i = 0; i < NDDATA; i++)
                    256:                lp->d_drivedata[i] = clp->drivedata[i];
                    257:        for (i = 0; i < NSPARE; i++)
                    258:                lp->d_spare[i] = clp->spare[i];
                    259:
                    260:        lp->d_magic2 = clp->magic2;
                    261:        lp->d_npartitions = clp->partitions;
                    262:        lp->d_bbsize = clp->bbsize;
                    263:        lp->d_sbsize = clp->sbsize;
                    264:
                    265:        bcopy(clp->vid_4, &lp->d_partitions[0], sizeof(struct partition) * 4);
                    266:        bcopy(clp->cfg_4, &lp->d_partitions[4], sizeof(struct partition) * 12);
                    267:
                    268:        if (clp->version < 2) {
                    269:                struct __partitionv0 *v0pp = (struct __partitionv0 *)lp->d_partitions;
                    270:                struct partition *pp = lp->d_partitions;
                    271:
                    272:                for (i = 0; i < lp->d_npartitions; i++, pp++, v0pp++) {
                    273:                        pp->p_fragblock = DISKLABELV1_FFS_FRAGBLOCK(v0pp->
                    274:                            p_fsize, v0pp->p_frag);
                    275:                        pp->p_offseth = 0;
                    276:                        pp->p_sizeh = 0;
                    277:                }
                    278:        }
                    279:
                    280:        lp->d_version = 1;
                    281:        lp->d_checksum = 0;
                    282:        lp->d_checksum = dkcksum(lp);
                    283: }

CVSweb