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