1223695Sdfr/*- 2223695Sdfr * Copyright (c) 2011 Google, Inc. 3223695Sdfr * All rights reserved. 4223695Sdfr * 5223695Sdfr * Redistribution and use in source and binary forms, with or without 6223695Sdfr * modification, are permitted provided that the following conditions 7223695Sdfr * are met: 8223695Sdfr * 1. Redistributions of source code must retain the above copyright 9223695Sdfr * notice, this list of conditions and the following disclaimer. 10223695Sdfr * 2. Redistributions in binary form must reproduce the above copyright 11223695Sdfr * notice, this list of conditions and the following disclaimer in the 12223695Sdfr * documentation and/or other materials provided with the distribution. 13223695Sdfr * 14223695Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15223695Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16223695Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17223695Sdfr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18223695Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19223695Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20223695Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21223695Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22223695Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23223695Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24223695Sdfr * SUCH DAMAGE. 25223695Sdfr * 26223695Sdfr * $FreeBSD$ 27223695Sdfr */ 28223695Sdfr 29223695Sdfr/* 30243243Sae * Device descriptor for partitioned disks. To use, set the 31223695Sdfr * d_slice and d_partition variables as follows: 32223695Sdfr * 33223695Sdfr * Whole disk access: 34223695Sdfr * 35223695Sdfr * d_slice = -1 36223695Sdfr * d_partition = -1 37223695Sdfr * 38223695Sdfr * Whole MBR slice: 39223695Sdfr * 40223695Sdfr * d_slice = MBR slice number (typically 1..4) 41223695Sdfr * d_partition = -1 42223695Sdfr * 43223695Sdfr * BSD disklabel partition within an MBR slice: 44223695Sdfr * 45223695Sdfr * d_slice = MBR slice number (typically 1..4) 46223695Sdfr * d_partition = disklabel partition (typically 0..7) 47223695Sdfr * 48243243Sae * BSD disklabel partition on the true dedicated disk: 49243243Sae * 50243243Sae * d_slice = -1 51243243Sae * d_partition = disklabel partition (typically 0..7) 52243243Sae * 53223695Sdfr * GPT partition: 54223695Sdfr * 55223695Sdfr * d_slice = GPT partition number (typically 1..N) 56223695Sdfr * d_partition = 255 57223695Sdfr * 58223695Sdfr * For both MBR and GPT, to automatically find the 'best' slice or partition, 59223695Sdfr * set d_slice to zero. This uses the partition type to decide which partition 60223695Sdfr * to use according to the following list of preferences: 61223695Sdfr * 62223695Sdfr * FreeBSD (active) 63223695Sdfr * FreeBSD (inactive) 64223695Sdfr * Linux (active) 65223695Sdfr * Linux (inactive) 66223695Sdfr * DOS/Windows (active) 67223695Sdfr * DOS/Windows (inactive) 68223695Sdfr * 69223695Sdfr * Active MBR slices (marked as bootable) are preferred over inactive. GPT 70223695Sdfr * doesn't have the concept of active/inactive partitions. In both MBR and GPT, 71223695Sdfr * if there are multiple slices/partitions of a given type, the first one 72223695Sdfr * is chosen. 73223695Sdfr * 74223695Sdfr * The low-level disk device will typically call slice_open() from its open 75223695Sdfr * method to interpret the disk partition tables according to the rules above. 76223695Sdfr * This will initialize d_offset to the block offset of the start of the 77223695Sdfr * selected partition - this offset should be added to the offset passed to 78223695Sdfr * the device's strategy method. 79223695Sdfr */ 80223695Sdfr 81223695Sdfrstruct disk_devdesc 82223695Sdfr{ 83223695Sdfr struct devsw *d_dev; 84223695Sdfr int d_type; 85223695Sdfr int d_unit; 86223695Sdfr void *d_opendata; 87223695Sdfr int d_slice; 88223695Sdfr int d_partition; 89243243Sae off_t d_offset; 90223695Sdfr}; 91223695Sdfr 92223695Sdfr/* 93223695Sdfr * Parse disk metadata and initialise dev->d_offset. 94223695Sdfr */ 95243243Saeextern int disk_open(struct disk_devdesc *dev, off_t mediasize, 96243243Sae u_int sectorsize, u_int flags); 97243243Sae#define DISK_F_NOCACHE 0x0001 /* Do not use metadata caching */ 98243243Saeextern int disk_close(struct disk_devdesc *dev); 99243243Saeextern void disk_cleanup(const struct devsw *d_dev); 100223695Sdfr 101223695Sdfr/* 102243243Sae * Print information about slices on a disk. 103223695Sdfr */ 104223695Sdfrextern void disk_print(struct disk_devdesc *dev, char *prefix, int verbose); 105243243Saeextern char* disk_fmtdev(struct disk_devdesc *dev); 106243243Saeextern int disk_parsedev(struct disk_devdesc *dev, const char *devspec, 107243243Sae const char **path); 108243243Sae 109