2 * Copyright (c) 2011 Google, Inc.
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 AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
31 * Userboot disk image handling.
39 #include <bootstrap.h>
42 #include "libuserboot.h"
44 int userboot_disk_maxunit = 0;
46 static int userdisk_init(void);
47 static int userdisk_strategy(void *devdata, int flag, daddr_t dblk,
48 size_t size, char *buf, size_t *rsize);
49 static int userdisk_open(struct open_file *f, ...);
50 static int userdisk_close(struct open_file *f);
51 static void userdisk_print(int verbose);
53 struct devsw userboot_disk = {
76 * Print information about disks
79 userdisk_print(int verbose)
83 struct disk_devdesc dev;
85 for (i = 0; i < userboot_disk_maxunit; i++) {
86 sprintf(line, " disk%d: Guest drive image\n", i);
88 dev.d_dev = &userboot_disk;
93 sprintf(line, " disk%d", i);
94 disk_print(&dev, line, verbose);
99 * Attempt to open the disk described by (dev) for use by (f).
102 userdisk_open(struct open_file *f, ...)
105 struct disk_devdesc *dev;
108 dev = va_arg(ap, struct disk_devdesc *);
111 if (dev->d_unit < 0 || dev->d_unit >= userboot_disk_maxunit)
114 return (disk_open(dev));
118 userdisk_close(struct open_file *f)
125 userdisk_strategy(void *devdata, int rw, daddr_t dblk, size_t size,
126 char *buf, size_t *rsize)
128 struct disk_devdesc *dev = devdata;
139 off = (dblk + dev->d_offset) * DISK_SECSIZE;
140 rc = CALLBACK(diskread, dev->d_unit, off, buf, size, &resid);
144 *rsize = size - resid;