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/*
20b1b8ab3lling * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
21b1b8ab3lling * Use is subject to license terms.
22b1b8ab3lling */
23b1b8ab3lling
24b1b8ab3lling#ifndef	_SYS_ZAP_LEAF_H
25b1b8ab3lling#define	_SYS_ZAP_LEAF_H
26b1b8ab3lling
27b1b8ab3lling#pragma ident	"%Z%%M%	%I%	%E% SMI"
28b1b8ab3lling
29b1b8ab3lling#define	ZAP_LEAF_MAGIC 0x2AB1EAF
30b1b8ab3lling
31b1b8ab3lling/* chunk size = 24 bytes */
32b1b8ab3lling#define	ZAP_LEAF_CHUNKSIZE 24
33b1b8ab3lling
34b1b8ab3lling/*
35b1b8ab3lling * The amount of space within the chunk available for the array is:
36b1b8ab3lling * chunk size - space for type (1) - space for next pointer (2)
37b1b8ab3lling */
38b1b8ab3lling#define	ZAP_LEAF_ARRAY_BYTES (ZAP_LEAF_CHUNKSIZE - 3)
39b1b8ab3lling
40b1b8ab3llingtypedef enum zap_chunk_type {
41b1b8ab3lling	ZAP_CHUNK_FREE = 253,
42b1b8ab3lling	ZAP_CHUNK_ENTRY = 252,
43b1b8ab3lling	ZAP_CHUNK_ARRAY = 251,
44b1b8ab3lling	ZAP_CHUNK_TYPE_MAX = 250
45b1b8ab3lling} zap_chunk_type_t;
46b1b8ab3lling
47b1b8ab3lling/*
48b1b8ab3lling * TAKE NOTE:
49b1b8ab3lling * If zap_leaf_phys_t is modified, zap_leaf_byteswap() must be modified.
50b1b8ab3lling */
51b1b8ab3llingtypedef struct zap_leaf_phys {
52b1b8ab3lling	struct zap_leaf_header {
53b1b8ab3lling		uint64_t lh_block_type;		/* ZBT_LEAF */
54b1b8ab3lling		uint64_t lh_pad1;
55b1b8ab3lling		uint64_t lh_prefix;		/* hash prefix of this leaf */
56b1b8ab3lling		uint32_t lh_magic;		/* ZAP_LEAF_MAGIC */
57b1b8ab3lling		uint16_t lh_nfree;		/* number free chunks */
58b1b8ab3lling		uint16_t lh_nentries;		/* number of entries */
59b1b8ab3lling		uint16_t lh_prefix_len;		/* num bits used to id this */
60b1b8ab3lling
61b1b8ab3lling/* above is accessable to zap, below is zap_leaf private */
62b1b8ab3lling
63b1b8ab3lling		uint16_t lh_freelist;		/* chunk head of free list */
64b1b8ab3lling		uint8_t lh_pad2[12];
65b1b8ab3lling	} l_hdr; /* 2 24-byte chunks */
66b1b8ab3lling
67b1b8ab3lling	/*
68b1b8ab3lling	 * The header is followed by a hash table with
69b1b8ab3lling	 * ZAP_LEAF_HASH_NUMENTRIES(zap) entries.  The hash table is
70b1b8ab3lling	 * followed by an array of ZAP_LEAF_NUMCHUNKS(zap)
71b1b8ab3lling	 * zap_leaf_chunk structures.  These structures are accessed
72b1b8ab3lling	 * with the ZAP_LEAF_CHUNK() macro.
73b1b8ab3lling	 */
74b1b8ab3lling
75b1b8ab3lling	uint16_t l_hash[1];
76b1b8ab3lling} zap_leaf_phys_t;
77b1b8ab3lling
78b1b8ab3llingtypedef union zap_leaf_chunk {
79b1b8ab3lling	struct zap_leaf_entry {
80b1b8ab3lling		uint8_t le_type; 		/* always ZAP_CHUNK_ENTRY */
81b1b8ab3lling		uint8_t le_int_size;		/* size of ints */
82b1b8ab3lling		uint16_t le_next;		/* next entry in hash chain */
83b1b8ab3lling		uint16_t le_name_chunk;		/* first chunk of the name */
84b1b8ab3lling		uint16_t le_name_length;	/* bytes in name, incl null */
85b1b8ab3lling		uint16_t le_value_chunk;	/* first chunk of the value */
86b1b8ab3lling		uint16_t le_value_length;	/* value length in ints */
87b1b8ab3lling		uint32_t le_cd;			/* collision differentiator */
88b1b8ab3lling		uint64_t le_hash;		/* hash value of the name */
89b1b8ab3lling	} l_entry;
90b1b8ab3lling	struct zap_leaf_array {
91b1b8ab3lling		uint8_t la_type;		/* always ZAP_CHUNK_ARRAY */
92b1b8ab3lling		uint8_t la_array[ZAP_LEAF_ARRAY_BYTES];
93b1b8ab3lling		uint16_t la_next;		/* next blk or CHAIN_END */
94b1b8ab3lling	} l_array;
95b1b8ab3lling	struct zap_leaf_free {
96b1b8ab3lling		uint8_t lf_type;		/* always ZAP_CHUNK_FREE */
97b1b8ab3lling		uint8_t lf_pad[ZAP_LEAF_ARRAY_BYTES];
98b1b8ab3lling		uint16_t lf_next;	/* next in free list, or CHAIN_END */
99b1b8ab3lling	} l_free;
100b1b8ab3lling} zap_leaf_chunk_t;
101b1b8ab3lling
102b1b8ab3lling#endif /* _SYS_ZAP_LEAF_H */
103