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