zap_leaf.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 2007 Sun Microsystems, Inc. All rights reserved.
  20. * Use is subject to license terms.
  21. */
  22. #ifndef _SYS_ZAP_LEAF_H
  23. #define _SYS_ZAP_LEAF_H
  24. #define ZAP_LEAF_MAGIC 0x2AB1EAF
  25. /* chunk size = 24 bytes */
  26. #define ZAP_LEAF_CHUNKSIZE 24
  27. /*
  28. * The amount of space within the chunk available for the array is:
  29. * chunk size - space for type (1) - space for next pointer (2)
  30. */
  31. #define ZAP_LEAF_ARRAY_BYTES (ZAP_LEAF_CHUNKSIZE - 3)
  32. typedef enum zap_chunk_type {
  33. ZAP_CHUNK_FREE = 253,
  34. ZAP_CHUNK_ENTRY = 252,
  35. ZAP_CHUNK_ARRAY = 251,
  36. ZAP_CHUNK_TYPE_MAX = 250
  37. } zap_chunk_type_t;
  38. /*
  39. * TAKE NOTE:
  40. * If zap_leaf_phys_t is modified, zap_leaf_byteswap() must be modified.
  41. */
  42. typedef struct zap_leaf_phys {
  43. struct zap_leaf_header {
  44. grub_uint64_t lh_block_type; /* ZBT_LEAF */
  45. grub_uint64_t lh_pad1;
  46. grub_uint64_t lh_prefix; /* hash prefix of this leaf */
  47. grub_uint32_t lh_magic; /* ZAP_LEAF_MAGIC */
  48. grub_uint16_t lh_nfree; /* number free chunks */
  49. grub_uint16_t lh_nentries; /* number of entries */
  50. grub_uint16_t lh_prefix_len; /* num bits used to id this */
  51. /* above is accessable to zap, below is zap_leaf private */
  52. grub_uint16_t lh_freelist; /* chunk head of free list */
  53. grub_uint8_t lh_pad2[12];
  54. } l_hdr; /* 2 24-byte chunks */
  55. /*
  56. * The header is followed by a hash table with
  57. * ZAP_LEAF_HASH_NUMENTRIES(zap) entries. The hash table is
  58. * followed by an array of ZAP_LEAF_NUMCHUNKS(zap)
  59. * zap_leaf_chunk structures. These structures are accessed
  60. * with the ZAP_LEAF_CHUNK() macro.
  61. */
  62. grub_uint16_t l_hash[0];
  63. } zap_leaf_phys_t;
  64. typedef union zap_leaf_chunk {
  65. struct zap_leaf_entry {
  66. grub_uint8_t le_type; /* always ZAP_CHUNK_ENTRY */
  67. grub_uint8_t le_int_size; /* size of ints */
  68. grub_uint16_t le_next; /* next entry in hash chain */
  69. grub_uint16_t le_name_chunk; /* first chunk of the name */
  70. grub_uint16_t le_name_length; /* bytes in name, incl null */
  71. grub_uint16_t le_value_chunk; /* first chunk of the value */
  72. grub_uint16_t le_value_length; /* value length in ints */
  73. grub_uint32_t le_cd; /* collision differentiator */
  74. grub_uint64_t le_hash; /* hash value of the name */
  75. } l_entry;
  76. struct zap_leaf_array {
  77. grub_uint8_t la_type; /* always ZAP_CHUNK_ARRAY */
  78. union
  79. {
  80. grub_uint8_t la_array[ZAP_LEAF_ARRAY_BYTES];
  81. grub_uint64_t la_array64;
  82. } GRUB_PACKED;
  83. grub_uint16_t la_next; /* next blk or CHAIN_END */
  84. } l_array;
  85. struct zap_leaf_free {
  86. grub_uint8_t lf_type; /* always ZAP_CHUNK_FREE */
  87. grub_uint8_t lf_pad[ZAP_LEAF_ARRAY_BYTES];
  88. grub_uint16_t lf_next; /* next in free list, or CHAIN_END */
  89. } l_free;
  90. } zap_leaf_chunk_t;
  91. #endif /* _SYS_ZAP_LEAF_H */