No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / news68k / stand / boot / devopen.c
blobea2a802fd8a07f8b33825ecd9a5ff9a9a3669307
1 /* $NetBSD: devopen.c,v 1.8 2005/12/11 12:18:24 christos Exp $ */
3 /*-
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
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.
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>
34 #include <machine/romcall.h>
36 #ifdef BOOT_DEBUG
37 # define DPRINTF printf
38 #else
39 # define DPRINTF while (0) printf
40 #endif
42 int dkopen(struct open_file *, ...);
43 int dkclose(struct open_file *);
44 int dkstrategy(void *, int, daddr_t, size_t, void *, size_t *);
46 struct devsw devsw[] = {
47 { "dk", dkstrategy, dkopen, dkclose, noioctl }
49 int ndevs = __arraycount(devsw);
51 struct fs_ops file_system[] = {
52 FS_OPS(ufs),
53 FS_OPS(ustarfs),
55 int nfsys = __arraycount(file_system);
57 struct romdev {
58 int fd;
59 } romdev;
61 int
62 devopen(struct open_file *f, const char *fname, char **file)
64 int fd;
65 char devname[32];
66 char *cp;
68 DPRINTF("devopen: %s\n", fname);
70 strcpy(devname, fname);
71 cp = strchr(devname, ')') + 1;
72 *cp = 0;
73 fd = rom_open(devname, 0);
75 DPRINTF("devname = %s, fd = %d\n", devname, fd);
76 if (fd == -1)
77 return -1;
79 romdev.fd = fd;
81 f->f_dev = devsw;
82 f->f_devdata = &romdev;
83 *file = strchr(fname, ')') + 1;
85 return 0;
88 int
89 dkopen(struct open_file *f, ...)
92 DPRINTF("dkopen\n");
93 return 0;
96 int
97 dkclose(struct open_file *f)
99 struct romdev *dev = f->f_devdata;
101 DPRINTF("dkclose\n");
102 rom_close(dev->fd);
103 return 0;
107 dkstrategy(void *devdata, int rw, daddr_t blk, size_t size, void *buf,
108 size_t *rsize)
110 struct romdev *dev = devdata;
112 /* XXX should use partition offset */
114 rom_lseek(dev->fd, blk * 512, 0);
115 rom_read(dev->fd, buf, size);
116 *rsize = size;
117 return 0;