[BACK]Return to rawfs.c CVS log [TXT][DIR] Up to [local] / sys / arch / mvmeppc / stand / libsa

Annotation of sys/arch/mvmeppc/stand/libsa/rawfs.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: rawfs.c,v 1.2 2002/03/14 01:26:41 millert Exp $ */
        !             2:
        !             3: /*
        !             4:  * Copyright (c) 1995 Gordon W. Ross
        !             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:  * 4. All advertising materials mentioning features or use of this software
        !            18:  *    must display the following acknowledgement:
        !            19:  *      This product includes software developed by Gordon W. Ross
        !            20:  *
        !            21:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
        !            22:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
        !            23:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
        !            24:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
        !            25:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
        !            26:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
        !            27:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
        !            28:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        !            29:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
        !            30:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        !            31:  */
        !            32:
        !            33: /*
        !            34:  * Raw file system - for stream devices like tapes.
        !            35:  * No random access, only sequential read allowed.
        !            36:  * This exists only to allow upper level code to be
        !            37:  * shielded from the fact that the device must be
        !            38:  * read only with whole block position and size.
        !            39:  */
        !            40:
        !            41: #include <sys/param.h>
        !            42: #include <stand.h>
        !            43: #include <rawfs.h>
        !            44:
        !            45: #define        RAWFS_BSIZE     512
        !            46:
        !            47: /*
        !            48:  * In-core open file.
        !            49:  */
        !            50: struct cfile {
        !            51:        daddr_t         fs_nextblk;     /* block number to read next */
        !            52:        int             fs_len;         /* amount left in f_buf */
        !            53:        char *          fs_ptr;         /* read pointer into f_buf */
        !            54:        char            fs_buf[RAWFS_BSIZE];
        !            55: };
        !            56:
        !            57: static int
        !            58: rawfs_get_block(struct open_file *);
        !            59:
        !            60: int    rawfs_open(path, f)
        !            61:        char *path;
        !            62:        struct open_file *f;
        !            63: {
        !            64:        struct cfile *fs;
        !            65:
        !            66:        /*
        !            67:         * The actual PROM driver has already been opened.
        !            68:         * Just allocate the I/O buffer, etc.
        !            69:         */
        !            70:        fs = alloc(sizeof(struct cfile));
        !            71:        fs->fs_nextblk = 0;
        !            72:        fs->fs_len = 0;
        !            73:        fs->fs_ptr = fs->fs_buf;
        !            74:
        !            75:        f->f_fsdata = fs;
        !            76:        return (0);
        !            77: }
        !            78:
        !            79: int    rawfs_close(f)
        !            80:        struct open_file *f;
        !            81: {
        !            82:        struct cfile *fs;
        !            83:
        !            84:        fs = (struct cfile *) f->f_fsdata;
        !            85:        f->f_fsdata = (void *)0;
        !            86:
        !            87:        if (fs != (struct cfile *)0)
        !            88:                free(fs, sizeof(*fs));
        !            89:
        !            90:        return (0);
        !            91: }
        !            92:
        !            93: int    rawfs_read(f, start, size, resid)
        !            94:        struct open_file *f;
        !            95:        void *start;
        !            96:        u_int size;
        !            97:        u_int *resid;
        !            98: {
        !            99:        struct cfile *fs = (struct cfile *)f->f_fsdata;
        !           100:        char *addr = start;
        !           101:        int error = 0;
        !           102:        size_t csize;
        !           103:
        !           104:        while (size != 0) {
        !           105:
        !           106:                if (fs->fs_len == 0)
        !           107:                        if ((error = rawfs_get_block(f)) != 0)
        !           108:                                break;
        !           109:
        !           110:                if (fs->fs_len <= 0)
        !           111:                        break;  /* EOF */
        !           112:
        !           113:                csize = size;
        !           114:                if (csize > fs->fs_len)
        !           115:                        csize = fs->fs_len;
        !           116:
        !           117:                bcopy(fs->fs_ptr, addr, csize);
        !           118:                fs->fs_ptr += csize;
        !           119:                fs->fs_len -= csize;
        !           120:                addr += csize;
        !           121:                size -= csize;
        !           122:        }
        !           123:        if (resid)
        !           124:                *resid = size;
        !           125:        return (error);
        !           126: }
        !           127:
        !           128: int    rawfs_write(f, start, size, resid)
        !           129:        struct open_file *f;
        !           130:        void *start;
        !           131:        size_t size;
        !           132:        size_t *resid;  /* out */
        !           133: {
        !           134:        return (EROFS);
        !           135: }
        !           136:
        !           137: off_t  rawfs_seek(f, offset, where)
        !           138:        struct open_file *f;
        !           139:        off_t offset;
        !           140:        int where;
        !           141: {
        !           142:        return (EFTYPE);
        !           143: }
        !           144:
        !           145: int    rawfs_stat(f, sb)
        !           146:        struct open_file *f;
        !           147:        struct stat *sb;
        !           148: {
        !           149:        return (EFTYPE);
        !           150: }
        !           151:
        !           152:
        !           153: /*
        !           154:  * Read a block from the underlying stream device
        !           155:  * (In our case, a tape drive.)
        !           156:  */
        !           157: static int
        !           158: rawfs_get_block(f)
        !           159:        struct open_file *f;
        !           160: {
        !           161:        struct cfile *fs;
        !           162:        int error, len;
        !           163:
        !           164:        fs = (struct cfile *)f->f_fsdata;
        !           165:        fs->fs_ptr = fs->fs_buf;
        !           166:
        !           167:        twiddle();
        !           168:        error = f->f_dev->dv_strategy(f->f_devdata, F_READ,
        !           169:                fs->fs_nextblk, RAWFS_BSIZE,    fs->fs_buf, &len);
        !           170:
        !           171:        if (!error) {
        !           172:                fs->fs_len = len;
        !           173:                fs->fs_nextblk += (RAWFS_BSIZE / DEV_BSIZE);
        !           174:        }
        !           175:
        !           176:        return (error);
        !           177: }
        !           178:

CVSweb