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