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