ofdev.c revision 1.23 1 1.23 phx /* $NetBSD: ofdev.c,v 1.23 2010/10/17 15:33:04 phx Exp $ */
2 1.1 tsubai
3 1.1 tsubai /*
4 1.1 tsubai * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5 1.1 tsubai * Copyright (C) 1995, 1996 TooLs GmbH.
6 1.1 tsubai * All rights reserved.
7 1.1 tsubai *
8 1.1 tsubai * Redistribution and use in source and binary forms, with or without
9 1.1 tsubai * modification, are permitted provided that the following conditions
10 1.1 tsubai * are met:
11 1.1 tsubai * 1. Redistributions of source code must retain the above copyright
12 1.1 tsubai * notice, this list of conditions and the following disclaimer.
13 1.1 tsubai * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 tsubai * notice, this list of conditions and the following disclaimer in the
15 1.1 tsubai * documentation and/or other materials provided with the distribution.
16 1.1 tsubai * 3. All advertising materials mentioning features or use of this software
17 1.1 tsubai * must display the following acknowledgement:
18 1.1 tsubai * This product includes software developed by TooLs GmbH.
19 1.1 tsubai * 4. The name of TooLs GmbH may not be used to endorse or promote products
20 1.1 tsubai * derived from this software without specific prior written permission.
21 1.1 tsubai *
22 1.1 tsubai * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23 1.1 tsubai * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 tsubai * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 tsubai * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 1.1 tsubai * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 1.1 tsubai * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 1.1 tsubai * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 1.1 tsubai * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 1.1 tsubai * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 1.1 tsubai * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 tsubai */
33 1.1 tsubai /*
34 1.1 tsubai * Device I/O routines using Open Firmware
35 1.1 tsubai */
36 1.1 tsubai
37 1.14 aymeric #include "ofdev.h"
38 1.17 uwe #include "openfirm.h"
39 1.14 aymeric
40 1.1 tsubai #include <sys/param.h>
41 1.1 tsubai #include <sys/disklabel.h>
42 1.13 lukem #include <sys/bootblock.h>
43 1.1 tsubai
44 1.1 tsubai #include <netinet/in.h>
45 1.1 tsubai
46 1.18 uwe #include <lib/libkern/libkern.h>
47 1.18 uwe
48 1.1 tsubai #include <lib/libsa/stand.h>
49 1.18 uwe #include <lib/libsa/byteorder.h>
50 1.1 tsubai #include <lib/libsa/cd9660.h>
51 1.1 tsubai #include <lib/libsa/nfs.h>
52 1.7 tsubai #include <lib/libsa/ufs.h>
53 1.20 hauke #include <lib/libsa/lfs.h>
54 1.9 tsutsui #include <lib/libsa/ustarfs.h>
55 1.1 tsubai
56 1.7 tsubai #include "hfs.h"
57 1.17 uwe #include "net.h"
58 1.1 tsubai
59 1.22 tsutsui #ifdef DEBUG
60 1.22 tsutsui # define DPRINTF printf
61 1.22 tsutsui #else
62 1.22 tsutsui # define DPRINTF while (0) printf
63 1.22 tsutsui #endif
64 1.1 tsubai
65 1.1 tsubai static int
66 1.12 aymeric strategy(void *devdata, int rw, daddr_t blk, size_t size, void *buf,
67 1.12 aymeric size_t *rsize)
68 1.1 tsubai {
69 1.1 tsubai struct of_dev *dev = devdata;
70 1.1 tsubai u_quad_t pos;
71 1.1 tsubai int n;
72 1.8 tsutsui
73 1.1 tsubai if (rw != F_READ)
74 1.1 tsubai return EPERM;
75 1.1 tsubai if (dev->type != OFDEV_DISK)
76 1.1 tsubai panic("strategy");
77 1.8 tsutsui
78 1.1 tsubai pos = (u_quad_t)(blk + dev->partoff) * dev->bsize;
79 1.8 tsutsui
80 1.1 tsubai for (;;) {
81 1.1 tsubai if (OF_seek(dev->handle, pos) < 0)
82 1.1 tsubai break;
83 1.1 tsubai n = OF_read(dev->handle, buf, size);
84 1.1 tsubai if (n == -2)
85 1.1 tsubai continue;
86 1.1 tsubai if (n < 0)
87 1.1 tsubai break;
88 1.1 tsubai *rsize = n;
89 1.1 tsubai return 0;
90 1.1 tsubai }
91 1.1 tsubai return EIO;
92 1.1 tsubai }
93 1.1 tsubai
94 1.1 tsubai static int
95 1.14 aymeric devopen_dummy(struct open_file *of, ...) {
96 1.14 aymeric return -1;
97 1.14 aymeric }
98 1.14 aymeric
99 1.14 aymeric static int
100 1.14 aymeric devclose(struct open_file *of)
101 1.1 tsubai {
102 1.1 tsubai struct of_dev *op = of->f_devdata;
103 1.8 tsutsui
104 1.1 tsubai if (op->type == OFDEV_NET)
105 1.1 tsubai net_close(op);
106 1.3 tsubai OF_call_method("dma-free", op->handle, 2, 0, op->dmabuf, MAXPHYS);
107 1.1 tsubai OF_close(op->handle);
108 1.1 tsubai op->handle = -1;
109 1.17 uwe return 0;
110 1.1 tsubai }
111 1.1 tsubai
112 1.19 mrg static struct devsw of_devsw[1] = {
113 1.17 uwe { "OpenFirmware", strategy, devopen_dummy, devclose, noioctl }
114 1.1 tsubai };
115 1.19 mrg int ndevs = sizeof of_devsw / sizeof of_devsw[0];
116 1.1 tsubai
117 1.20 hauke static struct fs_ops file_system_ffsv1 = FS_OPS(ffsv1);
118 1.20 hauke static struct fs_ops file_system_ffsv2 = FS_OPS(ffsv2);
119 1.20 hauke static struct fs_ops file_system_lfsv1 = FS_OPS(lfsv1);
120 1.20 hauke static struct fs_ops file_system_lfsv2 = FS_OPS(lfsv2);
121 1.15 junyoung static struct fs_ops file_system_hfs = FS_OPS(hfs);
122 1.15 junyoung static struct fs_ops file_system_ustarfs = FS_OPS(ustarfs);
123 1.15 junyoung static struct fs_ops file_system_cd9660 = FS_OPS(cd9660);
124 1.15 junyoung static struct fs_ops file_system_nfs = FS_OPS(nfs);
125 1.1 tsubai
126 1.20 hauke struct fs_ops file_system[8];
127 1.1 tsubai int nfsys;
128 1.1 tsubai
129 1.1 tsubai static struct of_dev ofdev = {
130 1.1 tsubai -1,
131 1.1 tsubai };
132 1.1 tsubai
133 1.22 tsutsui char opened_name[MAXBOOTPATHLEN];
134 1.1 tsubai
135 1.23 phx /*
136 1.23 phx * Check if this APM partition is a suitable root partition and return
137 1.23 phx * its file system type or zero.
138 1.23 phx */
139 1.23 phx static u_int8_t
140 1.23 phx check_apm_root(struct part_map_entry *part, int *clust)
141 1.23 phx {
142 1.23 phx struct blockzeroblock *bzb;
143 1.23 phx char typestr[32], *s;
144 1.23 phx u_int8_t fstype;
145 1.23 phx
146 1.23 phx *clust = 0; /* may become 1 for A/UX partitions */
147 1.23 phx fstype = 0;
148 1.23 phx bzb = (struct blockzeroblock *)(&part->pmBootArgs);
149 1.23 phx
150 1.23 phx /* convert partition type name to upper case */
151 1.23 phx strncpy(typestr, (char *)part->pmPartType, sizeof(typestr));
152 1.23 phx typestr[sizeof(typestr) - 1] = '\0';
153 1.23 phx for (s = typestr; *s; s++)
154 1.23 phx if ((*s >= 'a') && (*s <= 'z'))
155 1.23 phx *s = (*s - 'a' + 'A');
156 1.23 phx
157 1.23 phx if (strcmp(PART_TYPE_NBSD_PPCBOOT, typestr) == 0) {
158 1.23 phx if ((bzb->bzbMagic == BZB_MAGIC) &&
159 1.23 phx (bzb->bzbType < FSMAXTYPES))
160 1.23 phx fstype = bzb->bzbType;
161 1.23 phx else
162 1.23 phx fstype = FS_BSDFFS;
163 1.23 phx } else if (strcmp(PART_TYPE_UNIX, typestr) == 0 &&
164 1.23 phx bzb->bzbMagic == BZB_MAGIC && (bzb->bzbFlags & BZB_ROOTFS)) {
165 1.23 phx *clust = bzb->bzbCluster;
166 1.23 phx fstype = FS_BSDFFS;
167 1.23 phx }
168 1.23 phx
169 1.23 phx return fstype;
170 1.23 phx }
171 1.23 phx
172 1.23 phx /*
173 1.23 phx * Build a disklabel from APM partitions.
174 1.23 phx * We will just look for a suitable root partition and insert it into
175 1.23 phx * the 'a' slot. Should be sufficient to boot a kernel from it.
176 1.23 phx */
177 1.23 phx static int
178 1.23 phx search_mac_label(struct of_dev *devp, char *buf, struct disklabel *lp)
179 1.23 phx {
180 1.23 phx struct part_map_entry *pme;
181 1.23 phx struct partition *a_part;
182 1.23 phx size_t nread;
183 1.23 phx int blkno, clust, lastblk, lastclust;
184 1.23 phx u_int8_t fstype;
185 1.23 phx
186 1.23 phx pme = (struct part_map_entry *)buf;
187 1.23 phx a_part = &lp->d_partitions[0]; /* disklabel 'a' partition */
188 1.23 phx lastclust = -1;
189 1.23 phx
190 1.23 phx for (blkno = lastblk = 1; blkno <= lastblk; blkno++) {
191 1.23 phx if (strategy(devp, F_READ, blkno, DEV_BSIZE, pme, &nread)
192 1.23 phx || nread != DEV_BSIZE)
193 1.23 phx return ERDLAB;
194 1.23 phx if (pme->pmSig != PART_ENTRY_MAGIC ||
195 1.23 phx pme->pmPartType[0] == '\0')
196 1.23 phx break;
197 1.23 phx lastblk = pme->pmMapBlkCnt;
198 1.23 phx
199 1.23 phx fstype = check_apm_root(pme, &clust);
200 1.23 phx
201 1.23 phx if (fstype && (lastclust == -1 || clust < lastclust)) {
202 1.23 phx a_part->p_size = pme->pmPartBlkCnt;
203 1.23 phx a_part->p_offset = pme->pmPyPartStart;
204 1.23 phx a_part->p_fstype = fstype;
205 1.23 phx if ((lastclust = clust) == 0)
206 1.23 phx break; /* we won't find a better match */
207 1.23 phx }
208 1.23 phx }
209 1.23 phx if (lastclust < 0)
210 1.23 phx return ERDLAB; /* no root partition found */
211 1.23 phx
212 1.23 phx /* pretend we only have partitions 'a', 'b' and 'c' */
213 1.23 phx lp->d_npartitions = RAW_PART + 1;
214 1.23 phx return 0;
215 1.23 phx }
216 1.23 phx
217 1.1 tsubai static u_long
218 1.14 aymeric get_long(const void *p)
219 1.1 tsubai {
220 1.1 tsubai const unsigned char *cp = p;
221 1.8 tsutsui
222 1.1 tsubai return cp[0] | (cp[1] << 8) | (cp[2] << 16) | (cp[3] << 24);
223 1.1 tsubai }
224 1.1 tsubai
225 1.1 tsubai /*
226 1.23 phx * Find a valid disklabel from MBR partitions.
227 1.1 tsubai */
228 1.1 tsubai static int
229 1.23 phx search_dos_label(struct of_dev *devp, u_long off, char *buf,
230 1.23 phx struct disklabel *lp, u_long off0)
231 1.1 tsubai {
232 1.17 uwe size_t nread;
233 1.1 tsubai struct mbr_partition *p;
234 1.1 tsubai int i;
235 1.1 tsubai u_long poff;
236 1.1 tsubai static int recursion;
237 1.8 tsutsui
238 1.17 uwe if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &nread)
239 1.17 uwe || nread != DEV_BSIZE)
240 1.1 tsubai return ERDLAB;
241 1.8 tsutsui
242 1.13 lukem if (*(u_int16_t *)&buf[MBR_MAGIC_OFFSET] != sa_htole16(MBR_MAGIC))
243 1.1 tsubai return ERDLAB;
244 1.1 tsubai
245 1.1 tsubai if (recursion++ <= 1)
246 1.1 tsubai off0 += off;
247 1.13 lukem for (p = (struct mbr_partition *)(buf + MBR_PART_OFFSET), i = 4;
248 1.1 tsubai --i >= 0; p++) {
249 1.13 lukem if (p->mbrp_type == MBR_PTYPE_NETBSD
250 1.1 tsubai #ifdef COMPAT_386BSD_MBRPART
251 1.13 lukem || (p->mbrp_type == MBR_PTYPE_386BSD &&
252 1.1 tsubai (printf("WARNING: old BSD partition ID!\n"), 1)
253 1.1 tsubai /* XXX XXX - libsa printf() is void */ )
254 1.1 tsubai #endif
255 1.1 tsubai ) {
256 1.2 tsubai poff = get_long(&p->mbrp_start) + off0;
257 1.10 itojun if (strategy(devp, F_READ, poff + 1,
258 1.17 uwe DEV_BSIZE, buf, &nread) == 0
259 1.17 uwe && nread == DEV_BSIZE) {
260 1.1 tsubai if (!getdisklabel(buf, lp)) {
261 1.1 tsubai recursion--;
262 1.1 tsubai return 0;
263 1.1 tsubai }
264 1.1 tsubai }
265 1.17 uwe if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &nread)
266 1.17 uwe || nread != DEV_BSIZE) {
267 1.1 tsubai recursion--;
268 1.1 tsubai return ERDLAB;
269 1.1 tsubai }
270 1.13 lukem } else if (p->mbrp_type == MBR_PTYPE_EXT) {
271 1.2 tsubai poff = get_long(&p->mbrp_start);
272 1.23 phx if (!search_dos_label(devp, poff, buf, lp, off0)) {
273 1.1 tsubai recursion--;
274 1.1 tsubai return 0;
275 1.1 tsubai }
276 1.17 uwe if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &nread)
277 1.17 uwe || nread != DEV_BSIZE) {
278 1.1 tsubai recursion--;
279 1.1 tsubai return ERDLAB;
280 1.1 tsubai }
281 1.1 tsubai }
282 1.1 tsubai }
283 1.1 tsubai recursion--;
284 1.1 tsubai return ERDLAB;
285 1.1 tsubai }
286 1.1 tsubai
287 1.22 tsutsui bool
288 1.22 tsutsui parsefilepath(const char *path, char *devname, char *fname, char *ppart)
289 1.22 tsutsui {
290 1.22 tsutsui char *cp, *lp;
291 1.22 tsutsui char savec;
292 1.22 tsutsui int dhandle;
293 1.22 tsutsui char str[MAXBOOTPATHLEN];
294 1.22 tsutsui char devtype[16];
295 1.22 tsutsui
296 1.22 tsutsui DPRINTF("%s: path = %s\n", __func__, path);
297 1.22 tsutsui
298 1.22 tsutsui devtype[0] = '\0';
299 1.22 tsutsui
300 1.22 tsutsui if (devname != NULL)
301 1.22 tsutsui devname[0] = '\0';
302 1.22 tsutsui if (fname != NULL)
303 1.22 tsutsui fname[0] = '\0';
304 1.22 tsutsui if (ppart != NULL)
305 1.22 tsutsui *ppart = 0;
306 1.22 tsutsui
307 1.22 tsutsui strlcpy(str, path, sizeof(str));
308 1.22 tsutsui lp = str;
309 1.22 tsutsui for (cp = str; *cp != '\0'; lp = cp) {
310 1.22 tsutsui /* For each component of the path name... */
311 1.22 tsutsui while (*++cp != '\0' && *cp != '/')
312 1.22 tsutsui continue;
313 1.22 tsutsui savec = *cp;
314 1.22 tsutsui *cp = '\0';
315 1.22 tsutsui /* ...look whether there is a device with this name */
316 1.22 tsutsui dhandle = OF_finddevice(str);
317 1.22 tsutsui DPRINTF("%s: Checking %s: dhandle = %d\n",
318 1.22 tsutsui __func__, str, dhandle);
319 1.22 tsutsui *cp = savec;
320 1.22 tsutsui if (dhandle != -1) {
321 1.22 tsutsui /*
322 1.22 tsutsui * If it's a vaild device, lp is a delimiter
323 1.22 tsutsui * in the OF device path.
324 1.22 tsutsui */
325 1.22 tsutsui if (OF_getprop(dhandle, "device_type", devtype,
326 1.22 tsutsui sizeof devtype) < 0)
327 1.22 tsutsui devtype[0] = '\0';
328 1.22 tsutsui continue;
329 1.22 tsutsui }
330 1.22 tsutsui
331 1.22 tsutsui /*
332 1.22 tsutsui * If not, lp is the delimiter between OF device path
333 1.22 tsutsui * and the specified filename.
334 1.22 tsutsui */
335 1.22 tsutsui
336 1.22 tsutsui /* Check if the last component was a block device... */
337 1.22 tsutsui if (strcmp(devtype, "block") == 0) {
338 1.22 tsutsui /* search for arguments */
339 1.22 tsutsui for (cp = lp;
340 1.22 tsutsui --cp >= str && *cp != '/' && *cp != ':';)
341 1.22 tsutsui continue;
342 1.22 tsutsui if (cp >= str && *cp == ':') {
343 1.22 tsutsui /* found arguments */
344 1.22 tsutsui for (cp = lp;
345 1.22 tsutsui *--cp != ':' && *cp != ',';)
346 1.22 tsutsui continue;
347 1.22 tsutsui if (*++cp >= 'a' &&
348 1.22 tsutsui *cp <= 'a' + MAXPARTITIONS &&
349 1.22 tsutsui ppart != NULL)
350 1.22 tsutsui *ppart = *cp;
351 1.22 tsutsui }
352 1.22 tsutsui }
353 1.22 tsutsui if (*lp != '\0') {
354 1.22 tsutsui /* set filename */
355 1.22 tsutsui DPRINTF("%s: filename = %s\n", __func__, lp);
356 1.22 tsutsui if (fname != NULL)
357 1.22 tsutsui strcpy(fname, lp);
358 1.22 tsutsui if (str != lp) {
359 1.22 tsutsui /* set device path */
360 1.22 tsutsui *lp = '\0';
361 1.22 tsutsui DPRINTF("%s: device path = %s\n",
362 1.22 tsutsui __func__, str);
363 1.22 tsutsui if (devname != NULL)
364 1.22 tsutsui strcpy(devname, str);
365 1.22 tsutsui }
366 1.22 tsutsui }
367 1.22 tsutsui return true;
368 1.22 tsutsui }
369 1.22 tsutsui
370 1.22 tsutsui DPRINTF("%s: invalid path?\n", __func__);
371 1.22 tsutsui return false;
372 1.22 tsutsui }
373 1.22 tsutsui
374 1.1 tsubai int
375 1.14 aymeric devopen(struct open_file *of, const char *name, char **file)
376 1.1 tsubai {
377 1.1 tsubai char *cp;
378 1.1 tsubai char partition;
379 1.22 tsutsui char devname[MAXBOOTPATHLEN];
380 1.22 tsutsui char filename[MAXBOOTPATHLEN];
381 1.1 tsubai char buf[DEV_BSIZE];
382 1.1 tsubai struct disklabel label;
383 1.1 tsubai int handle, part;
384 1.17 uwe size_t nread;
385 1.1 tsubai int error = 0;
386 1.1 tsubai
387 1.1 tsubai if (ofdev.handle != -1)
388 1.1 tsubai panic("devopen");
389 1.1 tsubai if (of->f_flags != F_READ)
390 1.1 tsubai return EPERM;
391 1.22 tsutsui
392 1.22 tsutsui if (!parsefilepath(name, devname, filename, &partition))
393 1.22 tsutsui return ENOENT;
394 1.22 tsutsui
395 1.22 tsutsui if (filename[0] == '\0')
396 1.22 tsutsui /* no filename */
397 1.7 tsubai return ENOENT;
398 1.22 tsutsui
399 1.22 tsutsui if (devname[0] == '\0')
400 1.22 tsutsui /* no device, use default bootdev */
401 1.22 tsutsui strlcpy(devname, bootdev, sizeof(devname));
402 1.22 tsutsui
403 1.22 tsutsui DPRINTF("%s: devname = %s, filename = %s\n",
404 1.22 tsutsui __func__, devname, filename);
405 1.22 tsutsui
406 1.22 tsutsui strlcpy(opened_name, devname, sizeof(opened_name));
407 1.1 tsubai if (partition) {
408 1.1 tsubai cp = opened_name + strlen(opened_name);
409 1.1 tsubai *cp++ = ':';
410 1.1 tsubai *cp++ = partition;
411 1.1 tsubai *cp = 0;
412 1.1 tsubai }
413 1.22 tsutsui if (filename[0] != '/')
414 1.22 tsutsui strlcat(opened_name, "/", sizeof(opened_name));
415 1.22 tsutsui strlcat(opened_name, filename, sizeof(opened_name));
416 1.22 tsutsui
417 1.22 tsutsui DPRINTF("%s: opened_name = %s\n", __func__, opened_name);
418 1.22 tsutsui
419 1.22 tsutsui *file = opened_name + strlen(devname) + 1;
420 1.22 tsutsui if ((handle = OF_finddevice(devname)) == -1)
421 1.1 tsubai return ENOENT;
422 1.1 tsubai if (OF_getprop(handle, "device_type", buf, sizeof buf) < 0)
423 1.1 tsubai return ENXIO;
424 1.23 phx if (!strcmp(buf, "block") && strrchr(devname, ':') == NULL)
425 1.23 phx /* indicate raw partition, when missing */
426 1.22 tsutsui strlcat(devname, ":0", sizeof(devname));
427 1.22 tsutsui if ((handle = OF_open(devname)) == -1)
428 1.1 tsubai return ENXIO;
429 1.6 wiz memset(&ofdev, 0, sizeof ofdev);
430 1.1 tsubai ofdev.handle = handle;
431 1.3 tsubai ofdev.dmabuf = NULL;
432 1.3 tsubai OF_call_method("dma-alloc", handle, 1, 1, MAXPHYS, &ofdev.dmabuf);
433 1.1 tsubai if (!strcmp(buf, "block")) {
434 1.1 tsubai ofdev.type = OFDEV_DISK;
435 1.1 tsubai ofdev.bsize = DEV_BSIZE;
436 1.23 phx /* First try to find a disklabel without partitions */
437 1.1 tsubai if (strategy(&ofdev, F_READ,
438 1.17 uwe LABELSECTOR, DEV_BSIZE, buf, &nread) != 0
439 1.17 uwe || nread != DEV_BSIZE
440 1.1 tsubai || getdisklabel(buf, &label)) {
441 1.23 phx /* Else try APM or MBR partitions */
442 1.23 phx if (((struct drvr_map *)buf)->sbSig == DRIVER_MAP_MAGIC)
443 1.23 phx error = search_mac_label(&ofdev, buf, &label);
444 1.23 phx else
445 1.23 phx error = search_dos_label(&ofdev, 0, buf,
446 1.23 phx &label, 0);
447 1.1 tsubai if (error && error != ERDLAB)
448 1.1 tsubai goto bad;
449 1.1 tsubai }
450 1.1 tsubai
451 1.1 tsubai if (error == ERDLAB) {
452 1.1 tsubai if (partition)
453 1.8 tsutsui /*
454 1.8 tsutsui * User specified a parititon,
455 1.8 tsutsui * but there is none
456 1.8 tsutsui */
457 1.1 tsubai goto bad;
458 1.23 phx /* No label, just use complete disk */
459 1.1 tsubai ofdev.partoff = 0;
460 1.1 tsubai } else {
461 1.1 tsubai part = partition ? partition - 'a' : 0;
462 1.1 tsubai ofdev.partoff = label.d_partitions[part].p_offset;
463 1.1 tsubai }
464 1.8 tsutsui
465 1.19 mrg of->f_dev = of_devsw;
466 1.1 tsubai of->f_devdata = &ofdev;
467 1.20 hauke file_system[0] = file_system_ffsv1;
468 1.20 hauke file_system[1] = file_system_ffsv2;
469 1.20 hauke file_system[2] = file_system_lfsv1;
470 1.20 hauke file_system[3] = file_system_lfsv2;
471 1.20 hauke file_system[4] = file_system_ustarfs;
472 1.20 hauke file_system[5] = file_system_cd9660;
473 1.20 hauke file_system[6] = file_system_hfs;
474 1.20 hauke nfsys = 7;
475 1.1 tsubai return 0;
476 1.1 tsubai }
477 1.1 tsubai if (!strcmp(buf, "network")) {
478 1.1 tsubai ofdev.type = OFDEV_NET;
479 1.19 mrg of->f_dev = of_devsw;
480 1.1 tsubai of->f_devdata = &ofdev;
481 1.5 tsubai file_system[0] = file_system_nfs;
482 1.1 tsubai nfsys = 1;
483 1.17 uwe if ((error = net_open(&ofdev)))
484 1.1 tsubai goto bad;
485 1.1 tsubai return 0;
486 1.1 tsubai }
487 1.1 tsubai error = EFTYPE;
488 1.1 tsubai bad:
489 1.1 tsubai OF_close(handle);
490 1.1 tsubai ofdev.handle = -1;
491 1.1 tsubai return error;
492 1.1 tsubai }
493