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