1 /* $NetBSD: devopen.c,v 1.9 2005/12/11 12:18:25 christos Exp $ */
4 * Copyright (C) 1999 Tsubai Masanari. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <lib/libkern/libkern.h>
30 #include <lib/libsa/stand.h>
31 #include <lib/libsa/ufs.h>
32 #include <lib/libsa/ustarfs.h>
33 #include <netinet/in.h>
34 #include <lib/libsa/nfs.h>
36 #include <machine/apcall.h>
37 #include <machine/romcall.h>
41 # define DPRINTF printf
43 # define DPRINTF while (0) printf
46 int dkopen(struct open_file
*, ...);
47 int dkclose(struct open_file
*);
48 int dkstrategy(void *, int, daddr_t
, size_t, void *, size_t *);
49 #ifdef HAVE_CHANGEDISK_HOOK
50 void changedisk_hook(struct open_file
*);
53 struct devsw devsw
[] = {
54 { "dk", dkstrategy
, dkopen
, dkclose
, noioctl
}
56 int ndevs
= __arraycount(devsw
);
58 struct fs_ops file_system_ufs
= FS_OPS(ufs
);
59 struct fs_ops file_system_nfs
= FS_OPS(nfs
);
60 #ifdef SUPPORT_USTARFS
61 struct fs_ops file_system_ustarfs
= FS_OPS(ustarfs
);
62 struct fs_ops file_system
[2];
64 struct fs_ops file_system
[1];
73 devopen(struct open_file
*f
, const char *fname
, char **file
)
79 DPRINTF("devopen: %s\n", fname
);
81 strcpy(romdev
.devname
, fname
);
82 cp
= strchr(romdev
.devname
, ')') + 1;
85 fd
= apcall_open(romdev
.devname
, 2);
87 fd
= rom_open(romdev
.devname
, 2);
89 DPRINTF("devname = %s, fd = %d\n", romdev
.devname
, fd
);
94 if (strncmp(romdev
.devname
, "sonic", 5) == 0)
95 romdev
.devtype
= DT_NET
;
97 romdev
.devtype
= DT_BLOCK
;
100 f
->f_devdata
= &romdev
;
101 *file
= strchr(fname
, ')') + 1;
103 if (romdev
.devtype
== DT_BLOCK
) {
104 file_system
[0] = file_system_ufs
;
105 #ifdef SUPPORT_USTARFS
106 file_system
[1] = file_system_ustarfs
;
111 } else { /* DT_NET */
112 file_system
[0] = file_system_nfs
;
115 if ((error
= net_open(&romdev
)) != 0) {
116 printf("Can't open NFS network connection on `%s'\n",
126 dkopen(struct open_file
*f
, ...)
134 dkclose(struct open_file
*f
)
136 struct romdev
*dev
= f
->f_devdata
;
138 DPRINTF("dkclose\n");
140 apcall_close(dev
->fd
);
148 dkstrategy(void *devdata
, int rw
, daddr_t blk
, size_t size
, void *buf
,
151 struct romdev
*dev
= devdata
;
153 /* XXX should use partition offset */
156 apcall_lseek(dev
->fd
, blk
* 512, 0);
157 apcall_read(dev
->fd
, buf
, size
);
159 rom_lseek(dev
->fd
, blk
* 512, 0);
160 rom_read(dev
->fd
, buf
, size
);
162 *rsize
= size
; /* XXX */
166 #ifdef HAVE_CHANGEDISK_HOOK
168 changedisk_hook(struct open_file
*f
)
170 struct romdev
*dev
= f
->f_devdata
;
173 apcall_ioctl(dev
->fd
, APIOCEJECT
, NULL
);
174 apcall_close(dev
->fd
);
176 dev
->fd
= apcall_open(dev
->devname
, 2);
178 rom_ioctl(dev
->fd
, SYSIOCEJECT
, NULL
);
181 dev
->fd
= rom_open(dev
->devname
, 2);