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

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

1.1       nbrk        1: /*     $OpenBSD: disksubr.c,v 1.41 2007/06/20 18:15:45 deraadt Exp $   */
                      2: /*     $NetBSD: disksubr.c,v 1.9 1997/04/01 03:12:13 scottr Exp $      */
                      3:
                      4: /*
                      5:  * Copyright (c) 1982, 1986, 1988, 1993
                      6:  *     The Regents of the University of California.  All rights reserved.
                      7:  * (c) UNIX System Laboratories, Inc.
                      8:  * All or some portions of this file are derived from material licensed
                      9:  * to the University of California by American Telephone and Telegraph
                     10:  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
                     11:  * the permission of UNIX System Laboratories, Inc.
                     12:  *
                     13:  * Redistribution and use in source and binary forms, with or without
                     14:  * modification, are permitted provided that the following conditions
                     15:  * are met:
                     16:  * 1. Redistributions of source code must retain the above copyright
                     17:  *    notice, this list of conditions and the following disclaimer.
                     18:  * 2. Redistributions in binary form must reproduce the above copyright
                     19:  *    notice, this list of conditions and the following disclaimer in the
                     20:  *    documentation and/or other materials provided with the distribution.
                     21:  * 3. Neither the name of the University nor the names of its contributors
                     22:  *    may be used to endorse or promote products derived from this software
                     23:  *    without specific prior written permission.
                     24:  *
                     25:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     26:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     27:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     28:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     29:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     30:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     31:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     32:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     33:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     34:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     35:  * SUCH DAMAGE.
                     36:  */
                     37:
                     38: #include <sys/param.h>
                     39: #include <sys/systm.h>
                     40: #include <sys/buf.h>
                     41: #include <sys/disk.h>
                     42: #include <sys/disklabel.h>
                     43: #include <sys/syslog.h>
                     44:
                     45: /*
                     46:  * Attempt to read a disk label from a device using the indicated strategy
                     47:  * routine.  The label must be partly set up before this: secpercyl and
                     48:  * anything required in the strategy routine (e.g., sector size) must be
                     49:  * filled in before calling us.  Returns null on success and an error
                     50:  * string on failure.
                     51:  */
                     52: char *
                     53: readdisklabel(dev_t dev, void (*strat)(struct buf *),
                     54:     struct disklabel *lp, int spoofonly)
                     55: {
                     56:        struct buf *bp = NULL;
                     57:        char *msg;
                     58:
                     59:        if ((msg = initdisklabel(lp)))
                     60:                goto done;
                     61:
                     62:        bp = geteblk((int)lp->d_secsize);
                     63:        bp->b_dev = dev;
                     64:
                     65:        /* don't read the on-disk label if we are in spoofed-only mode */
                     66:        if (spoofonly)
                     67:                goto done;
                     68:
                     69:        bp->b_blkno = LABELSECTOR;
                     70:        bp->b_bcount = lp->d_secsize;
                     71:        bp->b_flags = B_BUSY | B_READ;
                     72:        (*strat)(bp);
                     73:        if (biowait(bp)) {
                     74:                msg = "disk label I/O error";
                     75:                goto done;
                     76:        }
                     77:
                     78:        msg = checkdisklabel(bp->b_data + LABELOFFSET, lp);
                     79:        if (msg == NULL)
                     80:                goto done;
                     81:
                     82: #if defined(CD9660)
                     83:        if (iso_disklabelspoof(dev, strat, lp) == 0) {
                     84:                msg = NULL;
                     85:                goto done;
                     86:        }
                     87: #endif
                     88: #if defined(UDF)
                     89:        if (udf_disklabelspoof(dev, strat, lp) == 0) {
                     90:                msg = NULL;
                     91:                goto done;
                     92:        }
                     93: #endif
                     94:
                     95: done:
                     96:        if (bp) {
                     97:                bp->b_flags |= B_INVAL;
                     98:                brelse(bp);
                     99:        }
                    100:        return (msg);
                    101: }
                    102:
                    103: /*
                    104:  * Write disk label back to device after modification.
                    105:  */
                    106: int
                    107: writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp)
                    108: {
                    109:        struct buf *bp = NULL;
                    110:        struct disklabel *dlp;
                    111:        int error = 0;
                    112:
                    113:        /* get a buffer and initialize it */
                    114:        bp = geteblk((int)lp->d_secsize);
                    115:        bp->b_dev = dev;
                    116:        bp->b_blkno = LABELSECTOR;
                    117:        bp->b_bcount = lp->d_secsize;
                    118:        bp->b_flags = B_BUSY | B_READ;
                    119:        (*strat)(bp);
                    120:        if ((error = biowait(bp)) != 0)
                    121:                goto done;
                    122:
                    123:        /* Write it in the regular place. */
                    124:        dlp = (struct disklabel *)(bp->b_data + LABELOFFSET);
                    125:        *dlp = *lp;
                    126:        bp->b_flags = B_BUSY | B_WRITE;
                    127:        (*strat)(bp);
                    128:        error = biowait(bp);
                    129:
                    130: done:
                    131:        if (bp) {
                    132:                bp->b_flags |= B_INVAL;
                    133:                brelse(bp);
                    134:        }
                    135:        return (error);
                    136: }

CVSweb