devopen.c revision 1.1.1.1.2.1 1 1.1.1.1.2.1 bouyer /* $NetBSD: devopen.c,v 1.1.1.1.2.1 2000/11/20 20:47:08 bouyer Exp $ */
2 1.1.1.1.2.1 bouyer
3 1.1.1.1.2.1 bouyer /*-
4 1.1.1.1.2.1 bouyer * Copyright (c) 1999 Shin Takemura.
5 1.1.1.1.2.1 bouyer * All rights reserved.
6 1.1.1.1.2.1 bouyer *
7 1.1.1.1.2.1 bouyer * This software is part of the PocketBSD.
8 1.1.1.1.2.1 bouyer *
9 1.1.1.1.2.1 bouyer * Redistribution and use in source and binary forms, with or without
10 1.1.1.1.2.1 bouyer * modification, are permitted provided that the following conditions
11 1.1.1.1.2.1 bouyer * are met:
12 1.1.1.1.2.1 bouyer * 1. Redistributions of source code must retain the above copyright
13 1.1.1.1.2.1 bouyer * notice, this list of conditions and the following disclaimer.
14 1.1.1.1.2.1 bouyer * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.1.1.2.1 bouyer * notice, this list of conditions and the following disclaimer in the
16 1.1.1.1.2.1 bouyer * documentation and/or other materials provided with the distribution.
17 1.1.1.1.2.1 bouyer * 3. All advertising materials mentioning features or use of this software
18 1.1.1.1.2.1 bouyer * must display the following acknowledgement:
19 1.1.1.1.2.1 bouyer * This product includes software developed by the PocketBSD project
20 1.1.1.1.2.1 bouyer * and its contributors.
21 1.1.1.1.2.1 bouyer * 4. Neither the name of the project nor the names of its contributors
22 1.1.1.1.2.1 bouyer * may be used to endorse or promote products derived from this software
23 1.1.1.1.2.1 bouyer * without specific prior written permission.
24 1.1.1.1.2.1 bouyer *
25 1.1.1.1.2.1 bouyer * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 1.1.1.1.2.1 bouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 1.1.1.1.2.1 bouyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 1.1.1.1.2.1 bouyer * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 1.1.1.1.2.1 bouyer * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 1.1.1.1.2.1 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 1.1.1.1.2.1 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 1.1.1.1.2.1 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 1.1.1.1.2.1 bouyer * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 1.1.1.1.2.1 bouyer * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 1.1.1.1.2.1 bouyer * SUCH DAMAGE.
36 1.1.1.1.2.1 bouyer *
37 1.1.1.1.2.1 bouyer */
38 1.1.1.1.2.1 bouyer #define STANDALONE_WINDOWS_SIDE
39 1.1.1.1.2.1 bouyer #include <stand.h>
40 1.1.1.1.2.1 bouyer #include <winblk.h>
41 1.1.1.1.2.1 bouyer #include <winfs.h>
42 1.1.1.1.2.1 bouyer #include <lib/libsa/ufs.h>
43 1.1.1.1.2.1 bouyer
44 1.1.1.1.2.1 bouyer extern int parsebootfile __P((const char *, char**, char**, unsigned int*,
45 1.1.1.1.2.1 bouyer unsigned int*, const char**));
46 1.1.1.1.2.1 bouyer
47 1.1.1.1.2.1 bouyer struct devsw devsw[] = {
48 1.1.1.1.2.1 bouyer {"winblk", winblkstrategy, winblkopen, winblkclose, winblkioctl },
49 1.1.1.1.2.1 bouyer };
50 1.1.1.1.2.1 bouyer int ndevs = sizeof(devsw) / sizeof(struct devsw);
51 1.1.1.1.2.1 bouyer
52 1.1.1.1.2.1 bouyer static struct fs_ops winop = {
53 1.1.1.1.2.1 bouyer win_open, win_close, win_read, win_write, win_seek, win_stat
54 1.1.1.1.2.1 bouyer };
55 1.1.1.1.2.1 bouyer
56 1.1.1.1.2.1 bouyer static struct fs_ops ufsop = {
57 1.1.1.1.2.1 bouyer ufs_open, ufs_close, ufs_read, ufs_write, ufs_seek, ufs_stat
58 1.1.1.1.2.1 bouyer };
59 1.1.1.1.2.1 bouyer
60 1.1.1.1.2.1 bouyer struct fs_ops file_system[] = {
61 1.1.1.1.2.1 bouyer { 0 },
62 1.1.1.1.2.1 bouyer };
63 1.1.1.1.2.1 bouyer int nfsys = 1;
64 1.1.1.1.2.1 bouyer
65 1.1.1.1.2.1 bouyer int
66 1.1.1.1.2.1 bouyer parsebootfile(fnamexx, fsmode, devname, unit, partition, file)
67 1.1.1.1.2.1 bouyer const char *fnamexx;
68 1.1.1.1.2.1 bouyer char **fsmode; /* out */
69 1.1.1.1.2.1 bouyer char **devname; /* out */
70 1.1.1.1.2.1 bouyer unsigned int *unit, *partition; /* out */
71 1.1.1.1.2.1 bouyer const char **file; /* out */
72 1.1.1.1.2.1 bouyer {
73 1.1.1.1.2.1 bouyer TCHAR *fname = (TCHAR*)fnamexx;
74 1.1.1.1.2.1 bouyer
75 1.1.1.1.2.1 bouyer if (fname[0] == TEXT('\\')) {
76 1.1.1.1.2.1 bouyer *fsmode = "win";
77 1.1.1.1.2.1 bouyer *devname = "";
78 1.1.1.1.2.1 bouyer *unit = 0;
79 1.1.1.1.2.1 bouyer *partition = 0;
80 1.1.1.1.2.1 bouyer *file = fname;
81 1.1.1.1.2.1 bouyer } else {
82 1.1.1.1.2.1 bouyer static char name[1024]; /* XXX */
83 1.1.1.1.2.1 bouyer
84 1.1.1.1.2.1 bouyer if (wcstombs(name, (TCHAR*)fname, sizeof(name)) < 0) {
85 1.1.1.1.2.1 bouyer return (ENOENT);
86 1.1.1.1.2.1 bouyer }
87 1.1.1.1.2.1 bouyer if ('1' <= name[0] && name[0] <= '9' && name[1] == ':') {
88 1.1.1.1.2.1 bouyer *unit = name[0] - '0';
89 1.1.1.1.2.1 bouyer *file = &name[2];
90 1.1.1.1.2.1 bouyer } else {
91 1.1.1.1.2.1 bouyer *unit = 1;
92 1.1.1.1.2.1 bouyer *file = name;
93 1.1.1.1.2.1 bouyer }
94 1.1.1.1.2.1 bouyer *fsmode = "ufs";
95 1.1.1.1.2.1 bouyer *devname = "DSK";
96 1.1.1.1.2.1 bouyer *partition = 0;
97 1.1.1.1.2.1 bouyer }
98 1.1.1.1.2.1 bouyer
99 1.1.1.1.2.1 bouyer return (0);
100 1.1.1.1.2.1 bouyer }
101 1.1.1.1.2.1 bouyer
102 1.1.1.1.2.1 bouyer
103 1.1.1.1.2.1 bouyer int
104 1.1.1.1.2.1 bouyer devopen(f, fname, file)
105 1.1.1.1.2.1 bouyer struct open_file *f;
106 1.1.1.1.2.1 bouyer const char *fname;
107 1.1.1.1.2.1 bouyer char **file;
108 1.1.1.1.2.1 bouyer {
109 1.1.1.1.2.1 bouyer char *devname;
110 1.1.1.1.2.1 bouyer char *fsmode;
111 1.1.1.1.2.1 bouyer unsigned int unit, partition;
112 1.1.1.1.2.1 bouyer int error;
113 1.1.1.1.2.1 bouyer
114 1.1.1.1.2.1 bouyer if ((error = parsebootfile(fname, &fsmode, &devname, &unit,
115 1.1.1.1.2.1 bouyer &partition, (const char **) file)))
116 1.1.1.1.2.1 bouyer return (error);
117 1.1.1.1.2.1 bouyer
118 1.1.1.1.2.1 bouyer if (!strcmp(fsmode, "win")) {
119 1.1.1.1.2.1 bouyer file_system[0] = winop;
120 1.1.1.1.2.1 bouyer f->f_flags |= F_NODEV; /* handled by Windows */
121 1.1.1.1.2.1 bouyer return (0);
122 1.1.1.1.2.1 bouyer } else
123 1.1.1.1.2.1 bouyer if (!strcmp(fsmode, "ufs")) {
124 1.1.1.1.2.1 bouyer file_system[0] = ufsop;
125 1.1.1.1.2.1 bouyer f->f_dev = &devsw[0]; /* Windows block device. */
126 1.1.1.1.2.1 bouyer return (*f->f_dev->dv_open)(f, devname, unit, partition);
127 1.1.1.1.2.1 bouyer } else {
128 1.1.1.1.2.1 bouyer printf("no file system\n");
129 1.1.1.1.2.1 bouyer return (ENXIO);
130 1.1.1.1.2.1 bouyer }
131 1.1.1.1.2.1 bouyer /* NOTREACHED */
132 1.1.1.1.2.1 bouyer }
133