[BACK]Return to diskio.c CVS log [TXT][DIR] Up to [local] / sys / arch / sgi / stand / boot

Annotation of sys/arch/sgi/stand/boot/diskio.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: diskio.c,v 1.2 2004/09/16 18:54:48 pefo Exp $ */
        !             2:
        !             3: /*
        !             4:  * Copyright (c) 2000 Opsycon AB  (www.opsycon.se)
        !             5:  * Copyright (c) 2000 Rtmx, Inc   (www.rtmx.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:  * 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. All advertising materials mentioning features or use of this software
        !            16:  *    must display the following acknowledgement:
        !            17:  *     This product includes software developed for Rtmx, Inc by
        !            18:  *     Opsycon Open System Consulting AB, Sweden.
        !            19:  * 4. The name of the author may not be used to endorse or promote products
        !            20:  *    derived from this software without specific prior written permission.
        !            21:  *
        !            22:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
        !            23:  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
        !            24:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            25:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
        !            26:  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            27:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            28:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            29:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            30:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            31:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            32:  * SUCH DAMAGE.
        !            33:  *
        !            34:  */
        !            35:
        !            36: #include <stand.h>
        !            37: #include <sys/param.h>
        !            38: #include <sys/disklabel.h>
        !            39: #include <mips64/arcbios.h>
        !            40:
        !            41:
        !            42: struct dio_softc {
        !            43:        int     sc_fd;                  /* PROM file id */
        !            44:        int     sc_part;                /* disk partition number */
        !            45:        struct  disklabel sc_label;     /* disk label for this disk */
        !            46: };
        !            47:
        !            48: int
        !            49: diostrategy(void *devdata, int rw, daddr_t bn, u_int reqcnt,
        !            50:                char *addr, u_int *cnt)
        !            51: {
        !            52:        struct dio_softc *sc = (struct dio_softc *)devdata;
        !            53:        struct partition *pp = &sc->sc_label.d_partitions[sc->sc_part];
        !            54:        int64_t offset;
        !            55:        int result;
        !            56:
        !            57:        offset = (pp->p_offset + bn) * DEV_BSIZE;
        !            58:
        !            59:        if ((Bios_Seek(sc->sc_fd, &offset, 0) < 0) ||
        !            60:            (Bios_Read(sc->sc_fd, addr, reqcnt, &result) < 0))
        !            61:                return EIO;
        !            62:
        !            63:        *cnt = result;
        !            64:        return (0);
        !            65: }
        !            66:
        !            67: int
        !            68: dioopen(struct open_file *f, ...)
        !            69: {
        !            70:        char *ctlr;
        !            71:        int partition;
        !            72:
        !            73:        struct dio_softc *sc;
        !            74:        struct disklabel *lp;
        !            75:        int fd;
        !            76:        daddr_t labelsector;
        !            77:        va_list ap;
        !            78:
        !            79:        va_start(ap, f);
        !            80:
        !            81:        ctlr = va_arg(ap, char *);
        !            82:        partition = va_arg(ap, int);
        !            83:        if (partition >= MAXPARTITIONS)
        !            84:                return (ENXIO);
        !            85:
        !            86:        if (Bios_Open(ctlr, 0, &fd) < 0)
        !            87:                return (ENXIO);
        !            88:
        !            89:        sc = alloc(sizeof(struct dio_softc));
        !            90:        bzero(sc, sizeof(struct dio_softc));
        !            91:        f->f_devdata = (void *)sc;
        !            92:
        !            93:        sc->sc_fd = fd;
        !            94:        sc->sc_part = partition;
        !            95:
        !            96:        lp = &sc->sc_label;
        !            97:        lp->d_secsize = DEV_BSIZE;
        !            98:        lp->d_secpercyl = 1;
        !            99:        lp->d_npartitions = MAXPARTITIONS;
        !           100:        lp->d_partitions[partition].p_offset = 0;
        !           101:        lp->d_partitions[0].p_size = 0x7fff0000;
        !           102:
        !           103:        labelsector = LABELSECTOR;
        !           104:
        !           105: #if 0
        !           106:        /* try to read disk label and partition table information */
        !           107:        i = diostrategy(sc, F_READ, (daddr_t)labelsector, DEV_BSIZE, buf, &cnt);
        !           108:
        !           109:        if (i == 0 && cnt == DEV_BSIZE)
        !           110:                msg = getdisklabel(buf, lp);
        !           111:        else
        !           112:                msg = "rd err";
        !           113:
        !           114:        if (msg) {
        !           115:                printf("%s: %s\n", ctlr, msg);
        !           116:                return ENXIO;
        !           117:        }
        !           118: #endif
        !           119:
        !           120:        return 0;
        !           121: }
        !           122:
        !           123: int
        !           124: dioclose(f)
        !           125:        struct open_file *f;
        !           126: {
        !           127:        Bios_Close(((struct dio_softc *)f->f_devdata)->sc_fd);
        !           128:        free(f->f_devdata, sizeof(struct dio_softc));
        !           129:        f->f_devdata = NULL;
        !           130:        return 0;
        !           131: }

CVSweb