Annotation of sys/arch/hp300/stand/libsa/rawfs.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: rawfs.c,v 1.4 2006/08/17 06:31:10 miod Exp $ */
! 2: /* $NetBSD: rawfs.c,v 1.2 1996/10/06 19:07:53 thorpej 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:
! 44: #include <lib/libsa/stand.h>
! 45: #include "rawfs.h"
! 46:
! 47: extern int debug;
! 48:
! 49: /* Our devices are generally willing to do 8K transfers. */
! 50: #define RAWFS_BSIZE 0x2000
! 51:
! 52: /*
! 53: * In-core open file.
! 54: */
! 55: struct rawfs_file {
! 56: daddr_t fs_nextblk; /* block number to read next */
! 57: int fs_len; /* amount left in f_buf */
! 58: char * fs_ptr; /* read pointer into f_buf */
! 59: char fs_buf[RAWFS_BSIZE];
! 60: };
! 61:
! 62: static int
! 63: rawfs_get_block(struct open_file *);
! 64:
! 65: int
! 66: rawfs_open(char *path, struct open_file *f)
! 67: {
! 68: struct rawfs_file *fs;
! 69:
! 70: /*
! 71: * The actual tape driver has already been opened.
! 72: * Just allocate the I/O buffer, etc.
! 73: */
! 74: fs = alloc(sizeof(struct rawfs_file));
! 75: fs->fs_nextblk = 0;
! 76: fs->fs_len = 0;
! 77: fs->fs_ptr = fs->fs_buf;
! 78:
! 79: #ifdef DEBUG_RAWFS
! 80: printf("rawfs_open: fs=0x%x\n", (u_long)fs);
! 81: #endif
! 82:
! 83: f->f_fsdata = fs;
! 84: return (0);
! 85: }
! 86:
! 87: int
! 88: rawfs_close(struct open_file *f)
! 89: {
! 90: struct rawfs_file *fs;
! 91:
! 92: fs = (struct rawfs_file *) f->f_fsdata;
! 93: f->f_fsdata = (void *)0;
! 94:
! 95: #ifdef DEBUG_RAWFS
! 96: printf("rawfs_close: fs=0x%x\n", (u_long)fs);
! 97: #endif
! 98:
! 99: if (fs != (struct rawfs_file *)0)
! 100: free(fs, sizeof(*fs));
! 101:
! 102: return (0);
! 103: }
! 104:
! 105: int
! 106: rawfs_read(struct open_file *f, void *start, size_t size, size_t *resid)
! 107: {
! 108: struct rawfs_file *fs = (struct rawfs_file *)f->f_fsdata;
! 109: char *addr = start;
! 110: int error = 0;
! 111: size_t csize;
! 112:
! 113: #ifdef DEBUG_RAWFS
! 114: printf("rawfs_read: file=0x%x, start=0x%x, size=%d, resid=0x%x\n",
! 115: (u_long)f, (u_long)start, size, resid);
! 116: printf(" fs=0x%x\n", (u_long)fs);
! 117: #endif
! 118:
! 119: while (size != 0) {
! 120:
! 121: if (fs->fs_len == 0)
! 122: if ((error = rawfs_get_block(f)) != 0)
! 123: break;
! 124:
! 125: if (fs->fs_len <= 0)
! 126: break; /* EOF */
! 127:
! 128: csize = size;
! 129: if (csize > fs->fs_len)
! 130: csize = fs->fs_len;
! 131:
! 132: bcopy(fs->fs_ptr, addr, csize);
! 133: fs->fs_ptr += csize;
! 134: fs->fs_len -= csize;
! 135: addr += csize;
! 136: size -= csize;
! 137: }
! 138: if (resid)
! 139: *resid = size;
! 140: return (error);
! 141: }
! 142:
! 143: int
! 144: rawfs_write(struct open_file *f, void *start, size_t size, size_t *resid)
! 145: {
! 146: #ifdef DEBUG_RAWFS
! 147: printf("rawfs_write: YOU'RE NOT SUPPOSED TO GET HERE!\n");
! 148: #endif
! 149: return (EROFS);
! 150: }
! 151:
! 152: off_t
! 153: rawfs_seek(struct open_file *f, off_t offset, int where)
! 154: {
! 155: #ifdef DEBUG_RAWFS
! 156: printf("rawfs_seek: YOU'RE NOT SUPPOSED TO GET HERE!\n");
! 157: #endif
! 158: return (EFTYPE);
! 159: }
! 160:
! 161: int
! 162: rawfs_stat(struct open_file *f, struct stat *sb)
! 163: {
! 164: #ifdef DEBUG_RAWFS
! 165: printf("rawfs_stat: I'll let you live only because of exec.c\n");
! 166: #endif
! 167: /*
! 168: * Clear out the stat buffer so that the uid check
! 169: * won't fail. See sys/lib/libsa/exec.c
! 170: */
! 171: bzero(sb, sizeof(*sb));
! 172:
! 173: return (EFTYPE);
! 174: }
! 175:
! 176: /*
! 177: * Read a block from the underlying stream device
! 178: * (In our case, a tape drive.)
! 179: */
! 180: static int
! 181: rawfs_get_block(struct open_file *f)
! 182: {
! 183: struct rawfs_file *fs;
! 184: size_t len;
! 185: int error;
! 186:
! 187: fs = (struct rawfs_file *)f->f_fsdata;
! 188: fs->fs_ptr = fs->fs_buf;
! 189:
! 190: twiddle();
! 191: #ifdef DEBUG_RAWFS
! 192: printf("rawfs_get_block: calling strategy\n");
! 193: #endif
! 194: error = f->f_dev->dv_strategy(f->f_devdata, F_READ,
! 195: fs->fs_nextblk, RAWFS_BSIZE, fs->fs_buf, &len);
! 196: #ifdef DEBUG_RAWFS
! 197: printf("rawfs_get_block: strategy returned %d\n", error);
! 198: #endif
! 199:
! 200: if (!error) {
! 201: fs->fs_len = len;
! 202: fs->fs_nextblk += (RAWFS_BSIZE / DEV_BSIZE);
! 203: }
! 204:
! 205: return (error);
! 206: }
CVSweb