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/*
20b24ab67Jeff Bonwick * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
21b1b8ab3lling * Use is subject to license terms.
22b1b8ab3lling */
23b1b8ab3lling
24b1b8ab3lling#ifndef	_SYS_ZAP_IMPL_H
25b1b8ab3lling#define	_SYS_ZAP_IMPL_H
26b1b8ab3lling
27b1b8ab3lling#define	ZAP_MAGIC 0x2F52AB2ABULL
28b1b8ab3lling
29b1b8ab3lling#define	MZAP_ENT_LEN		64
30b1b8ab3lling#define	MZAP_NAME_LEN		(MZAP_ENT_LEN - 8 - 4 - 2)
31b1b8ab3lling#define	MZAP_MAX_BLKSHIFT	SPA_MAXBLOCKSHIFT
32b1b8ab3lling#define	MZAP_MAX_BLKSZ		(1 << MZAP_MAX_BLKSHIFT)
33b1b8ab3lling
34b1b8ab3llingtypedef struct mzap_ent_phys {
35b1b8ab3lling	uint64_t mze_value;
36b1b8ab3lling	uint32_t mze_cd;
37b1b8ab3lling	uint16_t mze_pad;	/* in case we want to chain them someday */
38b1b8ab3lling	char mze_name[MZAP_NAME_LEN];
39b1b8ab3lling} mzap_ent_phys_t;
40b1b8ab3lling
41b1b8ab3llingtypedef struct mzap_phys {
42b1b8ab3lling	uint64_t mz_block_type;	/* ZBT_MICRO */
43b1b8ab3lling	uint64_t mz_salt;
44b1b8ab3lling	uint64_t mz_pad[6];
45b1b8ab3lling	mzap_ent_phys_t mz_chunk[1];
46b1b8ab3lling	/* actually variable size depending on block size */
47b1b8ab3lling} mzap_phys_t;
48b1b8ab3lling
49b1b8ab3lling/*
50b1b8ab3lling * The (fat) zap is stored in one object. It is an array of
51b1b8ab3lling * 1<<FZAP_BLOCK_SHIFT byte blocks. The layout looks like one of:
52b1b8ab3lling *
53b1b8ab3lling * ptrtbl fits in first block:
54b1b8ab3lling * 	[zap_phys_t zap_ptrtbl_shift < 6] [zap_leaf_t] ...
55b1b8ab3lling *
56b1b8ab3lling * ptrtbl too big for first block:
57b1b8ab3lling * 	[zap_phys_t zap_ptrtbl_shift >= 6] [zap_leaf_t] [ptrtbl] ...
58b1b8ab3lling *
59b1b8ab3lling */
60b1b8ab3lling
61b1b8ab3lling#define	ZBT_LEAF		((1ULL << 63) + 0)
62b1b8ab3lling#define	ZBT_HEADER		((1ULL << 63) + 1)
63b1b8ab3lling#define	ZBT_MICRO		((1ULL << 63) + 3)
64b1b8ab3lling/* any other values are ptrtbl blocks */
65b1b8ab3lling
66b1b8ab3lling/*
67b1b8ab3lling * the embedded pointer table takes up half a block:
68b1b8ab3lling * block size / entry size (2^3) / 2
69b1b8ab3lling */
70b1b8ab3lling#define	ZAP_EMBEDDED_PTRTBL_SHIFT(zap) (FZAP_BLOCK_SHIFT(zap) - 3 - 1)
71b1b8ab3lling
72b1b8ab3lling/*
73b1b8ab3lling * The embedded pointer table starts half-way through the block.  Since
74b1b8ab3lling * the pointer table itself is half the block, it starts at (64-bit)
75b1b8ab3lling * word number (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap)).
76b1b8ab3lling */
77b1b8ab3lling#define	ZAP_EMBEDDED_PTRTBL_ENT(zap, idx) \
78b1b8ab3lling	((uint64_t *)(zap)->zap_f.zap_phys) \
79b1b8ab3lling	[(idx) + (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap))]
80b1b8ab3lling
81b1b8ab3lling/*
82b1b8ab3lling * TAKE NOTE:
83b1b8ab3lling * If zap_phys_t is modified, zap_byteswap() must be modified.
84b1b8ab3lling */
85b1b8ab3llingtypedef struct zap_phys {
86b1b8ab3lling	uint64_t zap_block_type;	/* ZBT_HEADER */
87b1b8ab3lling	uint64_t zap_magic;		/* ZAP_MAGIC */
88b1b8ab3lling
89b1b8ab3lling	struct zap_table_phys {
90b1b8ab3lling		uint64_t zt_blk;	/* starting block number */
91b1b8ab3lling		uint64_t zt_numblks;	/* number of blocks */
92b1b8ab3lling		uint64_t zt_shift;	/* bits to index it */
93b1b8ab3lling		uint64_t zt_nextblk;	/* next (larger) copy start block */
94b1b8ab3lling		uint64_t zt_blks_copied; /* number source blocks copied */
95b1b8ab3lling	} zap_ptrtbl;
96b1b8ab3lling
97b1b8ab3lling	uint64_t zap_freeblk;		/* the next free block */
98b1b8ab3lling	uint64_t zap_num_leafs;		/* number of leafs */
99b1b8ab3lling	uint64_t zap_num_entries;	/* number of entries */
100b1b8ab3lling	uint64_t zap_salt;		/* salt to stir into hash function */
101b24ab67Jeff Bonwick	uint64_t zap_normflags;		/* flags for u8_textprep_str() */
102b24ab67Jeff Bonwick	uint64_t zap_flags;		/* zap_flag_t */
103b1b8ab3lling	/*
104b1b8ab3lling	 * This structure is followed by padding, and then the embedded
105b1b8ab3lling	 * pointer table.  The embedded pointer table takes up second
106b1b8ab3lling	 * half of the block.  It is accessed using the
107b1b8ab3lling	 * ZAP_EMBEDDED_PTRTBL_ENT() macro.
108b1b8ab3lling	 */
109b1b8ab3lling} zap_phys_t;
110b1b8ab3lling
111b1b8ab3lling#endif /* _SYS_ZAP_IMPL_H */
112