2 * Copyright (C) 2014 Nathan Whitehorn
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
29 #include <sys/types.h>
31 #include "bootstrap.h"
32 #include "host_syscall.h"
34 static int hostdisk_init(void);
35 static int hostdisk_strategy(void *devdata, int flag, daddr_t dblk,
36 size_t size, char *buf, size_t *rsize);
37 static int hostdisk_open(struct open_file *f, ...);
38 static int hostdisk_close(struct open_file *f);
39 static int hostdisk_ioctl(struct open_file *f, u_long cmd, void *data);
40 static void hostdisk_print(int verbose);
42 struct devsw hostdisk = {
61 hostdisk_strategy(void *devdata, int flag, daddr_t dblk, size_t size,
62 char *buf, size_t *rsize)
64 struct devdesc *desc = devdata;
70 if (host_seek(desc->d_unit, pos, 0) < 0) {
71 printf("Seek error\n");
74 n = host_read(desc->d_unit, buf, size);
84 hostdisk_open(struct open_file *f, ...)
90 desc = va_arg(vl, struct devdesc *);
93 desc->d_unit = host_open(desc->d_opendata, O_RDONLY, 0);
95 if (desc->d_unit <= 0) {
96 printf("hostdisk_open: couldn't open %s: %d\n",
97 desc->d_opendata, desc->d_unit);
105 hostdisk_close(struct open_file *f)
107 struct devdesc *desc = f->f_devdata;
109 host_close(desc->d_unit);
114 hostdisk_ioctl(struct open_file *f, u_long cmd, void *data)
121 hostdisk_print(int verbose)