xref: /OK3568_Linux_fs/u-boot/include/zfs/zap_leaf.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  *  GRUB  --  GRand Unified Bootloader
3*4882a593Smuzhiyun  *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, Inc.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun /*
8*4882a593Smuzhiyun  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
9*4882a593Smuzhiyun  * Use is subject to license terms.
10*4882a593Smuzhiyun  */
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #ifndef	_SYS_ZAP_LEAF_H
13*4882a593Smuzhiyun #define	_SYS_ZAP_LEAF_H
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #define	ZAP_LEAF_MAGIC 0x2AB1EAF
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun /* chunk size = 24 bytes */
18*4882a593Smuzhiyun #define	ZAP_LEAF_CHUNKSIZE 24
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun /*
21*4882a593Smuzhiyun  * The amount of space within the chunk available for the array is:
22*4882a593Smuzhiyun  * chunk size - space for type (1) - space for next pointer (2)
23*4882a593Smuzhiyun  */
24*4882a593Smuzhiyun #define	ZAP_LEAF_ARRAY_BYTES (ZAP_LEAF_CHUNKSIZE - 3)
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun typedef enum zap_chunk_type {
27*4882a593Smuzhiyun 	ZAP_CHUNK_FREE = 253,
28*4882a593Smuzhiyun 	ZAP_CHUNK_ENTRY = 252,
29*4882a593Smuzhiyun 	ZAP_CHUNK_ARRAY = 251,
30*4882a593Smuzhiyun 	ZAP_CHUNK_TYPE_MAX = 250
31*4882a593Smuzhiyun } zap_chunk_type_t;
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun /*
34*4882a593Smuzhiyun  * TAKE NOTE:
35*4882a593Smuzhiyun  * If zap_leaf_phys_t is modified, zap_leaf_byteswap() must be modified.
36*4882a593Smuzhiyun  */
37*4882a593Smuzhiyun typedef struct zap_leaf_phys {
38*4882a593Smuzhiyun 	struct zap_leaf_header {
39*4882a593Smuzhiyun 		uint64_t lh_block_type;		/* ZBT_LEAF */
40*4882a593Smuzhiyun 		uint64_t lh_pad1;
41*4882a593Smuzhiyun 		uint64_t lh_prefix;		/* hash prefix of this leaf */
42*4882a593Smuzhiyun 		uint32_t lh_magic;		/* ZAP_LEAF_MAGIC */
43*4882a593Smuzhiyun 		uint16_t lh_nfree;		/* number free chunks */
44*4882a593Smuzhiyun 		uint16_t lh_nentries;		/* number of entries */
45*4882a593Smuzhiyun 		uint16_t lh_prefix_len;		/* num bits used to id this */
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun 		/* above is accessable to zap, below is zap_leaf private */
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun 		uint16_t lh_freelist;		/* chunk head of free list */
50*4882a593Smuzhiyun 		uint8_t lh_pad2[12];
51*4882a593Smuzhiyun 	} l_hdr; /* 2 24-byte chunks */
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun 	/*
54*4882a593Smuzhiyun 	 * The header is followed by a hash table with
55*4882a593Smuzhiyun 	 * ZAP_LEAF_HASH_NUMENTRIES(zap) entries.  The hash table is
56*4882a593Smuzhiyun 	 * followed by an array of ZAP_LEAF_NUMCHUNKS(zap)
57*4882a593Smuzhiyun 	 * zap_leaf_chunk structures.  These structures are accessed
58*4882a593Smuzhiyun 	 * with the ZAP_LEAF_CHUNK() macro.
59*4882a593Smuzhiyun 	 */
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun 	uint16_t l_hash[1];
62*4882a593Smuzhiyun } zap_leaf_phys_t;
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun typedef union zap_leaf_chunk {
65*4882a593Smuzhiyun 	struct zap_leaf_entry {
66*4882a593Smuzhiyun 		uint8_t le_type;		/* always ZAP_CHUNK_ENTRY */
67*4882a593Smuzhiyun 		uint8_t le_int_size;		/* size of ints */
68*4882a593Smuzhiyun 		uint16_t le_next;		/* next entry in hash chain */
69*4882a593Smuzhiyun 		uint16_t le_name_chunk;		/* first chunk of the name */
70*4882a593Smuzhiyun 		uint16_t le_name_length;	/* bytes in name, incl null */
71*4882a593Smuzhiyun 		uint16_t le_value_chunk;	/* first chunk of the value */
72*4882a593Smuzhiyun 		uint16_t le_value_length;	/* value length in ints */
73*4882a593Smuzhiyun 		uint32_t le_cd;		/* collision differentiator */
74*4882a593Smuzhiyun 		uint64_t le_hash;		/* hash value of the name */
75*4882a593Smuzhiyun 	} l_entry;
76*4882a593Smuzhiyun 	struct zap_leaf_array {
77*4882a593Smuzhiyun 		uint8_t la_type;		/* always ZAP_CHUNK_ARRAY */
78*4882a593Smuzhiyun 		union {
79*4882a593Smuzhiyun 			uint8_t la_array[ZAP_LEAF_ARRAY_BYTES];
80*4882a593Smuzhiyun 			uint64_t la_array64;
81*4882a593Smuzhiyun 		} __attribute__ ((packed));
82*4882a593Smuzhiyun 		uint16_t la_next;		/* next blk or CHAIN_END */
83*4882a593Smuzhiyun 	} l_array;
84*4882a593Smuzhiyun 	struct zap_leaf_free {
85*4882a593Smuzhiyun 		uint8_t lf_type;		/* always ZAP_CHUNK_FREE */
86*4882a593Smuzhiyun 		uint8_t lf_pad[ZAP_LEAF_ARRAY_BYTES];
87*4882a593Smuzhiyun 		uint16_t lf_next;	/* next in free list, or CHAIN_END */
88*4882a593Smuzhiyun 	} l_free;
89*4882a593Smuzhiyun } zap_leaf_chunk_t;
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun #endif /* _SYS_ZAP_LEAF_H */
92