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