xref: /OK3568_Linux_fs/u-boot/include/zfs/zap_impl.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 (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
9*4882a593Smuzhiyun  */
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #ifndef	_SYS_ZAP_IMPL_H
12*4882a593Smuzhiyun #define	_SYS_ZAP_IMPL_H
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #define	ZAP_MAGIC 0x2F52AB2ABULL
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #define	ZAP_HASHBITS		28
17*4882a593Smuzhiyun #define	MZAP_ENT_LEN		64
18*4882a593Smuzhiyun #define	MZAP_NAME_LEN		(MZAP_ENT_LEN - 8 - 4 - 2)
19*4882a593Smuzhiyun #define	MZAP_MAX_BLKSHIFT	SPA_MAXBLOCKSHIFT
20*4882a593Smuzhiyun #define	MZAP_MAX_BLKSZ		(1 << MZAP_MAX_BLKSHIFT)
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun typedef struct mzap_ent_phys {
23*4882a593Smuzhiyun 	uint64_t mze_value;
24*4882a593Smuzhiyun 	uint32_t mze_cd;
25*4882a593Smuzhiyun 	uint16_t mze_pad;	/* in case we want to chain them someday */
26*4882a593Smuzhiyun 	char mze_name[MZAP_NAME_LEN];
27*4882a593Smuzhiyun } mzap_ent_phys_t;
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun typedef struct mzap_phys {
30*4882a593Smuzhiyun 	uint64_t mz_block_type;	/* ZBT_MICRO */
31*4882a593Smuzhiyun 	uint64_t mz_salt;
32*4882a593Smuzhiyun 	uint64_t mz_pad[6];
33*4882a593Smuzhiyun 	mzap_ent_phys_t mz_chunk[1];
34*4882a593Smuzhiyun 	/* actually variable size depending on block size */
35*4882a593Smuzhiyun } mzap_phys_t;
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun /*
38*4882a593Smuzhiyun  * The (fat) zap is stored in one object. It is an array of
39*4882a593Smuzhiyun  * 1<<FZAP_BLOCK_SHIFT byte blocks. The layout looks like one of:
40*4882a593Smuzhiyun  *
41*4882a593Smuzhiyun  * ptrtbl fits in first block:
42*4882a593Smuzhiyun  *	[zap_phys_t zap_ptrtbl_shift < 6] [zap_leaf_t] ...
43*4882a593Smuzhiyun  *
44*4882a593Smuzhiyun  * ptrtbl too big for first block:
45*4882a593Smuzhiyun  *	[zap_phys_t zap_ptrtbl_shift >= 6] [zap_leaf_t] [ptrtbl] ...
46*4882a593Smuzhiyun  *
47*4882a593Smuzhiyun  */
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun #define	ZBT_LEAF		((1ULL << 63) + 0)
50*4882a593Smuzhiyun #define	ZBT_HEADER		((1ULL << 63) + 1)
51*4882a593Smuzhiyun #define	ZBT_MICRO		((1ULL << 63) + 3)
52*4882a593Smuzhiyun /* any other values are ptrtbl blocks */
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun /*
55*4882a593Smuzhiyun  * the embedded pointer table takes up half a block:
56*4882a593Smuzhiyun  * block size / entry size (2^3) / 2
57*4882a593Smuzhiyun  */
58*4882a593Smuzhiyun #define	ZAP_EMBEDDED_PTRTBL_SHIFT(zap) (FZAP_BLOCK_SHIFT(zap) - 3 - 1)
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun /*
61*4882a593Smuzhiyun  * The embedded pointer table starts half-way through the block.  Since
62*4882a593Smuzhiyun  * the pointer table itself is half the block, it starts at (64-bit)
63*4882a593Smuzhiyun  * word number (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap)).
64*4882a593Smuzhiyun  */
65*4882a593Smuzhiyun #define	ZAP_EMBEDDED_PTRTBL_ENT(zap, idx) \
66*4882a593Smuzhiyun 	((uint64_t *)(zap)->zap_f.zap_phys) \
67*4882a593Smuzhiyun 	[(idx) + (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap))]
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun /*
70*4882a593Smuzhiyun  * TAKE NOTE:
71*4882a593Smuzhiyun  * If zap_phys_t is modified, zap_byteswap() must be modified.
72*4882a593Smuzhiyun  */
73*4882a593Smuzhiyun typedef struct zap_phys {
74*4882a593Smuzhiyun 	uint64_t zap_block_type;	/* ZBT_HEADER */
75*4882a593Smuzhiyun 	uint64_t zap_magic;		/* ZAP_MAGIC */
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun 	struct zap_table_phys {
78*4882a593Smuzhiyun 		uint64_t zt_blk;	/* starting block number */
79*4882a593Smuzhiyun 		uint64_t zt_numblks;	/* number of blocks */
80*4882a593Smuzhiyun 		uint64_t zt_shift;	/* bits to index it */
81*4882a593Smuzhiyun 		uint64_t zt_nextblk;	/* next (larger) copy start block */
82*4882a593Smuzhiyun 		uint64_t zt_blks_copied; /* number source blocks copied */
83*4882a593Smuzhiyun 	} zap_ptrtbl;
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun 	uint64_t zap_freeblk;		/* the next free block */
86*4882a593Smuzhiyun 	uint64_t zap_num_leafs;		/* number of leafs */
87*4882a593Smuzhiyun 	uint64_t zap_num_entries;	/* number of entries */
88*4882a593Smuzhiyun 	uint64_t zap_salt;		/* salt to stir into hash function */
89*4882a593Smuzhiyun 	uint64_t zap_normflags;		/* flags for u8_textprep_str() */
90*4882a593Smuzhiyun 	uint64_t zap_flags;		/* zap_flag_t */
91*4882a593Smuzhiyun 	/*
92*4882a593Smuzhiyun 	 * This structure is followed by padding, and then the embedded
93*4882a593Smuzhiyun 	 * pointer table.  The embedded pointer table takes up second
94*4882a593Smuzhiyun 	 * half of the block.  It is accessed using the
95*4882a593Smuzhiyun 	 * ZAP_EMBEDDED_PTRTBL_ENT() macro.
96*4882a593Smuzhiyun 	 */
97*4882a593Smuzhiyun } zap_phys_t;
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun #endif /* _SYS_ZAP_IMPL_H */
100