zap_impl.h 2.9 KB

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