199767f8919635c4928607450d9e0abb932109ceToomas Soome/*-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2011 Google, Inc.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * are met:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * $FreeBSD$
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Device descriptor for partitioned disks. To use, set the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * d_slice and d_partition variables as follows:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Whole disk access:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * d_slice = -1
199767f8919635c4928607450d9e0abb932109ceToomas Soome * d_partition = -1
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Whole MBR slice:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * d_slice = MBR slice number (typically 1..4)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * d_partition = -1
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * VTOC disklabel partition within an MBR slice:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * d_slice = MBR slice number (typically 1..4)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * d_partition = disklabel partition (typically 0..19)
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * BSD disklabel partition within an MBR slice:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * d_slice = MBR slice number (typically 1..4)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * d_partition = disklabel partition (typically 0..19)
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * BSD disklabel partition on the true dedicated disk:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * d_slice = -1
199767f8919635c4928607450d9e0abb932109ceToomas Soome * d_partition = disklabel partition (typically 0..19)
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * GPT partition:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * d_slice = GPT partition number (typically 1..N)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * d_partition = 255
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * For both MBR and GPT, to automatically find the 'best' slice or partition,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * set d_slice to zero. This uses the partition type to decide which partition
199767f8919635c4928607450d9e0abb932109ceToomas Soome * to use according to the following list of preferences:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Solaris2 (active)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Solaris2 (inactive)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Linux (active)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Linux (inactive)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DOS/Windows (active)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DOS/Windows (inactive)
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Active MBR slices (marked as bootable) are preferred over inactive. GPT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * doesn't have the concept of active/inactive partitions. In both MBR and GPT,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * if there are multiple slices/partitions of a given type, the first one
199767f8919635c4928607450d9e0abb932109ceToomas Soome * is chosen.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The low-level disk device will typically call disk_open() from its open
199767f8919635c4928607450d9e0abb932109ceToomas Soome * method to interpret the disk partition tables according to the rules above.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This will initialize d_offset to the block offset of the start of the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * selected partition - this offset should be added to the offset passed to
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the device's strategy method.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct disk_devdesc
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct devsw *d_dev;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int d_type;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int d_unit;
199767f8919635c4928607450d9e0abb932109ceToomas Soome void *d_opendata;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int d_slice;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int d_partition;
199767f8919635c4928607450d9e0abb932109ceToomas Soome off_t d_offset;
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeenum disk_ioctl {
199767f8919635c4928607450d9e0abb932109ceToomas Soome IOCTL_GET_BLOCKS,
199767f8919635c4928607450d9e0abb932109ceToomas Soome IOCTL_GET_BLOCK_SIZE
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Parse disk metadata and initialise dev->d_offset.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern int disk_open(struct disk_devdesc *dev, off_t mediasize,
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int sectorsize, u_int flags);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DISK_F_NOCACHE 0x0001 /* Do not use metadata caching */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern int disk_close(struct disk_devdesc *dev);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern void disk_cleanup(const struct devsw *d_dev);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern int disk_ioctl(struct disk_devdesc *dev, u_long cmd, void *buf);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern int disk_read(struct disk_devdesc *dev, void *buf, off_t offset,
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int blocks);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern int disk_write(struct disk_devdesc *dev, void *buf, off_t offset,
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int blocks);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Print information about slices on a disk.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern int disk_print(struct disk_devdesc *dev, char *prefix, int verbose);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern char* disk_fmtdev(struct disk_devdesc *dev);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern int disk_parsedev(struct disk_devdesc *dev, const char *devspec,
199767f8919635c4928607450d9e0abb932109ceToomas Soome const char **path);