xref: /illumos-gate/usr/src/boot/common/disk.h (revision 22028508fd28d36ff74dc02c5774a8ba1f0db045)
1*22028508SToomas Soome /*
2*22028508SToomas Soome  * Copyright (c) 2011 Google, Inc.
3*22028508SToomas Soome  * All rights reserved.
4*22028508SToomas Soome  *
5*22028508SToomas Soome  * Redistribution and use in source and binary forms, with or without
6*22028508SToomas Soome  * modification, are permitted provided that the following conditions
7*22028508SToomas Soome  * are met:
8*22028508SToomas Soome  * 1. Redistributions of source code must retain the above copyright
9*22028508SToomas Soome  *    notice, this list of conditions and the following disclaimer.
10*22028508SToomas Soome  * 2. Redistributions in binary form must reproduce the above copyright
11*22028508SToomas Soome  *    notice, this list of conditions and the following disclaimer in the
12*22028508SToomas Soome  *    documentation and/or other materials provided with the distribution.
13*22028508SToomas Soome  *
14*22028508SToomas Soome  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*22028508SToomas Soome  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*22028508SToomas Soome  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*22028508SToomas Soome  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*22028508SToomas Soome  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*22028508SToomas Soome  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*22028508SToomas Soome  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*22028508SToomas Soome  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*22028508SToomas Soome  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*22028508SToomas Soome  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*22028508SToomas Soome  * SUCH DAMAGE.
25*22028508SToomas Soome  */
26*22028508SToomas Soome 
27*22028508SToomas Soome /*
28*22028508SToomas Soome  * Device descriptor for partitioned disks. To use, set the
29*22028508SToomas Soome  * d_slice and d_partition variables as follows:
30*22028508SToomas Soome  *
31*22028508SToomas Soome  * Whole disk access:
32*22028508SToomas Soome  *
33*22028508SToomas Soome  *	d_slice = D_SLICENONE
34*22028508SToomas Soome  *	d_partition = <doesn't matter>
35*22028508SToomas Soome  *
36*22028508SToomas Soome  * Whole MBR slice:
37*22028508SToomas Soome  *
38*22028508SToomas Soome  *	d_slice = MBR slice number (typically 1..4)
39*22028508SToomas Soome  *	d_partition = D_PARTNONE
40*22028508SToomas Soome  *
41*22028508SToomas Soome  * VTOC disklabel partition within an MBR slice:
42*22028508SToomas Soome  *
43*22028508SToomas Soome  *	d_slice = MBR slice number (typically 1..4)
44*22028508SToomas Soome  *	d_partition = disklabel partition (typically 0..19 or D_PARTWILD)
45*22028508SToomas Soome  *
46*22028508SToomas Soome  * BSD disklabel partition within an MBR slice:
47*22028508SToomas Soome  *
48*22028508SToomas Soome  *	d_slice = MBR slice number (typically 1..4)
49*22028508SToomas Soome  *	d_partition = disklabel partition (typically 0..19 or D_PARTWILD)
50*22028508SToomas Soome  *
51*22028508SToomas Soome  * BSD disklabel partition on the true dedicated disk:
52*22028508SToomas Soome  *
53*22028508SToomas Soome  *	d_slice = D_SLICENONE
54*22028508SToomas Soome  *	d_partition = disklabel partition (typically 0..19 or D_PARTWILD)
55*22028508SToomas Soome  *
56*22028508SToomas Soome  * GPT partition:
57*22028508SToomas Soome  *
58*22028508SToomas Soome  *	d_slice = GPT partition number (typically 1..N)
59*22028508SToomas Soome  *	d_partition = D_PARTISGPT
60*22028508SToomas Soome  *
61*22028508SToomas Soome  * For MBR, setting d_partition to D_PARTWILD will automatically use the first
62*22028508SToomas Soome  * partition within the slice.
63*22028508SToomas Soome  *
64*22028508SToomas Soome  * For both MBR and GPT, to automatically find the 'best' slice and partition,
65*22028508SToomas Soome  * set d_slice to D_SLICEWILD. This uses the partition type to decide which
66*22028508SToomas Soome  * partition to use according to the following list of preferences:
67*22028508SToomas Soome  *
68*22028508SToomas Soome  *	Solaris2 (active)
69*22028508SToomas Soome  *	Solaris2 (inactive)
70*22028508SToomas Soome  *	Linux (active)
71*22028508SToomas Soome  *	Linux (inactive)
72*22028508SToomas Soome  *	DOS/Windows (active)
73*22028508SToomas Soome  *	DOS/Windows (inactive)
74*22028508SToomas Soome  *
75*22028508SToomas Soome  * Active MBR slices (marked as bootable) are preferred over inactive. GPT
76*22028508SToomas Soome  * doesn't have the concept of active/inactive partitions. In both MBR and GPT,
77*22028508SToomas Soome  * if there are multiple slices/partitions of a given type, the first one
78*22028508SToomas Soome  * is chosen.
79*22028508SToomas Soome  *
80*22028508SToomas Soome  * The low-level disk device will typically call disk_open() from its open
81*22028508SToomas Soome  * method to interpret the disk partition tables according to the rules above.
82*22028508SToomas Soome  * This will initialize d_offset to the block offset of the start of the
83*22028508SToomas Soome  * selected partition - this offset should be added to the offset passed to
84*22028508SToomas Soome  * the device's strategy method.
85*22028508SToomas Soome  */
86*22028508SToomas Soome 
87*22028508SToomas Soome #ifndef	_DISK_H
88*22028508SToomas Soome #define	_DISK_H
89*22028508SToomas Soome 
90*22028508SToomas Soome #define	D_SLICENONE	-1
91*22028508SToomas Soome #define	D_SLICEWILD	0
92*22028508SToomas Soome #define	D_PARTNONE	-1
93*22028508SToomas Soome #define	D_PARTWILD	-2
94*22028508SToomas Soome #define	D_PARTISGPT	255
95*22028508SToomas Soome 
96*22028508SToomas Soome struct disk_devdesc {
97*22028508SToomas Soome 	struct devdesc	dd;		/* Must be first. */
98*22028508SToomas Soome 	int		d_slice;
99*22028508SToomas Soome 	int		d_partition;
100*22028508SToomas Soome 	uint64_t	d_offset;
101*22028508SToomas Soome };
102*22028508SToomas Soome 
103*22028508SToomas Soome enum disk_ioctl {
104*22028508SToomas Soome 	IOCTL_GET_BLOCKS,
105*22028508SToomas Soome 	IOCTL_GET_BLOCK_SIZE
106*22028508SToomas Soome };
107*22028508SToomas Soome 
108*22028508SToomas Soome /*
109*22028508SToomas Soome  * Parse disk metadata and initialise dev->d_offset.
110*22028508SToomas Soome  */
111*22028508SToomas Soome extern int disk_open(struct disk_devdesc *, uint64_t, u_int);
112*22028508SToomas Soome extern int disk_close(struct disk_devdesc *);
113*22028508SToomas Soome extern int disk_ioctl(struct disk_devdesc *, u_long, void *);
114*22028508SToomas Soome extern int disk_read(struct disk_devdesc *, void *, uint64_t, u_int);
115*22028508SToomas Soome extern int disk_write(struct disk_devdesc *, void *, uint64_t, u_int);
116*22028508SToomas Soome 
117*22028508SToomas Soome /*
118*22028508SToomas Soome  * Print information about slices on a disk.
119*22028508SToomas Soome  */
120*22028508SToomas Soome extern int disk_print(struct disk_devdesc *, char *, int);
121*22028508SToomas Soome extern char* disk_fmtdev(struct disk_devdesc *);
122*22028508SToomas Soome extern int disk_parsedev(struct disk_devdesc *, const char *, const char **);
123*22028508SToomas Soome 
124*22028508SToomas Soome #endif	/* _DISK_H */
125