devopen.c revision 1.3 1 /* $NetBSD: devopen.c,v 1.3 2002/04/30 13:09:05 tsutsui Exp $ */
2
3 /*-
4 * Copyright (C) 1999 Tsubai Masanari. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
16 *
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.
27 */
28
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
34 #include <machine/romcall.h>
35
36 #ifdef BOOT_DEBUG
37 # define DPRINTF(x) printf x
38 #else
39 # define DPRINTF(x)
40 #endif
41
42 int dkopen __P((struct open_file *, ...));
43 int dkclose __P((struct open_file *));
44 int dkstrategy __P((void *, int, daddr_t, size_t, void *, size_t *));
45
46 struct devsw devsw[] = {
47 { "dk", dkstrategy, dkopen, dkclose, noioctl }
48 };
49 int ndevs = sizeof(devsw) / sizeof(devsw[0]);
50
51 struct fs_ops file_system[] = {
52 { ufs_open, ufs_close, ufs_read, ufs_write, ufs_seek, ufs_stat },
53 { ustarfs_open, ustarfs_close, ustarfs_read, ustarfs_write,
54 ustarfs_seek, ustarfs_stat }
55 };
56 int nfsys = sizeof(file_system) / sizeof(file_system[0]);
57
58 struct romdev {
59 int fd;
60 } romdev;
61
62 int
63 devopen(f, fname, file)
64 struct open_file *f;
65 const char *fname;
66 char **file; /* out */
67 {
68 int fd;
69 char devname[32];
70 char *cp;
71
72 DPRINTF(("devopen: %s\n", fname));
73
74 strcpy(devname, fname);
75 cp = strchr(devname, ')') + 1;
76 *cp = 0;
77 fd = rom_open(devname, 0);
78
79 DPRINTF(("devname = %s, fd = %d\n", devname, fd));
80 if (fd == -1)
81 return -1;
82
83 romdev.fd = fd;
84
85 f->f_dev = devsw;
86 f->f_devdata = &romdev;
87 *file = strchr(fname, ')') + 1;
88
89 return 0;
90 }
91
92 int
93 dkopen(struct open_file *f, ...)
94 {
95 DPRINTF(("dkopen\n"));
96 return 0;
97 }
98
99 int
100 dkclose(f)
101 struct open_file *f;
102 {
103 struct romdev *dev = f->f_devdata;
104
105 DPRINTF(("dkclose\n"));
106 rom_close(dev->fd);
107 return 0;
108 }
109
110 int
111 dkstrategy(devdata, rw, blk, size, buf, rsize)
112 void *devdata;
113 int rw;
114 daddr_t blk;
115 size_t size;
116 void *buf;
117 size_t *rsize; /* out: number of bytes transfered */
118 {
119 struct romdev *dev = devdata;
120
121 /* XXX should use partition offset */
122
123 rom_lseek(dev->fd, blk * 512, 0);
124 rom_read(dev->fd, buf, size);
125 *rsize = size;
126 return 0;
127 }
128