1 /* $NetBSD: devopen.c,v 1.3 2007/10/27 12:26:20 tsutsui Exp $ */
4 * Copyright (c) 2004 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <lib/libsa/stand.h>
33 #include <lib/libkern/libkern.h>
35 #include <netinet/in.h>
36 #include <lib/libsa/dev_net.h>
37 #include <lib/libsa/ufs.h>
38 #include <lib/libsa/nfs.h>
39 #include <lib/libsa/dev_net.h>
40 #include <machine/sbd.h>
44 extern uint8_t kernel_binary
[];
45 extern int kernel_binary_size
;
47 extern struct fs_ops datafs_ops
;
48 extern struct fs_ops bfs_ops
;
49 struct fs_ops ufs_ops
= {
50 ufs_open
, ufs_close
, ufs_read
, ufs_write
, ufs_seek
, ufs_stat
52 struct fs_ops nfs_ops
= {
53 nfs_open
, nfs_close
, nfs_read
, nfs_write
, nfs_seek
, nfs_stat
56 extern struct devsw netdevsw
;
57 extern struct devsw dkdevsw
;
60 /* Referenced by libsa/open.c */
61 struct fs_ops file_system
[1];
63 struct devsw devsw
[1];
67 devopen(struct open_file
*f
, const char *request
, char **file
)
74 strcpy(fname
, request
);
77 for (p
= fname
; *p
; p
++) {
85 if (filename
== 0) { /* not a loader's request. probably ufs_ls() */
86 printf("request=%s\n", request
);
88 file_system
[0] = ufs_ops
;
95 if (strcmp(fname
, "mem") == 0) {
96 data_attach(kernel_binary
, kernel_binary_size
);
98 f
->f_flags
|= F_NODEV
;
99 file_system
[0] = datafs_ops
;
100 printf("data(compiled):noname\n");
105 if (strcmp(fname
, "nfs") == 0) {
106 if (!DEVICE_CAPABILITY
.network_enabled
) {
107 printf("Network disabled.\n");
111 file_system
[0] = nfs_ops
;
112 f
->f_dev
= &netdevsw
;
113 if (*filename
== '\0') {
114 printf("set kernel filename. ex.) nfs:netbsd\n");
119 printf("nfs:/%s\n", filename
);
125 if (strcmp(fname
, "fd") == 0) {
126 printf("floppy(boot):/%s (ustarfs)\n", filename
);
128 file_system
[0] = datafs_ops
;
130 device_attach(NVSRAM_BOOTDEV_FLOPPYDISK
, -1, -1);
131 if (!ustarfs_load(filename
, &addr
, &size
))
133 data_attach(addr
, size
);
139 if (strncmp(fname
, "sd", 2) == 0) {
141 if (!DEVICE_CAPABILITY
.disk_enabled
) {
142 printf("Disk disabled.\n");
146 disk
= fname
[2] - '0';
147 partition
= fname
[3] - 'a';
148 if (disk
< 0 || disk
> 9 || partition
< 0 || partition
> 15) {
150 printf("disk(boot):%s ", filename
);
151 device_attach(NVSRAM_BOOTDEV_HARDDISK
, -1, -1);
153 fs
= fstype(partition
);
154 printf("disk(%d,%d):/%s ",
155 disk
, partition
, filename
);
156 device_attach(NVSRAM_BOOTDEV_HARDDISK
, disk
, partition
);
163 file_system
[0] = ufs_ops
;
168 f
->f_flags
|= F_NODEV
;
169 file_system
[0] = bfs_ops
;
172 printf(" (ustarfs)\n");
174 file_system
[0] = datafs_ops
;
176 if (!ustarfs_load(filename
, &addr
, &size
))
178 data_attach(addr
, size
);
185 printf("%s invalid.\n", fname
);