devopen.c revision 1.6 1 /* $NetBSD: devopen.c,v 1.6 2004/09/04 13:43:12 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 printf
38 #else
39 # define DPRINTF while (0) printf
40 #endif
41
42 int dkopen(struct open_file *, ...);
43 int dkclose(struct open_file *);
44 int dkstrategy(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(struct open_file *f, const char *fname, char **file)
64 {
65 int fd;
66 char devname[32];
67 char *cp;
68
69 DPRINTF("devopen: %s\n", fname);
70
71 strcpy(devname, fname);
72 cp = strchr(devname, ')') + 1;
73 *cp = 0;
74 fd = rom_open(devname, 0);
75
76 DPRINTF("devname = %s, fd = %d\n", devname, fd);
77 if (fd == -1)
78 return -1;
79
80 romdev.fd = fd;
81
82 f->f_dev = devsw;
83 f->f_devdata = &romdev;
84 *file = strchr(fname, ')') + 1;
85
86 return 0;
87 }
88
89 int
90 dkopen(struct open_file *f, ...)
91 {
92
93 DPRINTF("dkopen\n");
94 return 0;
95 }
96
97 int
98 dkclose(struct open_file *f)
99 {
100 struct romdev *dev = f->f_devdata;
101
102 DPRINTF("dkclose\n");
103 rom_close(dev->fd);
104 return 0;
105 }
106
107 int
108 dkstrategy(void *devdata, int rw, daddr_t blk, size_t size, void *buf,
109 size_t *rsize)
110 {
111 struct romdev *dev = devdata;
112
113 /* XXX should use partition offset */
114
115 rom_lseek(dev->fd, blk * 512, 0);
116 rom_read(dev->fd, buf, size);
117 *rsize = size;
118 return 0;
119 }
120