1/*- 2 * Copyright (c) 2011 Google, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 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 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: stable/11/sys/boot/userboot/userboot/userboot_disk.c 328889 2018-02-05 17:01:18Z kevans $"); |
29 30/* 31 * Userboot disk image handling. 32 */ 33 34#include <sys/disk.h> 35#include <stand.h> 36#include <stdarg.h> --- 18 unchanged lines hidden (view full) --- 55static void userdisk_cleanup(void); 56static int userdisk_strategy(void *devdata, int flag, daddr_t dblk, 57 size_t size, char *buf, size_t *rsize); 58static int userdisk_realstrategy(void *devdata, int flag, daddr_t dblk, 59 size_t size, char *buf, size_t *rsize); 60static int userdisk_open(struct open_file *f, ...); 61static int userdisk_close(struct open_file *f); 62static int userdisk_ioctl(struct open_file *f, u_long cmd, void *data); |
63static int userdisk_print(int verbose); |
64 65struct devsw userboot_disk = { 66 "disk", 67 DEVT_DISK, 68 userdisk_init, 69 userdisk_strategy, 70 userdisk_open, 71 userdisk_close, --- 39 unchanged lines hidden (view full) --- 111 if (userdisk_maxunit > 0) 112 free(ud_info); 113 disk_cleanup(&userboot_disk); 114} 115 116/* 117 * Print information about disks 118 */ |
119static int |
120userdisk_print(int verbose) 121{ 122 struct disk_devdesc dev; 123 char line[80]; |
124 int i, ret = 0; |
125 |
126 if (userdisk_maxunit == 0) 127 return (0); 128 129 printf("%s devices:", userboot_disk.dv_name); 130 if ((ret = pager_output("\n")) != 0) 131 return (ret); 132 |
133 for (i = 0; i < userdisk_maxunit; i++) { |
134 snprintf(line, sizeof(line), 135 " disk%d: Guest drive image\n", i); 136 ret = pager_output(line); 137 if (ret != 0) 138 break; |
139 dev.d_dev = &userboot_disk; 140 dev.d_unit = i; 141 dev.d_slice = -1; 142 dev.d_partition = -1; 143 if (disk_open(&dev, ud_info[i].mediasize, 144 ud_info[i].sectorsize, 0) == 0) { |
145 snprintf(line, sizeof(line), " disk%d", i); 146 ret = disk_print(&dev, line, verbose); |
147 disk_close(&dev); |
148 if (ret != 0) 149 break; |
150 } 151 } |
152 return (ret); |
153} 154 155/* 156 * Attempt to open the disk described by (dev) for use by (f). 157 */ 158static int 159userdisk_open(struct open_file *f, ...) 160{ --- 77 unchanged lines hidden --- |