1*454af1c0Sdsl /* $NetBSD: devopen.c,v 1.11 2009/03/14 15:36:07 dsl Exp $ */
2816bb961Sperry
3816bb961Sperry /*
4816bb961Sperry * Copyright (c) 1996
5816bb961Sperry * Matthias Drochner. All rights reserved.
6816bb961Sperry *
7816bb961Sperry * Redistribution and use in source and binary forms, with or without
8816bb961Sperry * modification, are permitted provided that the following conditions
9816bb961Sperry * are met:
10816bb961Sperry * 1. Redistributions of source code must retain the above copyright
11816bb961Sperry * notice, this list of conditions and the following disclaimer.
12816bb961Sperry * 2. Redistributions in binary form must reproduce the above copyright
13816bb961Sperry * notice, this list of conditions and the following disclaimer in the
14816bb961Sperry * documentation and/or other materials provided with the distribution.
15816bb961Sperry *
16816bb961Sperry * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17816bb961Sperry * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18816bb961Sperry * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19816bb961Sperry * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20816bb961Sperry * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21816bb961Sperry * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22816bb961Sperry * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23816bb961Sperry * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24816bb961Sperry * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25816bb961Sperry * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26816bb961Sperry */
27816bb961Sperry
28816bb961Sperry
29816bb961Sperry #include <lib/libsa/stand.h>
3023d58b46Sdrochner #include <lib/libkern/libkern.h>
31816bb961Sperry #include <lib/libsa/ufs.h>
32816bb961Sperry
33816bb961Sperry #include <libi386.h>
34816bb961Sperry #include <biosdisk.h>
35816bb961Sperry #include <dosfile.h>
3623d58b46Sdrochner #include <bootinfo.h>
3723d58b46Sdrochner
38816bb961Sperry struct devsw devsw[] = {
39f54b3f43Sjunyoung {"disk", biosdisk_strategy, biosdisk_open, biosdisk_close, biosdisk_ioctl},
40816bb961Sperry };
41816bb961Sperry int ndevs = sizeof(devsw) / sizeof(struct devsw);
42816bb961Sperry
43816bb961Sperry static struct fs_ops dosfs = {
44816bb961Sperry dos_open, dos_close, dos_read, dos_write, dos_seek, dos_stat
45816bb961Sperry };
46816bb961Sperry static struct fs_ops ufsfs = {
47816bb961Sperry ufs_open, ufs_close, ufs_read, ufs_write, ufs_seek, ufs_stat
48816bb961Sperry };
49816bb961Sperry
50816bb961Sperry struct fs_ops file_system[] = {
51816bb961Sperry {0},
52816bb961Sperry };
53816bb961Sperry int nfsys = 1;
54816bb961Sperry
55816bb961Sperry static struct {
56816bb961Sperry char *name;
57816bb961Sperry int biosdev;
58816bb961Sperry } biosdevtab[] = {
59e321bba7Sthorpej {
60e321bba7Sthorpej "fd", 0
61e321bba7Sthorpej },
62e321bba7Sthorpej {
63e321bba7Sthorpej "wd", 0x80
64e321bba7Sthorpej },
65e321bba7Sthorpej {
66e321bba7Sthorpej "sd", 0x80
67e321bba7Sthorpej },
68e321bba7Sthorpej {
69e321bba7Sthorpej "hd", 0x80
70e321bba7Sthorpej }
71816bb961Sperry };
72816bb961Sperry #define NUMBIOSDEVS (sizeof(biosdevtab) / sizeof(biosdevtab[0]))
73816bb961Sperry
74c3455f12Sdyoung static int dev2bios(char *, unsigned int, int *);
75e4841b3eSdrochner
76816bb961Sperry static int
dev2bios(char * devname,unsigned int unit,int * biosdev)77*454af1c0Sdsl dev2bios(char *devname, unsigned int unit, int *biosdev)
78816bb961Sperry {
7960ae17c7Sfvdl unsigned i;
80816bb961Sperry
81816bb961Sperry for (i = 0; i < NUMBIOSDEVS; i++)
82816bb961Sperry if (!strcmp(devname, biosdevtab[i].name)) {
83816bb961Sperry *biosdev = biosdevtab[i].biosdev + unit;
84816bb961Sperry if (unit >= 4) /* ??? */
85816bb961Sperry return (EUNIT);
86816bb961Sperry return (0);
87816bb961Sperry }
88816bb961Sperry return (ENXIO);
89816bb961Sperry }
90816bb961Sperry
9123d58b46Sdrochner struct btinfo_bootpath bibp;
9223d58b46Sdrochner
93816bb961Sperry int
devopen(struct open_file * f,const char * fname,char ** file)94*454af1c0Sdsl devopen(struct open_file *f, const char *fname, char **file)
95816bb961Sperry {
96816bb961Sperry char *devname;
97816bb961Sperry char *fsmode;
98c3455f12Sdyoung int unit, partition;
99816bb961Sperry int biosdev;
100816bb961Sperry int error;
101816bb961Sperry struct devsw *dp;
102816bb961Sperry
103e321bba7Sthorpej if ((error = parsebootfile(fname, &fsmode, &devname, &unit,
104e321bba7Sthorpej &partition, (const char **) file)))
105816bb961Sperry return (error);
106816bb961Sperry
107816bb961Sperry if (!strcmp(fsmode, "dos")) {
108816bb961Sperry file_system[0] = dosfs; /* structure assignment! */
109816bb961Sperry f->f_flags |= F_NODEV; /* handled by DOS */
110816bb961Sperry return (0);
111816bb961Sperry } else if (!strcmp(fsmode, "ufs")) {
112816bb961Sperry if ((error = dev2bios(devname, unit, &biosdev)))
113816bb961Sperry return (error);
114816bb961Sperry file_system[0] = ufsfs; /* structure assignment! */
115816bb961Sperry dp = &devsw[0]; /* must be biosdisk */
116816bb961Sperry f->f_dev = dp;
11723d58b46Sdrochner
11823d58b46Sdrochner strncpy(bibp.bootpath, *file, sizeof(bibp.bootpath));
11923d58b46Sdrochner BI_ADD(&bibp, BTINFO_BOOTPATH, sizeof(bibp));
12023d58b46Sdrochner
121f54b3f43Sjunyoung return (biosdisk_open(f, biosdev, partition));
122816bb961Sperry } else {
123816bb961Sperry printf("no file system\n");
124816bb961Sperry return (ENXIO);
125816bb961Sperry }
126816bb961Sperry /* NOTREACHED */
127816bb961Sperry }
128