zap_impl.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /*
  19. * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
  20. * Use is subject to license terms.
  21. */
  22. #ifndef _SYS_ZAP_IMPL_H
  23. #define _SYS_ZAP_IMPL_H
  24. #define ZAP_MAGIC 0x2F52AB2ABULL
  25. #define ZAP_HASHBITS 28
  26. #define MZAP_ENT_LEN 64
  27. #define MZAP_NAME_LEN (MZAP_ENT_LEN - 8 - 4 - 2)
  28. typedef struct mzap_ent_phys {
  29. grub_uint64_t mze_value;
  30. grub_uint32_t mze_cd;
  31. grub_uint16_t mze_pad; /* in case we want to chain them someday */
  32. char mze_name[MZAP_NAME_LEN];
  33. } mzap_ent_phys_t;
  34. typedef struct mzap_phys {
  35. grub_uint64_t mz_block_type; /* ZBT_MICRO */
  36. grub_uint64_t mz_salt;
  37. grub_uint64_t mz_pad[6];
  38. mzap_ent_phys_t mz_chunk[1];
  39. /* actually variable size depending on block size */
  40. } mzap_phys_t;
  41. /*
  42. * The (fat) zap is stored in one object. It is an array of
  43. * 1<<FZAP_BLOCK_SHIFT byte blocks. The layout looks like one of:
  44. *
  45. * ptrtbl fits in first block:
  46. * [zap_phys_t zap_ptrtbl_shift < 6] [zap_leaf_t] ...
  47. *
  48. * ptrtbl too big for first block:
  49. * [zap_phys_t zap_ptrtbl_shift >= 6] [zap_leaf_t] [ptrtbl] ...
  50. *
  51. */
  52. #define ZBT_LEAF ((1ULL << 63) + 0)
  53. #define ZBT_HEADER ((1ULL << 63) + 1)
  54. #define ZBT_MICRO ((1ULL << 63) + 3)
  55. /* any other values are ptrtbl blocks */
  56. /*
  57. * the embedded pointer table takes up half a block:
  58. * block size / entry size (2^3) / 2
  59. */
  60. #define ZAP_EMBEDDED_PTRTBL_SHIFT(zap) (FZAP_BLOCK_SHIFT(zap) - 3 - 1)
  61. /*
  62. * The embedded pointer table starts half-way through the block. Since
  63. * the pointer table itself is half the block, it starts at (64-bit)
  64. * word number (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap)).
  65. */
  66. #define ZAP_EMBEDDED_PTRTBL_ENT(zap, idx) \
  67. ((grub_uint64_t *)(zap)->zap_f.zap_phys) \
  68. [(idx) + (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap))]
  69. /*
  70. * TAKE NOTE:
  71. * If zap_phys_t is modified, zap_byteswap() must be modified.
  72. */
  73. typedef struct zap_phys {
  74. grub_uint64_t zap_block_type; /* ZBT_HEADER */
  75. grub_uint64_t zap_magic; /* ZAP_MAGIC */
  76. struct zap_table_phys {
  77. grub_uint64_t zt_blk; /* starting block number */
  78. grub_uint64_t zt_numblks; /* number of blocks */
  79. grub_uint64_t zt_shift; /* bits to index it */
  80. grub_uint64_t zt_nextblk; /* next (larger) copy start block */
  81. grub_uint64_t zt_blks_copied; /* number source blocks copied */
  82. } zap_ptrtbl;
  83. grub_uint64_t zap_freeblk; /* the next free block */
  84. grub_uint64_t zap_num_leafs; /* number of leafs */
  85. grub_uint64_t zap_num_entries; /* number of entries */
  86. grub_uint64_t zap_salt; /* salt to stir into hash function */
  87. grub_uint64_t zap_normflags; /* flags for u8_textprep_str() */
  88. grub_uint64_t zap_flags; /* zap_flag_t */
  89. /*
  90. * This structure is followed by padding, and then the embedded
  91. * pointer table. The embedded pointer table takes up second
  92. * half of the block. It is accessed using the
  93. * ZAP_EMBEDDED_PTRTBL_ENT() macro.
  94. */
  95. } zap_phys_t;
  96. #endif /* _SYS_ZAP_IMPL_H */