xref: /titanic_44/usr/src/grub/grub-0.97/stage2/zfs-include/zap_leaf.h (revision 1b8adde7ba7d5e04395c141c5400dc2cffd7d809)
1 /*
2  *  GRUB  --  GRand Unified Bootloader
3  *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, Inc.
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 /*
20  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
21  * Use is subject to license terms.
22  */
23 
24 #ifndef	_SYS_ZAP_LEAF_H
25 #define	_SYS_ZAP_LEAF_H
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #define	ZAP_LEAF_MAGIC 0x2AB1EAF
30 
31 /* chunk size = 24 bytes */
32 #define	ZAP_LEAF_CHUNKSIZE 24
33 
34 /*
35  * The amount of space within the chunk available for the array is:
36  * chunk size - space for type (1) - space for next pointer (2)
37  */
38 #define	ZAP_LEAF_ARRAY_BYTES (ZAP_LEAF_CHUNKSIZE - 3)
39 
40 typedef enum zap_chunk_type {
41 	ZAP_CHUNK_FREE = 253,
42 	ZAP_CHUNK_ENTRY = 252,
43 	ZAP_CHUNK_ARRAY = 251,
44 	ZAP_CHUNK_TYPE_MAX = 250
45 } zap_chunk_type_t;
46 
47 /*
48  * TAKE NOTE:
49  * If zap_leaf_phys_t is modified, zap_leaf_byteswap() must be modified.
50  */
51 typedef struct zap_leaf_phys {
52 	struct zap_leaf_header {
53 		uint64_t lh_block_type;		/* ZBT_LEAF */
54 		uint64_t lh_pad1;
55 		uint64_t lh_prefix;		/* hash prefix of this leaf */
56 		uint32_t lh_magic;		/* ZAP_LEAF_MAGIC */
57 		uint16_t lh_nfree;		/* number free chunks */
58 		uint16_t lh_nentries;		/* number of entries */
59 		uint16_t lh_prefix_len;		/* num bits used to id this */
60 
61 /* above is accessable to zap, below is zap_leaf private */
62 
63 		uint16_t lh_freelist;		/* chunk head of free list */
64 		uint8_t lh_pad2[12];
65 	} l_hdr; /* 2 24-byte chunks */
66 
67 	/*
68 	 * The header is followed by a hash table with
69 	 * ZAP_LEAF_HASH_NUMENTRIES(zap) entries.  The hash table is
70 	 * followed by an array of ZAP_LEAF_NUMCHUNKS(zap)
71 	 * zap_leaf_chunk structures.  These structures are accessed
72 	 * with the ZAP_LEAF_CHUNK() macro.
73 	 */
74 
75 	uint16_t l_hash[1];
76 } zap_leaf_phys_t;
77 
78 typedef union zap_leaf_chunk {
79 	struct zap_leaf_entry {
80 		uint8_t le_type; 		/* always ZAP_CHUNK_ENTRY */
81 		uint8_t le_int_size;		/* size of ints */
82 		uint16_t le_next;		/* next entry in hash chain */
83 		uint16_t le_name_chunk;		/* first chunk of the name */
84 		uint16_t le_name_length;	/* bytes in name, incl null */
85 		uint16_t le_value_chunk;	/* first chunk of the value */
86 		uint16_t le_value_length;	/* value length in ints */
87 		uint32_t le_cd;			/* collision differentiator */
88 		uint64_t le_hash;		/* hash value of the name */
89 	} l_entry;
90 	struct zap_leaf_array {
91 		uint8_t la_type;		/* always ZAP_CHUNK_ARRAY */
92 		uint8_t la_array[ZAP_LEAF_ARRAY_BYTES];
93 		uint16_t la_next;		/* next blk or CHAIN_END */
94 	} l_array;
95 	struct zap_leaf_free {
96 		uint8_t lf_type;		/* always ZAP_CHUNK_FREE */
97 		uint8_t lf_pad[ZAP_LEAF_ARRAY_BYTES];
98 		uint16_t lf_next;	/* next in free list, or CHAIN_END */
99 	} l_free;
100 } zap_leaf_chunk_t;
101 
102 #endif /* _SYS_ZAP_LEAF_H */
103