]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - sys/boot/common/disk.h
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / sys / boot / common / disk.h
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
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.
13  *
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
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28
29 /*
30  * Device descriptor for partitioned disks. We assume that all disk addresses
31  * are 512 byte block offsets from the start of the disk. To use, set the
32  * d_slice and d_partition variables as follows:
33  *
34  * Whole disk access:
35  *
36  *      d_slice = -1
37  *      d_partition = -1
38  *
39  * Whole MBR slice:
40  *
41  *      d_slice = MBR slice number (typically 1..4)
42  *      d_partition = -1
43  *
44  * BSD disklabel partition within an MBR slice:
45  *
46  *      d_slice = MBR slice number (typically 1..4)
47  *      d_partition = disklabel partition (typically 0..7)
48  *
49  * GPT partition:
50  *
51  *      d_slice = GPT partition number (typically 1..N)
52  *      d_partition = 255
53  *
54  * For both MBR and GPT, to automatically find the 'best' slice or partition,
55  * set d_slice to zero. This uses the partition type to decide which partition
56  * to use according to the following list of preferences:
57  *
58  *      FreeBSD (active)
59  *      FreeBSD (inactive)
60  *      Linux (active)
61  *      Linux (inactive)
62  *      DOS/Windows (active)
63  *      DOS/Windows (inactive)
64  *
65  * Active MBR slices (marked as bootable) are preferred over inactive. GPT
66  * doesn't have the concept of active/inactive partitions. In both MBR and GPT,
67  * if there are multiple slices/partitions of a given type, the first one
68  * is chosen.
69  *
70  * The low-level disk device will typically call slice_open() from its open
71  * method to interpret the disk partition tables according to the rules above.
72  * This will initialize d_offset to the block offset of the start of the
73  * selected partition - this offset should be added to the offset passed to
74  * the device's strategy method.
75  */
76
77 #define DISK_SECSIZE    512
78
79 struct disk_devdesc
80 {
81         struct devsw    *d_dev;
82         int             d_type;
83         int             d_unit;
84         void            *d_opendata;
85         int             d_slice;
86         int             d_partition;
87         int             d_offset;
88 };
89
90 /*
91  * Parse disk metadata and initialise dev->d_offset.
92  */
93 extern int disk_open(struct disk_devdesc * dev);
94
95 /*
96  * Print information about slices on a disk.  For the size calculations we
97  * assume a 512 byte sector.
98  */
99 extern void disk_print(struct disk_devdesc *dev, char *prefix, int verbose);