Home | History | Annotate | Line # | Download | only in dosboot
devopen.c revision 1.2
      1 /*	$NetBSD: devopen.c,v 1.2 1997/03/22 09:06:18 thorpej Exp $	 */
      2 
      3 /*
      4  * Copyright (c) 1996
      5  *	Matthias Drochner.  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 for the NetBSD Project
     18  *	by Matthias Drochner.
     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 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 #include <lib/libsa/stand.h>
     36 #include <lib/libsa/ufs.h>
     37 
     38 #include <libi386.h>
     39 #include <biosdisk.h>
     40 #include <dosfile.h>
     41 
     42 struct devsw devsw[] = {
     43 	{"disk", biosdiskstrategy, biosdiskopen, biosdiskclose, biosdiskioctl},
     44 };
     45 int ndevs = sizeof(devsw) / sizeof(struct devsw);
     46 
     47 static struct fs_ops dosfs = {
     48 	dos_open, dos_close, dos_read, dos_write, dos_seek, dos_stat
     49 };
     50 static struct fs_ops ufsfs = {
     51 	ufs_open, ufs_close, ufs_read, ufs_write, ufs_seek, ufs_stat
     52 };
     53 
     54 struct fs_ops   file_system[] = {
     55 	{0},
     56 };
     57 int  nfsys = 1;
     58 
     59 static struct {
     60 	char           *name;
     61 	int             biosdev;
     62 }               biosdevtab[] = {
     63 	{
     64 		"fd", 0
     65 	},
     66 	{
     67 		"wd", 0x80
     68 	},
     69 	{
     70 		"sd", 0x80
     71 	},
     72 	{
     73 		"hd", 0x80
     74 	}
     75 };
     76 #define NUMBIOSDEVS (sizeof(biosdevtab) / sizeof(biosdevtab[0]))
     77 
     78 static int
     79 dev2bios(devname, unit, biosdev)
     80 	char           *devname;
     81 	unsigned int    unit;
     82 	int            *biosdev;
     83 {
     84 	int             i;
     85 
     86 	for (i = 0; i < NUMBIOSDEVS; i++)
     87 		if (!strcmp(devname, biosdevtab[i].name)) {
     88 			*biosdev = biosdevtab[i].biosdev + unit;
     89 			if (unit >= 4)	/* ??? */
     90 				return (EUNIT);
     91 			return (0);
     92 		}
     93 	return (ENXIO);
     94 }
     95 
     96 int
     97 devopen(f, fname, file)
     98 	struct open_file *f;
     99 	const char     *fname;
    100 	char          **file;
    101 {
    102 	char           *devname;
    103 	char           *fsmode;
    104 	unsigned int    unit, partition;
    105 	int             biosdev;
    106 	int             error;
    107 	struct devsw   *dp;
    108 
    109 	if ((error = parsebootfile(fname, &fsmode, &devname, &unit,
    110 	    &partition, (const char **) file)))
    111 		return (error);
    112 
    113 	if (!strcmp(fsmode, "dos")) {
    114 		file_system[0] = dosfs;	/* structure assignment! */
    115 		f->f_flags |= F_NODEV;	/* handled by DOS */
    116 		return (0);
    117 	} else if (!strcmp(fsmode, "ufs")) {
    118 		if ((error = dev2bios(devname, unit, &biosdev)))
    119 			return (error);
    120 		file_system[0] = ufsfs;	/* structure assignment! */
    121 		dp = &devsw[0];	/* must be biosdisk */
    122 		f->f_dev = dp;
    123 		return (biosdiskopen(f, biosdev, partition));
    124 	} else {
    125 		printf("no file system\n");
    126 		return (ENXIO);
    127 	}
    128 	/* NOTREACHED */
    129 }
    130