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