devopen.c revision 1.4 1 /* $NetBSD: devopen.c,v 1.4 1999/04/14 11:53:44 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 dev2bios __P((char *, unsigned int, int *));
84
85 static int
86 dev2bios(devname, unit, biosdev)
87 char *devname;
88 unsigned int unit;
89 int *biosdev;
90 {
91 int i;
92
93 for (i = 0; i < NUMBIOSDEVS; i++)
94 if (!strcmp(devname, biosdevtab[i].name)) {
95 *biosdev = biosdevtab[i].biosdev + unit;
96 if (unit >= 4) /* ??? */
97 return (EUNIT);
98 return (0);
99 }
100 return (ENXIO);
101 }
102
103 struct btinfo_bootpath bibp;
104
105 int
106 devopen(f, fname, file)
107 struct open_file *f;
108 const char *fname;
109 char **file;
110 {
111 char *devname;
112 char *fsmode;
113 unsigned int unit, partition;
114 int biosdev;
115 int error;
116 struct devsw *dp;
117
118 if ((error = parsebootfile(fname, &fsmode, &devname, &unit,
119 &partition, (const char **) file)))
120 return (error);
121
122 if (!strcmp(fsmode, "dos")) {
123 file_system[0] = dosfs; /* structure assignment! */
124 f->f_flags |= F_NODEV; /* handled by DOS */
125 return (0);
126 } else if (!strcmp(fsmode, "ufs")) {
127 if ((error = dev2bios(devname, unit, &biosdev)))
128 return (error);
129 file_system[0] = ufsfs; /* structure assignment! */
130 dp = &devsw[0]; /* must be biosdisk */
131 f->f_dev = dp;
132
133 strncpy(bibp.bootpath, *file, sizeof(bibp.bootpath));
134 BI_ADD(&bibp, BTINFO_BOOTPATH, sizeof(bibp));
135
136 return (biosdiskopen(f, biosdev, partition));
137 } else {
138 printf("no file system\n");
139 return (ENXIO);
140 }
141 /* NOTREACHED */
142 }
143