Home | History | Annotate | Line # | Download | only in bootst
dev_tape.c revision 1.1
      1 /*	$NetBSD: dev_tape.c,v 1.1 1996/05/28 15:23:55 chuck Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1993 Paul Kranenburg
      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. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *      This product includes software developed by Paul Kranenburg.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission
     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  * This module implements a "raw device" interface suitable for
     35  * use by the stand-alone I/O library UFS file-system code, and
     36  * possibly for direct access (i.e. boot from tape).
     37  */
     38 
     39 #include <sys/types.h>
     40 #include <machine/prom.h>
     41 
     42 #include "stand.h"
     43 #include "libsa.h"
     44 
     45 
     46 extern int debug;
     47 
     48 struct mvmeprom_dskio tape_ioreq;
     49 
     50 /*
     51  * This is a special version of devopen() for tape boot.
     52  * In this version, the file name is a numeric string of
     53  * one digit, which is passed to the device open so it
     54  * can open the appropriate tape segment.
     55  */
     56 int
     57 devopen(f, fname, file)
     58 	struct open_file *f;
     59 	const char *fname;		/* normally "1" */
     60 	char **file;
     61 {
     62 	struct devsw *dp;
     63 	int error;
     64 
     65 	*file = (char*)fname;
     66 	dp = &devsw[0];
     67 	f->f_dev = dp;
     68 
     69 	/* The following will call tape_open() */
     70 	return (dp->dv_open(f, fname));
     71 }
     72 
     73 int
     74 tape_open(f, fname)
     75 	struct open_file *f;
     76 	char *fname;		/* partition number, i.e. "1" */
     77 {
     78 	int	error, part;
     79 	struct mvmeprom_dskio *ti;
     80 
     81 	/*
     82 	 * Set the tape segment number to the one indicated
     83 	 * by the single digit fname passed in above.
     84 	 */
     85 	if ((fname[0] < '0') && (fname[0] > '9')) {
     86 		return ENOENT;
     87 	}
     88 	part = fname[0] - '0';
     89 
     90 	/*
     91 	 * Setup our part of the saioreq.
     92 	 * (determines what gets opened)
     93 	 */
     94 	ti = &tape_ioreq;
     95 	bzero((caddr_t)ti, sizeof(*ti));
     96 
     97 	ti->ctrl_lun = bugargs.ctrl_lun;
     98 	ti->dev_lun = bugargs.dev_lun;
     99 	ti->status = 0;
    100 	ti->pbuffer = NULL;
    101 	ti->blk_num = part;
    102 	ti->blk_cnt = 0;
    103 	ti->flag = 0;
    104 	ti->addr_mod = 0;
    105 
    106 	f->f_devdata = ti;
    107 
    108 	return (error);
    109 }
    110 
    111 int
    112 tape_close(f)
    113 	struct open_file *f;
    114 {
    115 	struct mvmeprom_dskio *ti;
    116 
    117 
    118 	ti = f->f_devdata;
    119 	f->f_devdata = NULL;
    120 	return 0;
    121 }
    122 
    123 #define MVMEPROM_SCALE (512/MVMEPROM_BLOCK_SIZE)
    124 
    125 int
    126 tape_strategy(devdata, flag, dblk, size, buf, rsize)
    127 	void	*devdata;
    128 	int	flag;
    129 	daddr_t	dblk;
    130 	u_int	size;
    131 	char	*buf;
    132 	u_int	*rsize;
    133 {
    134 	struct mvmeprom_dskio *ti;
    135 	int ret;
    136 
    137 	ti = devdata;
    138 
    139 	if (flag != F_READ)
    140 		return(EROFS);
    141 
    142 	ti->status = 0;
    143 	ti->pbuffer = buf;
    144 	/* don't change block #, set in open */
    145 	ti->blk_cnt = size / (512 / MVMEPROM_SCALE);
    146 
    147 	ret = mvmeprom_diskrd(ti);
    148 
    149 	if (ret != 0)
    150 		return (EIO);
    151 
    152 	*rsize = (ti->blk_cnt / MVMEPROM_SCALE) * 512;
    153 	ti->flag |= IGNORE_FILENUM; /* ignore next time */
    154 
    155 	return (0);
    156 }
    157 
    158 int
    159 tape_ioctl()
    160 {
    161 	return EIO;
    162 }
    163 
    164