devopen.c revision 1.3 1 /* $NetBSD: devopen.c,v 1.3 2005/06/15 19:01:19 junyoung Exp $ */
2
3 /*
4 * Copyright (c) 1996, 1997
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 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28
29 #include <sys/types.h>
30
31 #include <lib/libsa/stand.h>
32 #include <lib/libkern/libkern.h>
33
34 #include <libi386.h>
35 #include <biosdisk.h>
36 #include "devopen.h"
37 #ifdef _STANDALONE
38 #include <bootinfo.h>
39 #endif
40 #ifdef SUPPORT_PS2
41 #include <biosmca.h>
42 #endif
43
44 static int dev2bios(char *, u_int, int *);
45
46 static int
47 dev2bios(char *devname, u_int unit, int *biosdev)
48 {
49 if (strcmp(devname, "hd") == 0)
50 *biosdev = 0x80 + unit;
51 else if (strcmp(devname, "fd") == 0)
52 *biosdev = 0x00 + unit;
53 else
54 return ENXIO;
55
56 return 0;
57 }
58
59 int
60 bios2dev(int biosdev, char **devname, u_int *unit, u_int sector, u_int *ptnp)
61 {
62 if (biosdev & 0x80)
63 *devname = "hd";
64 else
65 *devname = "fd";
66
67 *unit = biosdev & 0x7f;
68 *ptnp = biosdiskfindptn(biosdev, sector);
69
70 return 0;
71 }
72
73 #ifdef _STANDALONE
74 struct btinfo_bootpath bibp;
75 #endif
76
77 /*
78 * Open the BIOS disk device
79 */
80 int
81 devopen(struct open_file *f, const char *fname, char **file)
82 {
83 char *fsname, *devname;
84 u_int unit, partition;
85 int biosdev;
86 int error;
87
88 if ((error = parsebootfile(fname, &fsname, &devname,
89 &unit, &partition, (const char **) file))
90 || (error = dev2bios(devname, unit, &biosdev)))
91 return error;
92
93 f->f_dev = &devsw[0]; /* must be biosdisk */
94
95 #ifdef _STANDALONE
96 strncpy(bibp.bootpath, *file, sizeof(bibp.bootpath));
97 BI_ADD(&bibp, BTINFO_BOOTPATH, sizeof(bibp));
98 #endif
99
100 return biosdiskopen(f, biosdev, partition);
101 }
102