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