zap_leaf.h 2.7 KB

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