zap_impl.h 2.9 KB

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