1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
/* $NetBSD: devopen.c,v 1.7 2016/06/26 04:17:17 isaki Exp $ */
/*
* Copyright (c) 2001 Minoura Makoto
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/param.h>
#include <sys/disklabel.h>
#include <machine/bootinfo.h>
#include <lib/libkern/libkern.h>
#include <lib/libsa/stand.h>
#include "libx68k.h"
extern struct devspec devspec[]; /* defined in conf.c */
int devopen_open_dir = 0;
/*
* Parse a device spec.
*
* [ha@]<dev><unit><part>:<file>
* ha - host adaptor ("spc0", "spc1", "mha0")
* dev - device name (e.g., "sd")
* unit - 0-7
* part - a-p
*/
int
devparse(const char *fname, int *ha, int *dev, int *unit, int *part,
char **file)
{
char const *s;
int i;
s = fname;
if (strncmp(s, "spc0@", 5) == 0) {
*ha = (X68K_BOOT_SCSIIF_SPC << 4) | 0;
s += 5;
} else if (strncmp(s, "spc1@", 5) == 0) {
*ha = (X68K_BOOT_SCSIIF_SPC << 4) | 1;
s += 5;
} else if (strncmp(s, "mha0@", 5) == 0) {
*ha = (X68K_BOOT_SCSIIF_MHA << 4) | 0;
s += 5;
} else {
*ha = 0;
}
for (i = 0; devspec[i].ds_name != 0; i++) {
if (strncmp (devspec[i].ds_name, s,
strlen(devspec[i].ds_name)) == 0)
break;
}
if (devspec[i].ds_name == 0)
return ENODEV;
s += strlen(devspec[i].ds_name);
*dev = devspec[i].ds_dev;
if (devspec[i].ds_net) {
*unit = 0;
*part = 0;
} else {
*unit = *s++ - '0';
if (*unit < 0 || *unit > devspec[i].ds_maxunit)
/* bad unit */
return ENODEV;
*part = *s++ - 'a';
if (*part < 0 || *part > MAXPARTITIONS)
/* bad partition */
return ENODEV;
}
if (*s++ != ':')
return ENODEV;
if (*s == '/') {
s++;
if (devopen_open_dir && *s == 0)
s--;
}
*file = __UNCONST(s);
return 0;
}
int
devopen(struct open_file *f, const char *fname, char **file)
{
int error;
int ha, dev, unit, part;
struct devsw *dp = &devsw[0];
error = devparse(fname, &ha, &dev, &unit, &part, file);
if (error)
return error;
dp = &devsw[dev];
if (dp->dv_open == NULL)
return ENODEV;
f->f_dev = dp;
if ((error = (*dp->dv_open)(f, unit, part)) == 0)
return 0;
return error;
}
|