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