/*-1* Copyright (c) 2011 Google, Inc.2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*/2526/*27* Device descriptor for partitioned disks. To use, set the28* d_slice and d_partition variables as follows:29*30* Whole disk access:31*32* d_slice = D_SLICENONE33* d_partition = <doesn't matter>34*35* Whole MBR slice:36*37* d_slice = MBR slice number (typically 1..4)38* d_partition = D_PARTNONE39*40* BSD disklabel partition within an MBR slice:41*42* d_slice = MBR slice number (typically 1..4)43* d_partition = disklabel partition (typically 0..19 or D_PARTWILD)44*45* BSD disklabel partition on the true dedicated disk:46*47* d_slice = D_SLICENONE48* d_partition = disklabel partition (typically 0..19 or D_PARTWILD)49*50* GPT partition:51*52* d_slice = GPT partition number (typically 1..N)53* d_partition = D_PARTISGPT54*55* For MBR, setting d_partition to D_PARTWILD will automatically use the first56* partition within the slice.57*58* For both MBR and GPT, to automatically find the 'best' slice and partition,59* set d_slice to D_SLICEWILD. This uses the partition type to decide which60* partition to use according to the following list of preferences:61*62* FreeBSD (active)63* FreeBSD (inactive)64* Linux (active)65* Linux (inactive)66* DOS/Windows (active)67* DOS/Windows (inactive)68*69* Active MBR slices (marked as bootable) are preferred over inactive. GPT70* doesn't have the concept of active/inactive partitions. In both MBR and GPT,71* if there are multiple slices/partitions of a given type, the first one72* is chosen.73*74* The low-level disk device will typically call disk_open() from its open75* method to interpret the disk partition tables according to the rules above.76* This will initialize d_offset to the block offset of the start of the77* selected partition - this offset should be added to the offset passed to78* the device's strategy method.79*/8081#ifndef _DISK_H82#define _DISK_H8384#define D_SLICENONE -185#define D_SLICEWILD 086#define D_PARTNONE -187#define D_PARTWILD -288#define D_PARTISGPT 2558990struct disk_devdesc {91struct devdesc dd; /* Must be first. */92int d_slice;93int d_partition;94uint64_t d_offset;95};9697/*98* Parse disk metadata and initialise dev->d_offset.99*/100extern int disk_open(struct disk_devdesc *, uint64_t, u_int);101extern int disk_close(struct disk_devdesc *);102extern int disk_ioctl(struct disk_devdesc *, u_long, void *);103extern int disk_read(struct disk_devdesc *, void *, uint64_t, u_int);104extern int disk_write(struct disk_devdesc *, void *, uint64_t, u_int);105extern int ptblread(void *, void *, size_t, uint64_t);106107/*108* Print information about slices on a disk.109*/110extern int disk_print(struct disk_devdesc *, char *, int);111extern int disk_parsedev(struct devdesc **, const char *, const char **);112113char *disk_fmtdev(struct devdesc *vdev);114115#endif /* _DISK_H */116117118