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