1 /* $NetBSD: devopen.c,v 1.8 2005/12/11 12:18:24 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>
34 #include <machine/romcall.h>
37 # define DPRINTF printf
39 # define DPRINTF while (0) printf
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
[] = {
55 int nfsys
= __arraycount(file_system
);
62 devopen(struct open_file
*f
, const char *fname
, char **file
)
68 DPRINTF("devopen: %s\n", fname
);
70 strcpy(devname
, fname
);
71 cp
= strchr(devname
, ')') + 1;
73 fd
= rom_open(devname
, 0);
75 DPRINTF("devname = %s, fd = %d\n", devname
, fd
);
82 f
->f_devdata
= &romdev
;
83 *file
= strchr(fname
, ')') + 1;
89 dkopen(struct open_file
*f
, ...)
97 dkclose(struct open_file
*f
)
99 struct romdev
*dev
= f
->f_devdata
;
101 DPRINTF("dkclose\n");
107 dkstrategy(void *devdata
, int rw
, daddr_t blk
, size_t size
, void *buf
,
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
);