1b1b8ab34Slling /*
2b1b8ab34Slling  *  GRUB  --  GRand Unified Bootloader
3b1b8ab34Slling  *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, Inc.
4b1b8ab34Slling  *
5b1b8ab34Slling  *  This program is free software; you can redistribute it and/or modify
6b1b8ab34Slling  *  it under the terms of the GNU General Public License as published by
7b1b8ab34Slling  *  the Free Software Foundation; either version 2 of the License, or
8b1b8ab34Slling  *  (at your option) any later version.
9b1b8ab34Slling  *
10b1b8ab34Slling  *  This program is distributed in the hope that it will be useful,
11b1b8ab34Slling  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12b1b8ab34Slling  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13b1b8ab34Slling  *  GNU General Public License for more details.
14b1b8ab34Slling  *
15b1b8ab34Slling  *  You should have received a copy of the GNU General Public License
16b1b8ab34Slling  *  along with this program; if not, write to the Free Software
17b1b8ab34Slling  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18b1b8ab34Slling  */
19b1b8ab34Slling /*
20*b24ab676SJeff Bonwick  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
21b1b8ab34Slling  * Use is subject to license terms.
22b1b8ab34Slling  */
23b1b8ab34Slling 
24b1b8ab34Slling #ifndef	_SYS_ZAP_IMPL_H
25b1b8ab34Slling #define	_SYS_ZAP_IMPL_H
26b1b8ab34Slling 
27b1b8ab34Slling #define	ZAP_MAGIC 0x2F52AB2ABULL
28b1b8ab34Slling 
29b1b8ab34Slling #define	MZAP_ENT_LEN		64
30b1b8ab34Slling #define	MZAP_NAME_LEN		(MZAP_ENT_LEN - 8 - 4 - 2)
31b1b8ab34Slling #define	MZAP_MAX_BLKSHIFT	SPA_MAXBLOCKSHIFT
32b1b8ab34Slling #define	MZAP_MAX_BLKSZ		(1 << MZAP_MAX_BLKSHIFT)
33b1b8ab34Slling 
34b1b8ab34Slling typedef struct mzap_ent_phys {
35b1b8ab34Slling 	uint64_t mze_value;
36b1b8ab34Slling 	uint32_t mze_cd;
37b1b8ab34Slling 	uint16_t mze_pad;	/* in case we want to chain them someday */
38b1b8ab34Slling 	char mze_name[MZAP_NAME_LEN];
39b1b8ab34Slling } mzap_ent_phys_t;
40b1b8ab34Slling 
41b1b8ab34Slling typedef struct mzap_phys {
42b1b8ab34Slling 	uint64_t mz_block_type;	/* ZBT_MICRO */
43b1b8ab34Slling 	uint64_t mz_salt;
44b1b8ab34Slling 	uint64_t mz_pad[6];
45b1b8ab34Slling 	mzap_ent_phys_t mz_chunk[1];
46b1b8ab34Slling 	/* actually variable size depending on block size */
47b1b8ab34Slling } mzap_phys_t;
48b1b8ab34Slling 
49b1b8ab34Slling /*
50b1b8ab34Slling  * The (fat) zap is stored in one object. It is an array of
51b1b8ab34Slling  * 1<<FZAP_BLOCK_SHIFT byte blocks. The layout looks like one of:
52b1b8ab34Slling  *
53b1b8ab34Slling  * ptrtbl fits in first block:
54b1b8ab34Slling  * 	[zap_phys_t zap_ptrtbl_shift < 6] [zap_leaf_t] ...
55b1b8ab34Slling  *
56b1b8ab34Slling  * ptrtbl too big for first block:
57b1b8ab34Slling  * 	[zap_phys_t zap_ptrtbl_shift >= 6] [zap_leaf_t] [ptrtbl] ...
58b1b8ab34Slling  *
59b1b8ab34Slling  */
60b1b8ab34Slling 
61b1b8ab34Slling #define	ZBT_LEAF		((1ULL << 63) + 0)
62b1b8ab34Slling #define	ZBT_HEADER		((1ULL << 63) + 1)
63b1b8ab34Slling #define	ZBT_MICRO		((1ULL << 63) + 3)
64b1b8ab34Slling /* any other values are ptrtbl blocks */
65b1b8ab34Slling 
66b1b8ab34Slling /*
67b1b8ab34Slling  * the embedded pointer table takes up half a block:
68b1b8ab34Slling  * block size / entry size (2^3) / 2
69b1b8ab34Slling  */
70b1b8ab34Slling #define	ZAP_EMBEDDED_PTRTBL_SHIFT(zap) (FZAP_BLOCK_SHIFT(zap) - 3 - 1)
71b1b8ab34Slling 
72b1b8ab34Slling /*
73b1b8ab34Slling  * The embedded pointer table starts half-way through the block.  Since
74b1b8ab34Slling  * the pointer table itself is half the block, it starts at (64-bit)
75b1b8ab34Slling  * word number (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap)).
76b1b8ab34Slling  */
77b1b8ab34Slling #define	ZAP_EMBEDDED_PTRTBL_ENT(zap, idx) \
78b1b8ab34Slling 	((uint64_t *)(zap)->zap_f.zap_phys) \
79b1b8ab34Slling 	[(idx) + (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap))]
80b1b8ab34Slling 
81b1b8ab34Slling /*
82b1b8ab34Slling  * TAKE NOTE:
83b1b8ab34Slling  * If zap_phys_t is modified, zap_byteswap() must be modified.
84b1b8ab34Slling  */
85b1b8ab34Slling typedef struct zap_phys {
86b1b8ab34Slling 	uint64_t zap_block_type;	/* ZBT_HEADER */
87b1b8ab34Slling 	uint64_t zap_magic;		/* ZAP_MAGIC */
88b1b8ab34Slling 
89b1b8ab34Slling 	struct zap_table_phys {
90b1b8ab34Slling 		uint64_t zt_blk;	/* starting block number */
91b1b8ab34Slling 		uint64_t zt_numblks;	/* number of blocks */
92b1b8ab34Slling 		uint64_t zt_shift;	/* bits to index it */
93b1b8ab34Slling 		uint64_t zt_nextblk;	/* next (larger) copy start block */
94b1b8ab34Slling 		uint64_t zt_blks_copied; /* number source blocks copied */
95b1b8ab34Slling 	} zap_ptrtbl;
96b1b8ab34Slling 
97b1b8ab34Slling 	uint64_t zap_freeblk;		/* the next free block */
98b1b8ab34Slling 	uint64_t zap_num_leafs;		/* number of leafs */
99b1b8ab34Slling 	uint64_t zap_num_entries;	/* number of entries */
100b1b8ab34Slling 	uint64_t zap_salt;		/* salt to stir into hash function */
101*b24ab676SJeff Bonwick 	uint64_t zap_normflags;		/* flags for u8_textprep_str() */
102*b24ab676SJeff Bonwick 	uint64_t zap_flags;		/* zap_flag_t */
103b1b8ab34Slling 	/*
104b1b8ab34Slling 	 * This structure is followed by padding, and then the embedded
105b1b8ab34Slling 	 * pointer table.  The embedded pointer table takes up second
106b1b8ab34Slling 	 * half of the block.  It is accessed using the
107b1b8ab34Slling 	 * ZAP_EMBEDDED_PTRTBL_ENT() macro.
108b1b8ab34Slling 	 */
109b1b8ab34Slling } zap_phys_t;
110b1b8ab34Slling 
111b1b8ab34Slling #endif /* _SYS_ZAP_IMPL_H */
112