xref: /illumos-gate/usr/src/grub/grub-0.97/stage2/zfs-include/vdev_impl.h (revision 81b2d5738d8e67bdf2438cd3e8c79f379bce44d2)
1 /*
2  *  GRUB  --  GRand Unified Bootloader
3  *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, Inc.
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 /*
20  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
21  * Use is subject to license terms.
22  */
23 
24 #ifndef _SYS_VDEV_IMPL_H
25 #define	_SYS_VDEV_IMPL_H
26 
27 /* helper macros */
28 #undef	offsetof
29 #define	offsetof(t, m)		((int)&(((t *)0)->m))
30 #define	MAX(x, y)		((x) > (y) ? (x) : (y))
31 
32 #define	VDEV_PAD_SIZE 		(8 << 10)
33 /* 2 padding areas (vl_pad1 and vl_pad2) to skip */
34 #define	VDEV_SKIP_SIZE		VDEV_PAD_SIZE * 2
35 #define	VDEV_PHYS_SIZE		(112 << 10)
36 #define	VDEV_UBERBLOCK_RING	(128 << 10)
37 
38 #define	VDEV_UBERBLOCK_SHIFT(sh)		\
39 	MAX((sh), UBERBLOCK_SHIFT)
40 #define	VDEV_UBERBLOCK_COUNT(sh)		\
41 	(VDEV_UBERBLOCK_RING >> VDEV_UBERBLOCK_SHIFT(sh))
42 #define	VDEV_UBERBLOCK_OFFSET(sh, n)	\
43 	offsetof(vdev_label_t, vl_uberblock[(n) << VDEV_UBERBLOCK_SHIFT(sh)])
44 #define	VDEV_UBERBLOCK_SIZE(sh)			\
45 	(1ULL << VDEV_UBERBLOCK_SHIFT(sh))
46 
47 typedef struct vdev_phys {
48 	char		vp_nvlist[VDEV_PHYS_SIZE - sizeof (zio_eck_t)];
49 	zio_eck_t	vp_zbt;
50 } vdev_phys_t;
51 
52 typedef struct vdev_label {
53 	char		vl_pad1[VDEV_PAD_SIZE];			/*  8K	*/
54 	char		vl_pad2[VDEV_PAD_SIZE];			/*  8K	*/
55 	vdev_phys_t	vl_vdev_phys;				/* 112K	*/
56 	char		vl_uberblock[VDEV_UBERBLOCK_RING];	/* 128K	*/
57 } vdev_label_t;							/* 256K total */
58 
59 /*
60  * Size and offset of embedded boot loader region on each label.
61  * The total size of the first two labels plus the boot area is 4MB.
62  */
63 #define	VDEV_BOOT_OFFSET	(2 * sizeof (vdev_label_t))
64 #define	VDEV_BOOT_SIZE		(7ULL << 19)			/* 3.5M	*/
65 
66 /*
67  * Size of label regions at the start and end of each leaf device.
68  */
69 #define	VDEV_LABEL_START_SIZE	(2 * sizeof (vdev_label_t) + VDEV_BOOT_SIZE)
70 #define	VDEV_LABEL_END_SIZE	(2 * sizeof (vdev_label_t))
71 #define	VDEV_LABELS		4
72 
73 #endif	/* _SYS_VDEV_IMPL_H */
74