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